【问题标题】:Android, RenderScript from SupportLibrary and java.lang.NoClassDefFoundErrorAndroid,来自 SupportLibrary 的 RenderScript 和 java.lang.NoClassDefFoundError
【发布时间】:2017-05-23 08:23:24
【问题描述】:

我想使用 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.htmlScriptIntrinsicBlur 是在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

提前谢谢你。

【问题讨论】:

    标签: android android-support-library android-renderscript


    【解决方案1】:

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

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

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

    【讨论】:

    • 很抱歉回答迟了。但是……还是一样,build-tools 版本 25.0.2,gradle-plugin 版本 2.1.2
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-28
    • 2016-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多