0

我想使用 SupportLibrary 中的 RenderScript 来创建模糊效果。

为此,我从这里找到了解决方案 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 );

问题是, rs = RenderScript.create(myAndroidContext) 导致 java.lang.NoClassDefFoundError ,我不知道出了什么问题。

根据https://developer.android.com/reference/android/support/v8/renderscript/ScriptIntrinsicBlur.html ScriptIntrinsicBlur 在版本 23 中添加。

所以我只是在应用程序 gradle 中添加了以下几行:

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

我还尝试了如下所述的 renderscriptTargetApi 21 https://github.com/react-native-community/react-native-blur/issues/110#issuecomment-272956182

但仍然没有成功。有什么建议么?

也许一些额外的信息:

minSdk = 14,targetSdk = 19,compileSdk = 25

先感谢您。

4

1 回答 1

0

您使用的 build-tools 版本和 gradle-plugin 版本是什么?其他错误消息会有所帮助。

代码看起来不错。该问题可能与 proguard 配置有关。您能否添加以下内容:

-dontwarn android.support.v8.renderscript.*
-keepclassmembers class android.support.v8.renderscript.RenderScript {
  native *** rsn*(...);
  native *** n*(...);
}
于 2017-05-23T00:23:24.213 回答