DllNotFoundException in Unity android app

Hi, I am currently using Cryptlex in a unity application. I added the libLexActivator.so into the project and added the GitHub - cryptlex/lexactivator-dotnet: LexActivator API wrapper for .NET (licensing library).

Getting following message:

11:40:38.493UTC: GameInitialization:LicenseManager - Exception: System.DllNotFoundException: LexActivator
  at (wrapper managed-to-native) Cryptlex.LexActivatorNative.SetProductFile(string)
  at Cryptlex.LexActivator.SetProductFile (System.String filePath) [0x0000b] in C:\Users\Admin\wkspaces\<a game>New\<a game>\Assets\Plugins\LexActivator\API\LexActivator.cs:37 
  at Cryptlex.CryptlexService.SetProductFile (System.String filePath) [0x00001] in C:\Users\Admin\wkspaces\<a game>New\<a game>\Assets\Scripts\Runtime\Tools\License Tool\Scripts\ICryptlexService.cs:544 
  at LicenseManager.SetProductFileAndVersionGUIDv3 (LicenseManager+CryptlexProduct cryptlexProduct) [0x00059] in C:\Users\Admin\wkspaces\<a game>New\<a game>\Assets\Scripts\Runtime\Tools\License Tool\Scripts\LicenseManager.cs:136 
  at LicenseManager.IsProductGenuineV3 (LicenseManager+CryptlexProduct cryptlexProduct) [0x00038] in C:\Users\Admin\wkspaces\<a game>New\<a game>\Assets\Scripts\Runtime\Tools\License Tool\Scripts\LicenseManager.cs:198 
  at LicenseManager.IsProductGenuine (LicenseManager+CryptlexProduct cryptlexProduct) [0x0001d] in C:\Users\Admin\wkspaces\<a game>New\<a game>\Assets\Scripts\Runtime\Tools\License Tool\Scripts\LicenseManager.cs:151 
  at System.Linq.Enumerable.Any[TSource] (System.Collections.Generic.IEnumerable`1[T] source, System.Func`2[T,TResult] predicate) [0x0002c] in <351e49e2a5bf4fd6beabb458ce2255f3>:0 
  at LicenseManager.CheckLicense () [0x00002] in C:\Users\Admin\wkspaces\<a game>New\<a game>\Assets\Scripts\Runtime\Tools\License Tool\Scripts\LicenseManager.cs:91 
UnityEngine.Debug:LogError(Object)
Debug:LogError(Object, Object) (at Packages/<a game company>Utilities/Scripts/ExtendedDebug.cs:67)
Logger:LogError(String) (at Assets/Scripts/Runtime/Util/Logger.cs:26)
LicenseManager:CheckLicense() (at Assets/Scripts/Runtime/Tools/License Tool/Scripts/LicenseManager.cs:96)
LicenseManager:Start() (at Assets/Scripts/Runtime/Tools/License Tool/Scripts/LicenseManager.cs:77)

Libs are in
Assets/Plugins/Android/libs/arm64-v8a/libLexActivator.so
and
Assets/Plugins/Android/libs/armeabi-v7a/libLexActivator.so

Has anyone an idea?

Hi,

How did you add this project? You don’t have to include this code in your app, nor you have to manually include the DLLs and .so files.

You just have to install the nuget package and it will handle the rest.

Does the nuget package also handle the android integration?

We imported it via nuget for unity now. Still not working:

16:55:11.814UTC: GameInitialization:LicenseManager - Exception: System.DllNotFoundException: LexActivator
  at (wrapper managed-to-native) Cryptlex.LexActivatorNative.SetProductFile(string)
  at Cryptlex.LexActivator.SetProductFile (System.String filePath) [0x0000f] in <71174367958147759f59003818bb2d35>:0 
  at Cryptlex.CryptlexService.SetProductFile (System.String filePath) [0x00001] in

We were creating a whole new clean Unity project now, added NuGet for Unity and imported Cryptlex. We are running 2019.4.12f on build platform Android.

DllNotFoundException: LexActivator
Cryptlex.LexActivator.SetProductFile (System.String filePath) (at <4d90ce4b68b94b7b87033582a8ac55ff>:0)
Test.SetProductFileAndVersionGUIDv3 (CryptlexProduct cryptlexProduct) (at Assets/Test.cs:314)
Test.IsProductGenuineV3 (CryptlexProduct cryptlexProduct) (at Assets/Test.cs:353)
Test.CheckLicense () (at Assets/Test.cs:398)
UnityEngine.Events.InvokableCall.Invoke () (at <a4546799a4ab426788e4204c69507924>:0)
UnityEngine.Events.UnityEvent.Invoke () (at <a4546799a4ab426788e4204c69507924>:0)
GenericEventEditorTriggerEditor.OnInspectorGUI () (at Assets/Scenes/Editor/GenericEventEditorTriggerEditor.cs:23)
UnityEditor.UIElements.InspectorElement+<>c__DisplayClass58_0.<CreateIMGUIInspectorFromEditor>b__0 () (at <e6e2fa0a47414cd2ac33237924761b45>:0)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

Still the dll is not recognized. This is really urgent, do you maybe have a developer for me to talk to, so we can work this out?

The nuget package supports following platforms:

Windows, MacOS and Linux.

In case of Android we offer C library for NDK, and Java AAR package.

We will try adding Android support in the nuget package and see if it works.

1 Like

Thank you very much! Can you give an approximate eta?

Implementation will be simple to just update the nuspec file:

and add the following line:

<file src="runtimes\android-arm64\native\*.so" target="runtimes\android-arm64\native" />

But our C library requires JNIEnv to be passed to the library. In the Java library we get JNIEnv from JNA:

I am not sure how one would get it in dotnet. Any suggestions to speed this up?

I don’t know. Maybe this could help?

We are now trying to use the aar. This seems to work partly. No DllNotFoundException anymore. Setting the product data works, but setting the product id gives us following error:

Insufficient system permissions.

LexActivator.SetProductData(“PASTE_CONTENT_OF_PRODUCT.DAT_FILE”); => WORKS

LexActivator.SetProductId(“PASTE_PRODUCT_ID”, LexActivator.PermissionFlags.LA_IN_MEMORY); => DOES NOT WORK

We are currently working on an android vr headset from htc. Also using LA_IN_MEMORY does yield the same error. Any ideas?

How are you using the AAR package in the C# app?

LexActivator.PermissionFlags.LA_IN_MEMORY won’t cause Insufficient system permissions. Can you confirm again?

We dropped the AAR package into Plugins/runtimes/arm64-v8a/lexactivator-3.19.1.aar and specified the platform Android only.
Does not work for the editor, does work for the Android device.

SetProductId with LA_USER does return “Insufficient system permissions.” and the app crashes.
SetProductId with LA_IN_MEMORY does return “Can’t find an fitting activation.” and app crashes

We haven’t tested this with a VR device yet. Only with Android phones, so we can’t guarantee this would work.

Is there any way we could make this work? This is really important for us, as we are planning a major release on a standalone VR device (vive focus 3).

We could use the API, couldn’t we? Just creating a client ourself in C#. This will most probably not cause this problem, won’t it?

Hello @LIKE_A_GUEST !

While this will not cause any problems, it will be difficult for us to provide support for a custom client.

I would suggest you try to use LexActivator.SetCustomDeviceFingerprint() with multiple strings before activating the license and let me know if it works.

Used a 64 byte long hash calculated by the devices name as fingerprint. Still returns “Can’t find an fitting activation” and “Failure!” as soon as SetProductId is called in LA_IN_MEMORY mode. After that the application starts to crash. So it does unfortunately not work.

Hello @LIKE_A_GUEST,

I’m sorry to hear that solution did not work for you. I did some digging and found that the Unity documentation suggests using the CallStatic() method to call Java or Kotlin static methods from C# scripts.

The method is part of their Java interop. It might be useful to use this till we can confirm a dedicated solution for your use case.

So, we got it at least not crashing our app anymore. We are also able to activate a license. Unfortunately IsLicenseGenuine & IsLicenseValid always returns LA_FAIL. Except before activation. This is really weird behavior. Do you know anything about this?

09-13 12:42:49.379 W  16:42:49.378UTC: Failed to get product key: The product id is incorrect.
09-13 12:42:49.379 W  16:42:49.379UTC: Cannot load license information to display in UI: product key not found
09-13 12:42:53.158 I  16:42:53.157UTC: GameInitialization:LicenseManager - Checking License for Version 3
09-13 12:42:53.161 I  16:42:53.160UTC: GameInitialization:LicenseManager - Setting GUID to GUID CUT v3
09-13 12:42:53.164 W  16:42:53.163UTC: GameInitialization:LicenseManager - Activation unsuccessful.
09-13 12:42:53.164 I  16:42:53.164UTC: GameInitialization:LicenseManager - Failure!
09-13 12:42:53.164 I  ReturnCode: 1
09-13 12:44:40.160 I  16:44:40.159UTC: GameInitialization:LicenseManager - Setting GUID to GUID CUT  v3
09-13 12:44:40.161 I  16:44:40.161UTC: GameInitialization:LicenseManager - Setting Product Key to: KEY CUT 
09-13 12:44:40.163 I  16:44:40.162UTC: GameInitialization:LicenseManager - Setting Activation Meta Data, Device Name:  DEVICE NAME CUT 
09-13 12:44:40.164 I  16:44:40.164UTC: GameInitialization:LicenseManager - Trying to activate the product
09-13 12:44:40.964 I  16:44:40.963UTC: GameInitialization:LicenseManager - Success!
09-13 12:44:40.964 I  ReturnCode: 0
09-13 12:44:40.965 I  16:44:40.965UTC: Email MAIL CUT  : fieldData CUT  
09-13 12:44:40.966 I  16:44:40.965UTC: GameInitialization:LicenseManager - The Email address matches the registrated Email address
09-13 12:44:40.966 I  16:44:40.966UTC: GameInitialization:LicenseManager - Activation Successful
09-13 12:46:46.831 W  16:46:46.830UTC: Failed to get product key: The product id is incorrect.
09-13 12:46:46.831 W  16:46:46.831UTC: Cannot load license information to display in UI: product key not found
09-13 12:46:50.649 I  16:46:50.649UTC: GameInitialization:LicenseManager - Checking License for Version 3
09-13 12:46:50.653 I  16:46:50.653UTC: GameInitialization:LicenseManager - Setting GUID to GUID CUT  v3
09-13 12:46:50.656 W  16:46:50.656UTC: GameInitialization:LicenseManager - Activation unsuccessful.
09-13 12:46:58.927 I  16:46:58.926UTC: GameInitialization:LicenseManager - Setting GUID to GUID CUT  v3
09-13 12:46:58.929 I  16:46:58.927UTC: GameInitialization:LicenseManager - Setting Product Key to:
09-13 12:46:58.932 E  16:46:58.931UTC: Invalid license key.

Glad you got it working. Can you share some code instead of the log so we can have a look?

Hey adnan,
sent you a DM with the relevant code.