简体   繁体   English

Android - Renderscript支持库 - 加载RS jni库时出错

[英]Android - Renderscript Support Library - Error loading RS jni library

I am trying to include the Renderscript support library into my project. 我试图将Renderscript支持库包含到我的项目中。 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. 我没有使用任何Renderscript jar文件,我试图通过Gradle使用它。

Here are my Gradle.build files 这是我的Gradle.build文件

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. 我尝试并在stackoverflow上找到可能的解决方案的一切都无法正常工作。 I also have this included in my proguard config 我也将这个包含在我的proguard配置中

#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. 编辑:这是我实际使用renderscript的实现,这也是导致我的应用程序在调用时崩溃的地方。

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() );

Unfortunately Renderscript is not available for the armeabi architecture. 不幸的是,Renderscript不适用于armeabi架构。 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: 好的一面是,您可以在运行时检查以查看设备的体系结构,而不是在这些设备上运行Renderscript代码:

System.getProperty("os.arch");

There is also an issue open on the android bug tracker, where they state: android bug跟踪器上还有一个问题,它们声明:

We only ship the support library for armeabi-v7a. 我们只发运armeabi-v7a的支持库。 This is a known limitation. 这是一个已知的限制。

https://code.google.com/p/android/issues/detail?id=68520 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 . 编辑:如果要在armeabi设备上实现没有Renderscript的模糊,可以使用Bitmap.createScaledBitmap设置filter将图像缩小到true

In general, you can solve that by unzipping your apk file, then check lib folder. 一般情况下,您可以解压缩您的apk文件,然后检查lib文件夹。 lib folder contains native libraries grouped by different system architectures (arm64-v8a, armeabi, armeabi-v7a, mips, x86, etc). lib文件夹包含按不同系统体系结构分组的本机库(arm64-v8a,armeabi,armeabi-v7a,mips,x86等)。

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. 有时某些库仅存在于某些系统体系结构而不是所有体系结构中,因此在使用此本机库中的任何代码(例如Renderscript支持库)之前,您需要首先检查系统体系结构。

For Renderscript exception, you can do something like that 对于Renderscript异常,您可以执行类似的操作

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
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 androidx renderscript crash“加载RS jni库时出错:java.lang.UnsatisfiedLinkError:从JNI_OnLoad返回的JNI_ERR” - androidx renderscript crash “Error loading RS jni library: java.lang.UnsatisfiedLinkError: JNI_ERR returned from JNI_OnLoad” Proguard + RenderScript 支持库错误 - Proguard + RenderScript support library error 在没有支持库的Android中设置Renderscript - Set Up Renderscript In Android Without Support Library IllegalAccessError 与 RenderScript 支持库 - IllegalAccessError with RenderScript Support library Renderscript通过支持库 - Renderscript via the support library Renderscript支持库存在问题 - Problems with the Renderscript support library 加载RS jni库时出错:UnsatisfiedLinkError:无法加载RSSupport:findLibrary返回null - Error loading RS jni library: UnsatisfiedLinkError: Couldn't load RSSupport: findLibrary returned null Android-运行应用程序时加载JNI库时出错 - Android - Error loading JNI library when running an app 尝试在Android手机上使用RenderScript支持库模糊图像时出错 - Error when trying to blur image using RenderScript support library on android phone Android Studio当前不支持使用支持库RenderScript API? - Use of Support Library RenderScript APIs is not currently supported with Android Studio?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM