Android - Renderscript Support Library - Error loading RS jni library

两盒软妹~` 提交于 2019-12-18 17:32:31

问题


I am trying to include the Renderscript support library into my project. I am getting the following error.

android.support.v8.renderscript.RSRuntimeException: Error loading RS jni library: java.lang.UnsatisfiedLinkError: Couldn't load rsjni: findLibrary returned null

I am not using any Renderscript jar files, I am attempting to use it via Gradle.

Here are my Gradle.build files

TOP LEVEL

buildscript {
repositories {
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:1.2.3'
}
}

ext {
compileSdkVersion="Google Inc.:Google APIs:22"
buildToolsVersion="23.0.1"
playStoreMinSdkVersion=16
amazonStoreMinSdkVersion=8
targetSdkVersion=22
versionCode=20
versionName="3.3.0"
runProguard=true
zipAlign=true
proguardConfiguration='../proguard.config'
}

allprojects {
repositories {
    jcenter()
}
}

Application Specific

defaultConfig {
    applicationId "**REMOVED**"
    //noinspection GroovyAssignabilityCheck
    targetSdkVersion rootProject.ext.targetSdkVersion
    //noinspection GroovyAssignabilityCheck
    versionCode rootProject.ext.versionCode
    //noinspection GroovyAssignabilityCheck
    versionName rootProject.ext.versionName

    renderscriptTargetApi 23
    renderscriptSupportModeEnabled true
}

Everything I try & find as possible solutions on stackoverflow are not working. I also have this included in my proguard config

#RenderScript
-keepclasseswithmembernames class * {
native <methods>;
}
-keep class android.support.v8.renderscript.** { *; }

Edit: Here is the implementation where I actually use renderscript, also this is where it causes my app the crash when called.

public static BitmapDrawable Blur ( View view ){

    Bitmap image = GetScreenshot( view );

    int width = Math.round( image.getWidth() * DEFAULT_BITMAP_SCALE );
    int height = Math.round( image.getHeight() * DEFAULT_BITMAP_SCALE );

    Bitmap inputBitmap = Bitmap.createScaledBitmap( image, width, height, false );

    Bitmap outputBitmap = Bitmap.createBitmap( inputBitmap );

    RenderScript rs = RenderScript.create( view.getContext() );
    ScriptIntrinsicBlur intrinsicBlur = ScriptIntrinsicBlur.create( rs, Element.U8_4(rs) );

    Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);
    Allocation tmpOut = Allocation.createFromBitmap( rs, outputBitmap );

    intrinsicBlur.setRadius( DEFAULT_BLUR_RADIUS );
    intrinsicBlur.setInput( tmpIn );
    intrinsicBlur.forEach( tmpOut );

    tmpOut.copyTo( outputBitmap );

    inputBitmap.recycle();
    rs.destroy();

    return new BitmapDrawable( outputBitmap );
}

This is the exact line

RenderScript rs = RenderScript.create( view.getContext() );

回答1:


Unfortunately Renderscript is not available for the armeabi architecture. The bright side is that you can check at runtime to see the architecture of the device and not run the Renderscript code on those devices:

System.getProperty("os.arch");

There is also an issue open on the android bug tracker, where they state:

We only ship the support library for armeabi-v7a. This is a known limitation.

https://code.google.com/p/android/issues/detail?id=68520

Edit: If you want to implement a blur without Renderscript on armeabi devices, you can simply downscale the image with Bitmap.createScaledBitmap setting filter to true.




回答2:


In general, you can solve that by unzipping your apk file, then check lib folder. lib folder contains native libraries grouped by different system architectures (arm64-v8a, armeabi, armeabi-v7a, mips, x86, etc).

Sometimes some libraries exist only for some system architectures not all architectures, so you need to check system architecture first before using any code from this native library for example Renderscript support library.

For Renderscript exception, you can do something like that

ArrayList<String> abis = new ArrayList<>();

 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
   abis.add(Build.CPU_ABI);
 } else {
    for (String abi : Build.SUPPORTED_ABIS) {
        abis.add(abi);
    }
 }

 if (abis.contains("x86") || abis.contains("mips") || abis.contains("armeabi-v7a")) {
   // do Renderscript stuff
 }


来源:https://stackoverflow.com/questions/32786838/android-renderscript-support-library-error-loading-rs-jni-library

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