Android, RenderScript from SupportLibrary and java.lang.NoClassDefFoundError

546 views Asked by At

I wanted to use RenderScript from the SupportLibrary to create a blur effekt.

For this I've found the solution from here https://stackoverflow.com/a/14988991/408780

final RenderScript rs;
rs = RenderScript.create( myAndroidContext );
final Allocation input = Allocation.createFromBitmap( rs, photo, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT );
final Allocation output = Allocation.createTyped( rs, input.getType() );
final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create( rs, Element.U8_4( rs ) );
script.setRadius( myBlurRadius /* e.g. 3.f */ );
script.setInput( input );
script.forEach( output );
output.copyTo( photo );

The problem is, that rs = RenderScript.create(myAndroidContext) causes java.lang.NoClassDefFoundError and I have no idea, what is going wrong.

According to https://developer.android.com/reference/android/support/v8/renderscript/ScriptIntrinsicBlur.html ScriptIntrinsicBlur was added in the version 23.

So I just added to the app gradle following lines:

android {
...
    defaultConfig {
        ...
        renderscriptTargetApi 23
        renderscriptSupportModeEnabled true
    }
... 
}

I also tried with renderscriptTargetApi 21 as described below https://github.com/react-native-community/react-native-blur/issues/110#issuecomment-272956182

But still no success. Any suggestions?

Maybe some additional infos:

minSdk = 14, targetSdk = 19, compileSdk = 25

Thank you in advance.

1

There are 1 answers

1
Miao Wang On

What is the build-tools version and gradle-plugin version you are using? Additional error messages would be helpful.

The code looks fine. The problem might be related to proguard configuration. Could you add the following:

-dontwarn android.support.v8.renderscript.*
-keepclassmembers class android.support.v8.renderscript.RenderScript {
  native *** rsn*(...);
  native *** n*(...);
}