将字节码转换为dex时出错:多个dex文件,Android Studio 3.0

将字节码转换为dex时出错:多个dex文件,Android Studio 3.0,android,android-studio,android-studio-3.0,dex,android-multidex,Android,Android Studio,Android Studio 3.0,Dex,Android Multidex,我最近升级到Android Studio 3.0,运行该程序时出现以下错误: Error:Error converting bytecode to dex: Cause: com.android.dex.DexException: Multiple dex files define Lcom/vuforia/TransformModel; Error:com.android.dex.DexException: Multiple dex files define Lcom/vuforia/Tran

我最近升级到Android Studio 3.0,运行该程序时出现以下错误:

Error:Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Lcom/vuforia/TransformModel;
Error:com.android.dex.DexException: Multiple dex files define Lcom/vuforia/TransformModel;
Error:  at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:661)
Error:  at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:616)
Error:  at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:598)
Error:  at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
Error:  at com.android.dx.merge.DexMerger.merge(DexMerger.java:198)
Error:  at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:61)
Error:  at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:36)
Error:  at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1424)
Error:  at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
Error:  at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
Error:  at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
Error:  at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Error:Execution failed for task ':app:transformDexArchiveWithDexMergerForDebug'.
> com.android.build.api.transform.TransformException: com.android.dex.DexException: Multiple dex files define Lcom/vuforia/TransformModel;
除了我的主
应用程序
模块外,我的项目中还有两个其他模块。我已经试过了

  • ,
  • ,
  • ,
  • 正在删除
    .gradle
    文件夹,但它们都不起作用
有人能帮我吗

应用程序
模块:

apply plugin: 'com.android.application'
android {
    compileSdkVersion 25
    buildToolsVersion '26.0.2'
    defaultConfig {
        applicationId "com.example.shais.gpsdetector"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        resValue "string", "google_maps_key", (project.findProperty("GOOGLE_MAPS_API_KEY") ?: "")
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dexOptions {
        javaMaxHeapSize "4g"
        preDexLibraries = false
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.google.android.gms:play-services-location:10.2.4'
    compile 'com.google.android.gms:play-services-places:10.2.4'
    compile 'com.google.android.gms:play-services-maps:10.2.4'
    compile 'com.google.maps.android:android-maps-utils:0.5+'
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:cardview-v7:25.3.1'
    compile 'com.android.support:recyclerview-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
    implementation 'com.cocoahero.android:geojson:1.0.1'
    compile 'com.android.volley:volley:1.0.0'
    compile 'com.google.code.gson:gson:2.8.1'
    compile 'com.android.support:design:25.3.1'
    implementation project(':vuforia')
    implementation project(':rajawali')
}
apply plugin: 'com.android.library'

android {
    compileSdkVersion 25
    buildToolsVersion '26.0.2'

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dexOptions {
        preDexLibraries = false
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    testCompile 'junit:junit:4.12'
    compile files('libs/Vuforia.jar')
}
apply plugin: 'com.android.library'
apply plugin: 'jacoco'
apply plugin: 'signing'

android {
    compileSdkVersion 25
    buildToolsVersion '26.0.2'

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        debug {
            testCoverageEnabled true
            minifyEnabled false
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }   
    lintOptions {
        abortOnError false
    }
}

dependencies {   
    androidTestCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'org.jetbrains:annotations-java5:15.0'
}
Vuforia
模块:

apply plugin: 'com.android.application'
android {
    compileSdkVersion 25
    buildToolsVersion '26.0.2'
    defaultConfig {
        applicationId "com.example.shais.gpsdetector"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        resValue "string", "google_maps_key", (project.findProperty("GOOGLE_MAPS_API_KEY") ?: "")
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dexOptions {
        javaMaxHeapSize "4g"
        preDexLibraries = false
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.google.android.gms:play-services-location:10.2.4'
    compile 'com.google.android.gms:play-services-places:10.2.4'
    compile 'com.google.android.gms:play-services-maps:10.2.4'
    compile 'com.google.maps.android:android-maps-utils:0.5+'
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:cardview-v7:25.3.1'
    compile 'com.android.support:recyclerview-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
    implementation 'com.cocoahero.android:geojson:1.0.1'
    compile 'com.android.volley:volley:1.0.0'
    compile 'com.google.code.gson:gson:2.8.1'
    compile 'com.android.support:design:25.3.1'
    implementation project(':vuforia')
    implementation project(':rajawali')
}
apply plugin: 'com.android.library'

android {
    compileSdkVersion 25
    buildToolsVersion '26.0.2'

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dexOptions {
        preDexLibraries = false
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    testCompile 'junit:junit:4.12'
    compile files('libs/Vuforia.jar')
}
apply plugin: 'com.android.library'
apply plugin: 'jacoco'
apply plugin: 'signing'

android {
    compileSdkVersion 25
    buildToolsVersion '26.0.2'

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        debug {
            testCoverageEnabled true
            minifyEnabled false
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }   
    lintOptions {
        abortOnError false
    }
}

dependencies {   
    androidTestCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'org.jetbrains:annotations-java5:15.0'
}
rajawali
模块:

apply plugin: 'com.android.application'
android {
    compileSdkVersion 25
    buildToolsVersion '26.0.2'
    defaultConfig {
        applicationId "com.example.shais.gpsdetector"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        resValue "string", "google_maps_key", (project.findProperty("GOOGLE_MAPS_API_KEY") ?: "")
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dexOptions {
        javaMaxHeapSize "4g"
        preDexLibraries = false
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.google.android.gms:play-services-location:10.2.4'
    compile 'com.google.android.gms:play-services-places:10.2.4'
    compile 'com.google.android.gms:play-services-maps:10.2.4'
    compile 'com.google.maps.android:android-maps-utils:0.5+'
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:cardview-v7:25.3.1'
    compile 'com.android.support:recyclerview-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
    implementation 'com.cocoahero.android:geojson:1.0.1'
    compile 'com.android.volley:volley:1.0.0'
    compile 'com.google.code.gson:gson:2.8.1'
    compile 'com.android.support:design:25.3.1'
    implementation project(':vuforia')
    implementation project(':rajawali')
}
apply plugin: 'com.android.library'

android {
    compileSdkVersion 25
    buildToolsVersion '26.0.2'

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dexOptions {
        preDexLibraries = false
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    testCompile 'junit:junit:4.12'
    compile files('libs/Vuforia.jar')
}
apply plugin: 'com.android.library'
apply plugin: 'jacoco'
apply plugin: 'signing'

android {
    compileSdkVersion 25
    buildToolsVersion '26.0.2'

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        debug {
            testCoverageEnabled true
            minifyEnabled false
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }   
    lintOptions {
        abortOnError false
    }
}

dependencies {   
    androidTestCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'org.jetbrains:annotations-java5:15.0'
}

首先,尝试删除项目中的
.gradle
文件夹。然后,您需要在Linux中使用以下命令检查依赖关系树中的依赖关系:

./gradlew app:dependencies
或者,如果您正在使用Windows,请尝试以下操作:

gradlew.bat app:dependencies
如果在列表中发现重复的依赖项,可以使用以下方法将其排除:

compile('com.library.name:version') {
  exclude group: 'com.example', module: 'library'
}

首先,尝试删除项目中的
.gradle
文件夹。然后,您需要在Linux中使用以下命令检查依赖关系树中的依赖关系:

./gradlew app:dependencies
或者,如果您正在使用Windows,请尝试以下操作:

gradlew.bat app:dependencies
如果在列表中发现重复的依赖项,可以使用以下方法将其排除:

compile('com.library.name:version') {
  exclude group: 'com.example', module: 'library'
}

最后,我终于解决了这个问题。该错误是由于
Vuforia
gradle中的
Vuforia
jar的两条路径引起的。
Vuforia
Gradle中的以下两行实际上指向同一个库jar

compile fileTree(include: ['*.jar'], dir: 'libs')
compile files('libs/Vuforia.jar')

我只是删除了第二次编译的
jar
,它删除了我的错误。

最后,我解决了这个问题。该错误是由于
Vuforia
gradle中的
Vuforia
jar的两条路径引起的。
Vuforia
Gradle中的以下两行实际上指向同一个库jar

compile fileTree(include: ['*.jar'], dir: 'libs')
compile files('libs/Vuforia.jar')

我只是删除了第二次编译的
jar
,它删除了我的错误。

显示您的
build.gradle
。相同的模块导致问题!这可能会有帮助:@IntelliJAmiya完成。你能看一下吗section@IntelliJAmiya我也试过了。从错误日志中,我猜它在vuforia模块的某处。显示您的
build.gradle
。相同的模块导致问题!这可能会有帮助:@IntelliJAmiya完成。你能看一下吗section@IntelliJAmiya我也试过了。从错误日志中,我猜它在vuforia模块的某个地方。你救了我的命,这就是我一直在寻找的答案!你救了我的命,这就是我一直在寻找的答案!