Renderscript NoClassDefFound During Instrumented Test



我正在编写一个使用多个android.support.v8.renderscript函数的类的插测试。

在设备上正常运行时,渲染脚本不会引发任何错误。但是,在androidTest中出现以下错误:

java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v8/renderscript/Allocation;

build.gradle defaultConfig:

defaultConfig {
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0.0"
renderscriptTargetApi 28
renderscriptSupportModeEnabled true
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}

如何确保renderscript在测试期间可用?

该项目是开源的,您可以看到我正在测试的功能,blur()此处使用renderscript的位置:BlurKit。

我遇到的问题是在创建RenderScript对象期间。

RenderScript

rs = RenderScript.create(context(;

我收到的错误与您相同

java.lang.NoClassDefFoundError: 失败的解析: Landroid/support/v8/renderscript/Allocation;

我通过以下方式解决了这个问题

  1. renderscript-v8.jar从 Android SDK dir (Android\Sdk\build-tools\28.0.3\renderscript\lib\renderscript-v8.jar( 复制到 app module libs dir(即:app\libs. 如果不存在,则创建 libs 目录(

    项目\

    • .app\
      • 库\ 渲染脚本-v8.jar
  2. 在 app\build.gradle 中,将implementation files('libs/renderscript-v8.jar')添加到依赖项。

dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') .... implementation files('libs/renderscript-v8.jar') }

这些对我不起作用 renderscriptTargetApi 28 renderscriptSupportModeEnabled true

最新更新