- Home /
Build an android apk from Unity3d project working with C/C++ dll
I made a Unity3d project working with C/C++ Dll. So first I made the dll in Visual studio.
// mydll.cpp
#define EXPORT_API __declspec(dllexport)
extern "C" {
int EXPORT_API add(int a, int b)
{
return a+b;
}
}
And I added this dll into my Unity3D project and called
// C# script in Unity3D
public class TestDll : MonoBehaviour
{
[DllImport("mydll")]
private static extern int add (int a, int b);
void Start() {
int a = add (100, 200);
}
}
This code works well and I got the correct result in Unity3D editor.
So I built this project to android platform and got an apk. I installed and run this apk on my android device but the app doesn't work. The app didn't run the Dll function.
Whats the matter? I tried to find out the solution in Google and here, but didn't get anything, yet. Please help me. Thanks.
Answer by Bojidar · Aug 06, 2014 at 02:25 PM
From the Manual:
Deployment
For cross platform deployment, your project should include plugins for each supported ??platform (ie, libPlugin.so for Android, Plugin.bundle for Mac and Plugin.dll for Windows). Unity automatically picks the right plugin for the target platform and includes it with the player.
In short, .DLL files work only on Windows, .SO files only on Linux (Android is also a kind of Linux), and .BUNDLE only on Mac.
Thanks to @robertbu for pointing this in his comment.
Your answer
Follow this Question
Related Questions
Referencing a DLL in C# 0 Answers
DLLs work on Windows but not on Android 1 Answer
Using a predefined dll in an android build 1 Answer
How do I include added dll's to a android apk build? 1 Answer
Recompiling my DLL as SO. 0 Answers