【问题标题】:Unable to merge dex when used library with Android studio 3.0.1?使用 Android studio 3.0.1 的库时无法合并 dex?
【发布时间】:2019-08-03 05:35:09
【问题描述】:

我正在添加 Admob(play-services-ads) 库并尝试运行我的代码,然后它显示了一些错误:

错误:任务 ':app:transformDexArchiveWithExternalLibsDexMergerForDebug' 执行失败。 java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: 无法合并 dex

我做了很多改变,但仍然面临这个问题。

我正在使用此代码:

defaultConfig {
        applicationId "com.applist.carstation"
        minSdkVersion 17
        targetSdkVersion 27
        versionCode 2
        versionName "1.1.0"
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }


 buildTypes {
        release {

            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    dexOptions {

        javaMaxHeapSize "4g"
    }

我也使用依赖是:

    implementation "com.android.support:support-v4:27.1.0"
    implementation 'com.android.support:appcompat-v7:27.1.0'
    implementation 'com.android.support:design:27.1.0'
    implementation 'com.android.support:support-vector-drawable:27.1.0'
    implementation 'com.android.support:mediarouter-v7:27.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:recyclerview-v7:27.1.0'
    implementation 'com.android.support:multidex:1.0.3'

    implementation 'com.google.android.gms:play-services-ads:17.1.3'
    implementation 'com.google.android.gms:play-services:11.4.0'

    implementation 'com.google.firebase:firebase-messaging:17.4.0'

我更新了版本代码 add multidex enable true 但我仍然收到此错误

我必须改变哪里?

错误:任务 ':app:transformDexArchiveWithExternalLibsDexMergerForDebug' 执行失败。 java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: 无法合并 dex

【问题讨论】:

    标签: java android admob


    【解决方案1】:

    创建应用程序类

    public class MyApplication extends MultiDexApplication {
    }
    

    并添加到清单文件中

    <application
            android:allowBackup="true"
            android:icon="@drawable/logo"
            android:label="@string/app_name"
            android:supportsRtl="true"
            android:name=".MyApplication"
            android:theme="@style/AppTheme">
    

    【讨论】:

    • 我创建的 myApplication 类使用 MultiDexApplicatoin 扩展但无法正常工作
    • 您有什么建议请回复
    • 尝试清理和文件->无效的缓存重启
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多