Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.UnsatisfiedLinkError: No implementation found for java.lang.String when proguard enabled

Tags:

java

c++

android

I am getting the following error when I enable proguard.

java.lang.UnsatisfiedLinkError: No implementation found for java.lang.String com.osolutions.otv.utilities.al.b() (tried Java_com_osolutions_otv_utilities_al_b and Java_com_osolutions_otv_utilities_al_b__)
   at com.osolutions.otv.utilities.al.b(Native Method)
   at com.osolutions.otv.utilities.al.<clinit>(Unknown Source)
   at com.osolutions.otv.activity.SplashScreenActivity.a(Unknown Source)
   at com.osolutions.otv.activity.y.run(Unknown Source)
   at android.os.Handler.handleCallback(Handler.java:739)
   at android.os.Handler.dispatchMessage(Handler.java:95)
   at android.os.Looper.loop(Looper.java:148)
   at android.app.ActivityThread.main(ActivityThread.java:7331)
   at java.lang.reflect.Method.invoke(Native Method)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

I have initialized the Cpp class also using

static {
     System.loadLibrary("baseUrl");
}

If I disable proguard it works fine. This is the case when proguard is enabled.

like image 578
bhaskar Avatar asked Jul 09 '19 08:07

bhaskar


People also ask

What does unsatisfiedlinkerror mean in Java?

java.lang.UnsatisfiedLinkError: /opt/IBM/ondemand/V10.x/www/libars3wapi32.a (A file or directory in the path name does not exist.) This error indicates GSKit cannot be found by ODWEK.

What does unsatisfiedlinkerror-gskit cannot be found by odwek mean?

java.lang.UnsatisfiedLinkError: /opt/IBM/ondemand/V10.x/www/libars3wapi32.a (A file or directory in the path name does not exist.) This error indicates GSKit cannot be found by ODWEK. Use the ldd command on Unix and Linux to confirm GSKit can be located by ODWEK. For example, on AIX, run the command ldd /opt/IBM/ondemand/V10.x/www/libars3wapi32.a

How does Java load native libraries at runtime?

Java loads native libraries at runtime by invoking the System.load () or the System.loadLibrary () method. The main difference between the two is that the latter doesn’t require the absolute path and file extension of the library to be specified—it relies on the java.library.path system property instead.

Why is ocijdbc11 DLL not found in Java library?

If you look at the error you will find that Java is complaining that ocijdbc11 dll is not found in java.library.path. If you further look then you will say that Oracle Driver is using System.loadLibrary() method to load the native library , which explains why Java is searching for dll in java.library.path .


1 Answers

As @Botje suggests, it looks like the problem in your case is that the native name and the definition of your method in Java side get out of sync, so to speak.

Your public native String myMethod(); gets changed to public native String b(); by ProGuard, but your native implementation keeps the original name. That's why the Java runtime cannot find it.

You need to add the following to your ProGuard file:

-keepclasseswithmembernames,includedescriptorclasses class * {
    native <methods>;
}

Please, do NOT mark this answer as the solution, as it was @Botje who came with it (I just developed the explanation a little further).

@Botje please add your own answer so he can mark it as the solution.

like image 181
Xavier Rubio Jansana Avatar answered Oct 22 '22 22:10

Xavier Rubio Jansana