java - Android studio 3.0.1使用库时无法合并dex?

标签 java android admob

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

Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge 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'

我更新了版本代码添加 multidex 启用 true 但仍然收到此错误

哪里需要改变?

Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

最佳答案

创建应用程序类

public class MyApplication extends MultiDexApplication {
}

并添加到 list 文件中

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

关于java - Android studio 3.0.1使用库时无法合并dex?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57335730/

相关文章:

java - 如何在 Java Web 处理程序中获取本地文件大小?

java - 如何为 xml 创建 GUI?

android - 为android测试任务生成xml报告

android - 如何在 corona sdk 中创建和保存设置?

swift - 为什么我的插页式广告产生错误?

java - 如何将CSS类放入html :select element in jsp

c# - Java ZIP 文件从一个 zip 复制并粘贴到另一个 zip

android - 使用服务器文件创建媒体封面流画廊

android - onAdFailedtoLoad : 3 error only on Android version of Flutter app for AdMob

iOS:Google Analytics 和 AdMob 的 CocoaPods 问题