RenderScript V8定义了多个dex文件

时间:2014-12-26 22:44:55

标签: 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放入我的App graddle文件中,我会收到错误:

Error loading RS jni library: java.lang.UnsatisfiedLinkError: Couldn't load RSSupport from loader dalvik.system.PathClassLoader[]: findLibrary returned null

当我将renderscript值放在我自己的Graddle文件中时,会出现一个dex文件异常:

意外的顶级例外:

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

显然会发生dexfile异常,因为它们都添加了RenderScriptSupportEnabled true和RenderScriptTargetApi。但我不知道我需要做些什么来让他们都工作。每当我删除我自己的graddle中的renderscript时,我的项目都无法正常工作,但是当我在StackBlur模块中删除它时,那个将不起作用。

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

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')
}

1 个答案:

答案 0 :(得分:2)

在第26次尝试之后,我发现这些线条给了我这些问题:

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

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