在为我的Android应用程序构建APK时,会显示以下错误:
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lcom/google/firebase/iid/zzb;
我无法找到错误。我的模块:app gradle文件是:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "27.0.0"
defaultConfig {
applicationId "//my application"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
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'
})
compile 'com.android.support:design:26.+'
compile 'com.android.support:support-v4:26.+'
compile 'com.google.android.gms:play-services-fitness:11.0.0'
compile 'com.google.firebase:firebase-messaging:9.0.1'
compile 'com.mcxiaoke.volley:library:1.0.19'
compile 'com.google.code.gson:gson:2.6.1'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.android.support:recyclerview-v7:26.+'
compile 'com.android.support:cardview-v7:26.+'
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
}
我在某处读过,除非你绝对需要在build.gradle中启用multiDex,否则不要这样做!
但是当我从gradle文件中删除该行时,
compile 'com.google.firebase:firebase-messaging:9.0.1'
然后建立apk成功。 由于我在我的应用程序中需要firebase,这对我来说不是一个解决方案。
任何人都可以帮助我吗?
答案 0 :(得分:1)
您需要使用version
dependencies
使用此
compile 'com.google.android.gms:play-services-fitness:11.0.0'
compile 'com.google.firebase:firebase-messaging:11.0.0'
而不是这个
compile 'com.google.android.gms:play-services-fitness:11.0.0'
compile 'com.google.firebase:firebase-messaging:9.0.1'
答案 1 :(得分:0)
构建gradle文件
apply plugin: 'com.android.application'
android {
signingConfigs {
}
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.imageditor.Image"
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
multiDexEnabled true
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/license.txt'
exclude 'META-INF/notice.txt'
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt')
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}