android - RenderScript V8 定义了多个 dex 文件

标签 android gradle android-studio renderscript

我正在尝试让它工作一段时间。
我正在使用 StackBlur 模块 https://github.com/kikoso/android-stackblur 这是 Graddle 文件的样子:

apply plugin: 'android-library'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile fileTree(dir: "$buildDir/native-libs", include: 'native-libs.jar')
}

android {
    compileSdkVersion 21
    buildToolsVersion '21.1.2'

    defaultConfig {
        renderscriptTargetApi 19
        renderscriptSupportModeEnabled true
    }

sourceSets {
    main {
        manifest.srcFile 'AndroidManifest.xml'
        java.srcDirs = ['src']
        resources.srcDirs = ['src']
        aidl.srcDirs = ['src']
        renderscript.srcDirs = ['src']
        res.srcDirs = ['res']
        assets.srcDirs = ['assets']
    }

    // Move the tests to tests/java, tests/res, etc...
    instrumentTest.setRoot('tests')

    // Move the build types to build-types/<type>
    // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
    // This moves them out of them default location under src/<type>/... which would
    // conflict with src/ being used by the main source set.
    // Adding new build types or product flavors should be accompanied
    // by a similar customization.
    debug.setRoot('build-types/debug')
    release.setRoot('build-types/release')
}
}

    task nativeLibsToJar(type: Zip, description: 'create a jar archive of the native libs') {
        destinationDir file("$buildDir/native-libs")
        baseName 'native-libs'
        extension 'jar'
        from fileTree(dir: 'libs', include: '**/*.so')
        from fileTree(dir: 'renderscript', include: '**/*.so')
        into 'lib/'
    }

    tasks.withType(JavaCompile) {
        compileTask -> compileTask.dependsOn(nativeLibsToJar)
    }

这个库中的一切都完美无缺。但是,当我尝试在自己的项目中使用我自己的代码使用 RenderScript 时。麻烦开始了。如果我没有将 RenderScript 放入我的应用程序 gradle 文件中,我会收到错误消息:

加载 RS jni 库时出错:java.lang.UnsatisfiedLinkError:无法从加载器 dalvik.system.PathClassLoader[] 加载 RSSupport:findLibrary 返回 null

当我将 renderscript 值放入我自己的 Gradle 文件中时,开始出现 dex 文件异常:

意外的顶级异常:

com.android.dex.DexException: Multiple dex files define Landroid/support/v8/renderscript/Allocation$1;

dexfile 异常显然会发生,因为它们都添加了 RenderScriptSupportEnabled true 和 RenderScriptTargetApi。但我不知道我需要做什么才能让它们都起作用。每当我在自己的 gradle 中删除渲染脚本时,我的项目将无法运行,但当我在 StackBlur 模块中删除它时,该项目将无法运行。

有什么建议吗?
这是我的 gradle 文件:

apply plugin: 'com.android.application'
android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"
    defaultConfig {
        applicationId "package.name.app"
        minSdkVersion 17
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
        renderscriptSupportModeEnabled true
        renderscriptTargetApi 19

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:21+'
    compile 'com.android.support:support-v4:21.0.2'
    compile 'com.android.support:cardview-v7:21.0.+'
    compile 'com.android.support:recyclerview-v7:21.0.+'
    compile project(':StackBlur')
}

最佳答案

在第 26 次尝试之后,我发现这些行给我带来了问题:

dependencies {
   compile fileTree(dir: 'libs', include: '*.jar')
   compile fileTree(dir: "$buildDir/native-libs", include: 'native-libs.jar')
}

我不得不删除这些,并清理项目。

关于android - RenderScript V8 定义了多个 dex 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27662743/

相关文章:

android - Android Studio 0.8.6不会自动与Gradle文件同步

java - 如何根据显着光值使振动不同?

android - Gradle:强制使用存储库作为依赖项

基于Android Fragment的开源项目

android - 适用于 Android NDK 的 Googletest

gradle - Libgdx 和 gradle 模块

jaxb - Gradle 中的自定义任务构建顺序

Android Studio 从存储库导入 aar 文件使依赖项消失

Android Studio 不为我的导入项目生成 R.java

android - 混合依赖版本的可能影响