Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JNA 5.3.0 access classes missing on android without reflection #1089

Closed
matthiasblaesing opened this issue Apr 25, 2019 · 2 comments · Fixed by #1090
Closed

JNA 5.3.0 access classes missing on android without reflection #1089

matthiasblaesing opened this issue Apr 25, 2019 · 2 comments · Fixed by #1090

Comments

@matthiasblaesing
Copy link
Member

matthiasblaesing commented Apr 25, 2019

Reported on the mailinglist:

Running my app using JNA 5.3.0 on OS versions prior to Android 8.0 (API level 26) results in the following stack trace:

--------- beginning of crash

04-24 17:02:35.617 12484-12484/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.bugsbegone.myapp, PID: 12484
java.lang.NoClassDefFoundError: Failed resolution of: Ljava/lang/invoke/MethodType;
at com.sun.jna.internal.ReflectionUtils.(ReflectionUtils.java:77)
at com.sun.jna.internal.ReflectionUtils.isDefault(ReflectionUtils.java:135)
at com.sun.jna.Library$Handler.invoke(Library.java:231)
at java.lang.reflect.Proxy.invoke(Proxy.java:393)
at com.bugsbegone.myapp.$Proxy2.mylib_init(Unknown Source)
[... My app specific trace ...]
at android.app.Activity.performCreate(Activity.java:6270)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2382)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493)
at android.app.ActivityThread.access$1000(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1357)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5446)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:743)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:633)
Caused by: java.lang.ClassNotFoundException: Didn't find class "java.lang.invoke.MethodType" on path:
DexPathList[[zip file "/data/app/com.bugsbegone.myapp-1/base.apk",
zip file "/data/app/com.bugsbegone.myapp-1/split_lib_dependencies_apk.apk",
zip file "/data/app/com.bugsbegone.myapp-1/split_lib_slice_0_apk.apk",
[... lots of slices ...]
zip file "/data/app/com.bugsbegone.myapp-1/split_lib_slice_9_apk.apk"],
nativeLibraryDirectories=[/data/app/com.bugsbegone.myapp-1/lib/x86_64,
/data/app/com.bugsbegone.myapp-1/base.apk!/lib/x86_64,
/data/app/com.bugsbegone.myapp-1/split_lib_dependencies_apk.apk!/lib/x86_64,
/data/app/com.bugsbegone.myapp-1/split_lib_slice_0_apk.apk!/lib/x86_64,
[... lots of slices ...]
/data/app/com.bugsbegone.myapp-1/split_lib_slice_9_apk.apk!/lib/x86_64,
/vendor/lib64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at com.sun.jna.internal.ReflectionUtils.(ReflectionUtils.java:77)
at com.sun.jna.internal.ReflectionUtils.isDefault(ReflectionUtils.java:135)
at com.sun.jna.Library$Handler.invoke(Library.java:231)
at java.lang.reflect.Proxy.invoke(Proxy.java:393)
at com.bugsbegone.myapp.$Proxy2.mylib_init(Unknown Source)
[... My app specific trace ...]
at android.app.Activity.performCreate(Activity.java:6270)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2382)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493)
at android.app.ActivityThread.access$1000(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1357)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5446)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:743)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:633)
Suppressed: java.lang.ClassNotFoundException: java.lang.invoke.MethodType
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 21 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available

The breaking change is [GITHUB-813] Support binding interfaces containing default methods, which resolves #813.
Unfortunately, the MethodType class doesn't exist in Android until API level 26 (https://developer.android.com/reference/java/lang/invoke/MethodType).

It would be a shame to have to undo this new feature for backwards compatibility, but it does wipe out JNA support on >75% of current android devices.
Maybe a separate branch for Android would be the best way to allow bug fixes etc. to continue, but without any of the unsupported Java7+ features?

@matthiasblaesing
Copy link
Member Author

A suggested fix was created as #1090. Here is a test build:

dist.zip

@matthiasblaesing
Copy link
Member Author

Reply on mailinglist:

Tested on APIs down to 17 (NDK rev. 17 support stops at android-16 anyway).
It works perfectly, thank you!

Typo, android-16 became the minimum in NDK rev. 18.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant