Search Unity

Question Unity don't find java-interop library

Discussion in 'Android' started by Clashman, Jun 3, 2021.

  1. Clashman

    Clashman

    Joined:
    Feb 18, 2019
    Posts:
    53
    Hi !
    I use java-interop dll file to use android functions.
    When I added the file in my assets, there no more errors in my console.
    However, the android logcat shows me "DllNotFoundException : java-interop" when a function which use Android functions is active...
    What can I do to resolve this problem ?

    Thanks for answers !
     
  2. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,920
    What is java-interop and where do you get it?
     
  3. Clashman

    Clashman

    Joined:
    Feb 18, 2019
    Posts:
    53
    It's a dll file. I need it to call java functions in my c# scripts.
    I found it in the folder pf Visual Studio program :
    "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0".
     
  4. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,920
    If it's a native dll, you cannot use it on Android platform, it's usable only on Windows.
     
  5. Clashman

    Clashman

    Joined:
    Feb 18, 2019
    Posts:
    53
    Are you sure ?
    Xamarin framework on vscode which make us to create android/IOS app use Mono.Android.dll and Mono.Android use java.interop.dll...
     
    Last edited: Jun 22, 2021
  6. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,920
    Maybe it's a managed assembly, I am not sure, but dynamic libraries on Android have to have .so extension.
     
  7. Clashman

    Clashman

    Joined:
    Feb 18, 2019
    Posts:
    53
    I think the dll is detected by the editor but the build doesn't find it.
     
  8. Clashman

    Clashman

    Joined:
    Feb 18, 2019
    Posts:
    53
    I have some news : I 'm using Java.Interop plugin and I have to use java-interop. It's not the same. However, I don't know how to find java-interop...
     
  9. RahulJain07

    RahulJain07

    Joined:
    Sep 9, 2020
    Posts:
    15
    Facing the exact same issue. I am using Mono.Android.dll. All the other dlls are correctly referenced in the apk but it cant find java-interop. I have included java.interop.dll in Plugins/Android
     
  10. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,736
    Based on messages above the java.interop.dll is a native dll file, not .NET dll, so it won't work on Android.
     
  11. RahulJain07

    RahulJain07

    Joined:
    Sep 9, 2020
    Posts:
    15
    Hi @Aurimas-Cernius, thanks for the reply, But when I include the dll (java.interop.dll) in my Unity project it recognizes it as a managed .NET lib.
     

    Attached Files:

  12. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,736
    How is that library used then? Or ss it used by Mono.Android.dll internally?
     
  13. RahulJain07

    RahulJain07

    Joined:
    Sep 9, 2020
    Posts:
    15
    Yes by Mono.Android.dll Internally. I am basically trying to convert a Xamarin project to unity which consists of about 20+ libs (dlls). I am able to reference all of them in my unity project as all are .Net 4.x libs. The only issue is that some of the libs internally references java.interop and Mono.Android (which in turn references java.interop) . Therefore, I copied these two libs which comes along with VS Xamarin installation. But now I am stuck on Dllnotfound: java-interop.

    Basically in the Xamarin project the libs which have dependency on these two libs are used in the MainActivity.cs to initialize native android processes like wifi / bluetooth communication. The problem is there is no such MainActivity.cs file in Unity the analogous to it is you can export the unity project to android studio and there is UnityPlayerActivity.java but as I don't have the source code for these dlls in cannot write the same functionality in UnityPlayerActivity.java and I also cannot import managed dlls in java. So I have to use the libs in unity itself.
     
  14. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,920
    Could you unzip apk and manually check if that dll is present?
     
  15. RahulJain07

    RahulJain07

    Joined:
    Sep 9, 2020
    Posts:
    15
    Your guess is correct, I unzipped the apk and only these two dlls are missing. Dont understand the logic at all.
     
  16. RahulJain07

    RahulJain07

    Joined:
    Sep 9, 2020
    Posts:
    15
    ohh Sorry, I check the old apk in which I didn't included these dlls while compiling. In the new apk the dll is present.
     
  17. RahulJain07

    RahulJain07

    Joined:
    Sep 9, 2020
    Posts:
    15
    I suppose the error is not related to this dll because on extensive browsing I found that java.interop.dll has dependency on other libs like libjava-interop.so and so on. I am not able to find these libs anywhere hence these are not included in the project and the error is due to these libs missing.
     
  18. RahulJain07

    RahulJain07

    Joined:
    Sep 9, 2020
    Posts:
    15
    Following is the adb error stack from the android device

    DllNotFoundException: java-interop
    11-24 15:35:36.244 4311 4436 E Unity : at (wrapper managed-to-native) Java.Interop.NativeMethods.java_interop_jvm_list(intptr[],int,int&)
    11-24 15:35:36.244 4311 4436 E Unity : at Java.Interop.JniRuntime.GetCreatedJavaVMs (System.IntPtr[] handles, System.Int32 bufLen, System.Int32& nVMs) [0x00000] in <1959115d56f8444789986cf39185638c>:0
    11-24 15:35:36.244 4311 4436 E Unity : at Java.Interop.JniRuntime.GetAvailableInvocationPointers () [0x00000] in <1959115d56f8444789986cf39185638c>:0
    11-24 15:35:36.244 4311 4436 E Unity : at Java.Interop.JniRuntime.get_CurrentRuntime () [0x00095] in <1959115d56f8444789986cf39185638c>:0
    11-24 15:35:36.244 4311 4436 E Unity : at Java.Interop.JniEnvironmentInfo..ctor () [0x00006] in <1959115d56f8444789986cf39185638c>:0
    11-24 15:35:36.244 4311 4436 E Unity : at Java.Interop.JniEnvironment+<>c.<.cctor>b__35_0 () [0x00000] in <1959115d56f8444789986cf39185638c>:0
    11-24 15:35:36.244 4311 4436 E Unity : at System.Threading.ThreadLocal`1[T].GetValueSlow () [0x00031] in <695d1cc93cca45069c528c15c9fdd749>:0
    11-24 15:35:36.244 4311 4436 E Unity : at System.Threading.ThreadLocal`1[T].get_Value () [0x0003e] in <695d1cc93cca45069c528c15c9fdd749>:0
    11-24 15:35:36.244 4311 4436 E Unity : at Java.Interop.JniEnvironment+Strings.NewString (System.Char* unicodeChars, System.Int32 l
     
  19. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,920
    Your guess is correct it's trying to access native libjava-interop.so. The 'lib' prefix is stripped in these cases