17

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?

ssuukk
  • 8,200
  • 7
  • 35
  • 47
  • 2
    I'm also having issues with renderscript... it crashes my app with a fatal signal11 pre API21 – Patric Oct 19 '18 at 04:32

8 Answers8

19

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

  • This solved it for me as well, it was crashing on API 21 before. renderscriptTargetApi can be at least the same as your minSdkVersion though I think. – ZeroStatic Nov 29 '18 at 10:27
  • Strange! Seems only broken with AndroidX. Works like a charm with the legacy support library – Sdghasemi Jan 05 '19 at 12:42
  • What do you miss out on by turning renderscriptSupportMode off? – wz2b Jan 25 '19 at 15:40
  • 1
    Guys, I've kinda found a problem with this. It seems that changing from the support libraries (android.support.v8.renderscript) to the regular renderscript libraries (android.renderscript.RenderScript), removes 64-bit compatibility. This means your app will no longer be supported by 1 Aug on the playstore for 64 bit phones. Has anyone found a solution for this??? – Zee Jun 04 '19 at 13:06
  • @Zee it seems that you need bump your `renderscriptTargetApi` to 21 or later to get 64-bit support - https://developer.android.com/distribute/best-practices/develop/64-bit#renderscript-and-64-bit – npace Aug 07 '19 at 09:57
  • Where can I find androidx.renderscript.RenderScript? Which androidx artifact contains it as I was not able to find it on packages reference list https://developer.android.com/reference/androidx/packages – Marcin Bak Oct 16 '19 at 07:57
  • Worked for me, set renderscriptTargetApi = minSdkVersion = 21. renderscriptSupportModeEnabled = false. App was crashing on API21 aswell. Works now. Thanks! – seed_87 Oct 29 '19 at 16:36
7

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
bosphere
  • 388
  • 3
  • 7
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
    }
    // ...
}
Vergiliy
  • 1,248
  • 1
  • 13
  • 22
  • 1
    YAY! This works :) also checked and it does not cause the bit 64 issue. – Zee Feb 28 '20 at 13:28
  • Wait, it still crashes on Android 6 :( sigh. Does anyone actually have a solution for this? – Zee Mar 19 '20 at 14:13
  • There was no need to update `renderscriptTargetApi` to 29 in my case. I have set it to 19, while I use RS features from 21. Updating `buildToolsVersion` and also updating the pro-guard rules worked for me. – Petrakeas Apr 15 '20 at 12:41
4

in my gradle module file I had:

renderscriptTargetApi 19
renderscriptSupportModeEnabled true

And, I had the following imports before migrating to AndroidX:

import android.support.v8.renderscript.Allocation;
import android.support.v8.renderscript.Element;
import android.support.v8.renderscript.Matrix4f;
import android.support.v8.renderscript.RenderScript;
import android.support.v8.renderscript.ScriptIntrinsicBlur;
import android.support.v8.renderscript.ScriptIntrinsicColorMatrix;
import android.support.v8.renderscript.ScriptIntrinsicConvolve3x3;

After migrating to AndroidX, just like the documentation says:

I kept the same statements on my gradle module file, but I upgraded to buildToolsVersion 29.0.2 and my compileSdkVersion to 28

I changed the previous imports to the following, and it all works.

import androidx.renderscript.Matrix4f;
import androidx.renderscript.RenderScript;
import androidx.renderscript.Allocation;
import androidx.renderscript.Element;
import androidx.renderscript.ScriptIntrinsicBlur;
import androidx.renderscript.ScriptIntrinsicColorMatrix;
import androidx.renderscript.ScriptIntrinsicConvolve3x3;
ChrisK0043
  • 91
  • 7
3

I fixed by adding proguard: I got answer from google supporter here

-keepclasseswithmembernames,includedescriptorclasses class * {
native <methods>;
}
# RenderScript to be safe on "native callback" side
-keep class androidx.renderscript.** { *; }
Duong.Nguyen
  • 373
  • 3
  • 13
2

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.

NinjaCoder
  • 31
  • 2
  • 1
    I published an app (closed alpha) in Google Play with RenderScript **without support mode** and I got no warnings. But I did notice the filesize is about 2MB smaller, and the `Native platforms` in Google Play are listed as `None`. With support mode enabled, there were 4 (`arm64-v8a, armeabi-v7a, x86, x86_64`). – lenooh Jun 30 '19 at 12:00
  • ok setting renderscriptSupportModeEnabled to false does the trick (I think) for the Android 6 issue and then having renderscriptTargetApi on 22 solves the 64 bit issue. But after all that, we still get a crash on Xiomi Redmi Go (android 8.1 ???). Hope this helps someone – Zee Mar 26 '20 at 14:00
1
android {
    //...
    defaultConfig {
        //...

        renderscriptTargetApi 21
        renderscriptSupportModeEnabled true
    }
}
ilidiocn
  • 323
  • 2
  • 5
  • 1
    This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/low-quality-posts/29545641) – vakio Aug 07 '21 at 14:02
  • @vakio: Why isn’t it an answer? It would be more _useful_ with an explanation, and especially to differentiate it from existing answers, but it looks like an answer to me. – Jeremy Caney Aug 08 '21 at 02:28
  • The templates to choose from when reviewing are not always 100% in line with what the problem is. It is an answer, but not a complete answer. And there are similar answers so it would be helpful if there was an explanation as to why this answer is different – vakio Aug 08 '21 at 06:45
  • I´m providing what is necessary to fix your error, so if you have question, please let me know it, so for this error especially place the code to your gradle file – ilidiocn Aug 09 '21 at 13:05
0

I had the same problem. The only thing that worked for me (after trying some of these), was updating to the latest build tools version (29.0.3) which I'm not sure existed when these question was originally posted:

buildToolsVersion '29.0.3'
codingjeremy
  • 5,215
  • 1
  • 36
  • 39