Renderscript broken with AndroidX?

跟風遠走 提交于 2019-12-14 03:45:12

问题


Since I've migrated to androidx I can't make Renderscript run. I'm getting following exception:

2018-10-12 16:27:58.328 27195-27195/pl.qus.xenoamp2 A/zygote64: java_vm_ext.cc:504] JNI DETECTED ERROR IN APPLICATION: JNI NewGlobalRef called with pending exception java.lang.ClassNotFoundException: Didn't find class "android.support.v8.renderscript.RenderScript" on path: DexPathList[[zip file "/data/app/pl.qus.xenoamp2-xHJAddeg9oM-uGSxlvMp7A==/base.apk"],nativeLibraryDirectories=[/data/app/pl.qus.xenoamp2-xHJAddeg9oM-uGSxlvMp7A==/lib/arm64, /data/app/pl.qus.xenoamp2-xHJAddeg9oM-uGSxlvMp7A==/base.apk!/lib/arm64-v8a, /system/lib64, /system/vendor/lib64]] 2018-10-12 16:27:58.328 27195-27195/pl.qus.xenoamp2 A/zygote64: java_vm_ext.cc:504] at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:93) 2018-10-12 16:27:58.328 27195-27195/pl.qus.xenoamp2 A/zygote64: java_vm_ext.cc:504] at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:379) 2018-10-12 16:27:58.328 27195-27195/pl.qus.xenoamp2 A/zygote64: java_vm_ext.cc:504] at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312) 2018-10-12 16:27:58.328 27195-27195/pl.qus.xenoamp2 A/zygote64: java_vm_ext.cc:504] at java.lang.String java.lang.Runtime.nativeLoad(java.lang.String, java.lang.ClassLoader, java.lang.String) (Runtime.java:-2) 2018-10-12 16:27:58.328 27195-27195/pl.qus.xenoamp2 A/zygote64: java_vm_ext.cc:504] at java.lang.String java.lang.Runtime.doLoad(java.lang.String, java.lang.ClassLoader) (Runtime.java:1099) 2018-10-12 16:27:58.328 27195-27195/pl.qus.xenoamp2 A/zygote64: java_vm_ext.cc:504] at void java.lang.Runtime.loadLibrary0(java.lang.ClassLoader, java.lang.String) (Runtime.java:1014) 2018-10-12 16:27:58.328 27195-27195/pl.qus.xenoamp2 A/zygote64: java_vm_ext.cc:504] at void java.lang.System.loadLibrary(java.lang.String) (System.java:1657) 2018-10-12 16:27:58.328 27195-27195/pl.qus.xenoamp2 A/zygote64: java_vm_ext.cc:504] at androidx.renderscript.RenderScript androidx.renderscript.RenderScript.internalCreate(android.content.Context, int, androidx.renderscript.RenderScript$ContextType, int) (RenderScript.java:1408) 2018-10-12 16:27:58.328 27195-27195/pl.qus.xenoamp2 A/zygote64: java_vm_ext.cc:504] at androidx.renderscript.RenderScript androidx.renderscript.RenderScript.create(android.content.Context, int, androidx.renderscript.RenderScript$ContextType, int) (RenderScript.java:1599) 2018-10-12 16:27:58.328 27195-27195/pl.qus.xenoamp2 A/zygote64: java_vm_ext.cc:504] at androidx.renderscript.RenderScript androidx.renderscript.RenderScript.create(android.content.Context, androidx.renderscript.RenderScript$ContextType, int) (RenderScript.java:1549) 2018-10-12 16:27:58.328 27195-27195/pl.qus.xenoamp2 A/zygote64: java_vm_ext.cc:504] at androidx.renderscript.RenderScript androidx.renderscript.RenderScript.create(android.content.Context, androidx.renderscript.RenderScript$ContextType) (RenderScript.java:1525) 2018-10-12 16:27:58.328 27195-27195/pl.qus.xenoamp2 A/zygote64: java_vm_ext.cc:504] at androidx.renderscript.RenderScript androidx.renderscript.RenderScript.create(android.content.Context) (RenderScript.java:1512)

I have usual entries in gradle:

    renderscriptTargetApi 18
    renderscriptSupportModeEnabled true

Anything else I have to change?


回答1:


I had the same issue, i switched to non support version of renderscript

In project gradle

renderscriptTargetApi 17
renderscriptSupportModeEnabled false

And in the class that use renderscript

import android.renderscript.RenderScript

instead of

import androidx.renderscript.RenderScript

It did the job for me but i don't like this solution, to be completed




回答2:


There was an issue with the build tools (the prebuilt librsjni_androidx.so, to be exact), and is now fixed in version 29.0.2.

I've verified this by upgrading compile sdk to API 29 and build tools to 29.0.2.

Edit: This is what I've configured in build.gradle:

    renderscriptTargetApi 18
    renderscriptSupportModeEnabled true



回答3:


The marked answer does make it work, but as @Zee mentioned, it seems that the non-support regular renderscript removes 64-bit compatibility. Now I got a warning message from Google Play console about it when trying to publish my app. So I guess if we are still using renderscript, we will have to stay with support version and not migrate to AndroidX for now.




回答4:


I was able to solve the problem by changing the version of buildToolsVersion to 29.0.2 and renderscriptTargetApi to 29:

android {
    // ...
    buildToolsVersion '29.0.2'
    defaultConfig {
        // ...
        renderscriptTargetApi 29
        renderscriptSupportModeEnabled true
    }
    // ...
}


来源:https://stackoverflow.com/questions/52781821/renderscript-broken-with-androidx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!