我正在添加 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/