- Home /
DLLs work on Windows but not on Android
Dear Unity community,
I'm trying to use OpenSSL in our project but it only works for Windows. This OpenSSL solution is using libeay32.dll , ssleay32.dll and a C# .net 3.5 wrapper called ManagedOpenSsl.dll Does someone know how to make this work for Android too? When the encryption method is called, it does not encrypt and I see these errors in logcat:
12-22 16:27:40.081 13134 13172 D Unity : Unable to lookup library path for 'libeay32', native render plugin support disabled.
12-22 16:27:40.081 13134 13172 E Unity : Unable to find libeay32
12-22 16:27:40.467 13134 13172 D Unity : Unable to lookup library path for 'ssleay32', native render plugin support disabled.
12-22 16:27:40.468 13134 13172 E Unity : Unable to find ssleay32
The dll's are located in the plugins /Assets/Plugins folder, other dll's work but these do not.
Kind regards, Yorick
Answer by DreadKyller · Dec 22, 2017 at 10:51 PM
These files aren't the same for each operating system. DLLs are windows-specific (without third party software)
Windows: .dll
Dynamic Link Library
Linux (Android is a flavor of Linux): .so
Shared Object
Mac: .dylib
Dynamic Libraries
Also, you can't just rename the binary either, they much be compiled for each, although it's possible to compile for one system (say Linux) from another (say Windows) with the proper software. I believe Unity does support such software, however if you got these DLLs somewhere else, you'll need to find the appropriate files for the target platform. If you compiled these DLLs yourself, you'll need to recompile to the proper format, plenty of info online regarding how to do so.
Thank you very much. I've noticed something in the App.config of the repository.
<dllmap os="osx" dll="libeay32" target="libcrypto.1.0.0.dylib"/>
<dllmap os="osx" dll="ssleay32" target="libssl.1.0.0.dylib"/>
<dllmap os="!windows,osx" dll="libeay32" target="libcrypto.so"/>
<dllmap os="!windows,osx" dll="ssleay32" target="libssl.so"/>
So I'm wondering, will it work if I add a dllmap targeting Android to use libcrypto.so and libssl.so ? Sound to me that's a step in the right direction, but then there's the possiblity that I need to build the dll's on Android or perhaps I should build the dll's on Linux if Android is a flavor of Linux. To make it even more complicated, this should also work on iPhones and iPads.
I Think just building for android/linux should do the trick because the ddlmaps refer to libcrypto.so and libssl.so
Update: I've used a linux virtual box with CentOS 7 to get the .so files. It coincidentally had the exactly right version of OpenSSL installed(1.0.2k) but it could not find libcrypto.so or libssl.so so I used "yum provides libcrypto.so.10" to find out how to get these files on the virtual machine. After installing it "yum install libcrypto.so.10" I could use "find / -name libcrypto.so.10" and "find / -name libssl.so.10" to discover where these files were located. They were called libcrypto.so.1.0.2k and libssl.so.1.0.2k. I transfered the 32bit and 64bit versions to my work computer using ftp, removed ".1.0.2k" from all of them so they had the neutral libcrypto.so and libssl.so names as desired by the configuration file in the git repostory in my first post. I dropped them in the appropriate directory in my unity project:
Assets/Plugins/Android/libs/x86/
Assets/Plugins/Android/libs/armeabi-v7a/
Then I built the project for android and checked adb logcat for any errors and ufortunately it gave me the exact same errors described in my first post.
I feel like I'm getting very close but it still does not work. Is there anyone who can help me out a little bit more? Thanks in advance
Update: I've edited the $$anonymous$$anagedOpenSSL dll to skip the dllmap configuration. I think that only works when used outside of Unity. I built two ($$anonymous$$anagedOpenSSL) dll's one that searches for the windows libraries and one that searches for the android libraries. const string DLLNA$$anonymous$$E = "crypto";
Is used on android and DLLNA$$anonymous$$E is used in every [DllImport] attribute which would link the native C methods to C# calls. The actual "dll's" are called libcrypto.so and libssl.so but to make it work for Android people should remove the lib part and extension which results in calls to crypto and ssl. At this moment, OpenSSL works on Windows in the Unity editor. On Android however, I get a number of errors:
01-03 15:32:50.743 2573 2616 D Unity : Unable to load library '/system/lib/libcrypto.so', native render plugin support disabled: java.lang.UnsatisfiedLinkError: dlopen failed: library "/system/lib/libcrypto.so" needed or dlopened by "/system/lib/libnativeloader.so" is not accessible for the namespace "classloader-namespace"
01-03 15:32:50.744 2573 2616 E Unity : Unable to find crypto 01-03 15:32:51.276 2573 2616 D Unity : Unable to load library '/system/lib/libssl.so', native render plugin support disabled: java.lang.UnsatisfiedLinkError: dlopen failed: library "/system/lib/libssl.so" needed or dlopened by "/system/lib/libnativeloader.so" is not accessible for the namespace "classloader-namespace"
01-03 15:32:51.277 2573 2616 E Unity : Unable to find ssl
01-03 15:32:51.312 2573 2616 E Unity : DllNotFoundException: crypto
It seems to search for libcrypto.so(the right name) in /system/lib/ which to me sounds like it's not loading it from the one I've added to the Unity folder but it's actually searching for it on the device. How would I link that back to the one I've actually added to the Unity project?
@Dread$$anonymous$$yller Could you maybe clarify a bit more about the problem and possible solution?
Thanks in advance
I've moved the entire $$anonymous$$anagedOpenSLL source code to my Unity project to be able to use Unity's platform dependent compilation. Changed the const string part to:
#if UNITY_EDITOR || UNITY_STANDALONE_WIN
const string DLLNA$$anonymous$$E = "libeay32";
const string SSLDLLNA$$anonymous$$E = "ssleay32";
#elif UNITY_ANDROID || UNITY_STANDALONE_LINUX
const string DLLNA$$anonymous$$E = "crypto";
const string SSLDLLNA$$anonymous$$E = "ssl";
#elif UNITY_IOS || UNITY_STANDALONE_OSX
no support yet
#endif
It works on Windows but when I run this on android I get the exact same error as in the previous comment. It's still searching for the /system/lib/libcrypto.so ins$$anonymous$$d of loading it from Unity.