【问题标题】:Error:Error converting bytecode to dex: Multiple dex files define错误:将字节码转换为 dex 时出错:多个 dex 文件定义
【发布时间】:2017-11-11 07:53:35
【问题描述】:

我遇到了这个问题,你能帮帮我吗:

Error:Error converting bytecode to dex:

原因:com.android.dex.DexException:多个dex文件定义了Lcom/google/android/gms/auth/api/signin/internal/zzf; ...

FAILURE:构建失败并出现异常。

  • 出了什么问题: 任务 ':app:transformClassesWithDexForDebug' 执行失败。

    com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: 执行时出错带有参数的主类 com.android.dx.command.Main 的 java 进程 {--dex --num-threads=4 --output D:\Projectos\Chat_Final\app\build\intermediates\transforms\dex\debug\folders \1000\1f\main D:\Projectos\Chat_Final\app\build\intermediates\pre-dexed\debug\classes_9fd79174a0a6dc23209652a8a58b3e02e9146491.jar D:\Projectos\Chat_Final\app\build\intermediates\pre-dexed\debug\bolts-applinks -1.4.0_7536087ced7b51cacc52bdfc4ca05ab61d61e0c3.jar D:\Projectos\Chat_Final\app\build\intermediates\pre-dexed\debug\jackson-databind-2.2.2_c79be971c56bd1cdc38488184cf71a5146b761ff.jar D:\Projectos\ \debug\classes_3b9a81b892f55e63da37657bf33b2ce2fe9ca8b0.jar

我的 build.glade

    packagingOptions {
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
}

}

/* 包装选项 { 排除“元信息/许可证” //如果您使用的是firebase,请包含以下行 //排除'META-INF/LICENSE-FIREBASE.txt' 排除“元信息/通知” }*/

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])


    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 'com.android.support:recyclerview-v7:25.0.1'
    compile 'com.android.support:cardview-v7:25.0.1'
    compile 'com.android.support:design:25.0.1'
    //compile 'com.android.support:support-v4:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'


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

    compile 'com.firebase:firebase-client-android:2.4.0'
    compile 'com.google.firebase:firebase-core:10.2.6'
    compile 'com.google.firebase:firebase-auth:10.2.6'
    compile 'com.google.firebase:firebase-database:10.2.6'
    compile 'com.google.firebase:firebase-storage:10.2.6'
    compile 'com.google.firebase:firebase-messaging:10.2.6'
    compile 'com.firebaseui:firebase-ui-database:0.6.0'
    compile 'com.firebaseui:firebase-ui-storage:0.6.0'


    compile 'com.firebaseui:firebase-ui-auth:0.6.0'
    //compile 'com.android.support:multidex:1.0.0'

    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.github.bumptech.glide:glide:3.7.0'


    compile 'com.squareup.okhttp3:okhttp:3.6.0'

    //Notification

    compile 'com.onesignal:OneSignal:[3.5.3,4.0.0)'




    compile 'com.google.android.gms:play-services-gcm:10.2.6'

    compile 'com.google.android.gms:play-services-location:10.2.6'



}

应用插件:'com.google.gms.google-services'

【问题讨论】:

    标签: android firebase


    【解决方案1】:

    如果您的 minSdkVersion 设置为 21 或更高,您只需将 multiDexEnabled 设置为 true > 在您的应用级build.gradle 文件中,如下所示:

    android {
        defaultConfig {
            ...
            minSdkVersion 21 
            targetSdkVersion 25
            multiDexEnabled true
        }
        ...
    }
    

    但是,如果您的 minSdkVersion 设置为 20 或更低,那么您必须使用 multidex 支持库,如下所示:

    修改app级的build.gradle文件启用multidex,并将multidex库添加为依赖,如下图:

    android {
        defaultConfig {
            ...
            minSdkVersion 15 
            targetSdkVersion 25
            multiDexEnabled true
        }
        ...
    }
    
    dependencies {
      compile 'com.android.support:multidex:1.0.1'
    }
    

    像这样创建一个应用程序类:

    public class MyApplication extends MultiDexApplication {
      @Override
      protected void attachBaseContext(Context base) {
         super.attachBaseContext(base);
         MultiDex.install(this);
      }
    }
    

    在 Manifest 中添加这个应用程序类。

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="your package name">
        <application
            android:name=".MyApplication" >
            ...
        </application>
    </manifest>
    

    您也可以查看此链接:

    https://developer.android.com/studio/build/multidex.html

    【讨论】:

      猜你喜欢
      • 2018-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-18
      • 1970-01-01
      相关资源
      最近更新 更多