如何修复Android Studio错误

时间:2017-01-17 07:41:59

标签: android android-studio build.gradle

请帮我解决此错误 错误

Error:Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;

Error:Execution failed for task ':SchedulerApp:transformClassesWithDexForRelease'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: java.lang.UnsupportedOperationException

我的build.gradle

apply plugin: 'com.android.application'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':android-support-v7-appcompat')
    compile 'com.google.firebase:firebase-ads:10.0.1'

}

android {
    compileSdkVersion 22
    buildToolsVersion "25.0.2"

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


apply plugin: 'com.google.gms.google-services'

3 个答案:

答案 0 :(得分:1)

  1. 尝试clean,然后Make Project

  2. 在DefaultConfig中添加multiDexEnabled = true

  3. 希望它有所帮助!

答案 1 :(得分:1)

尝试改变,

compile project(':android-support-v7-appcompat')

 compile 'com.android.support:appcompat-v7:25.1.0'

答案 2 :(得分:0)

这不是多指数问题。

您正在添加相同的类(Landroid / support / v4 / accessibilityservice / AccessibilityServiceInfoCompat $ AccessibilityServiceInfoVersionImpl)两次
这个类在你的项目$postNav和firebase的依赖项中。

你为什么要用这个?

android-support-v7-appcompat

我建议你改用

compile project(':android-support-v7-appcompat')