构建我的Android项目时无法合并dex错误

时间:2019-01-04 00:42:51

标签: android gradle dex

我正在尝试构建我的android项目并收到错误“无法合并dex”

我尝试了其他帖子中提到的其他选项。其中一些是

  • 删除未使用的库
  • 在gradle文件中添加multidexenabled = true
  • 将实现'com.android.support:multidex:1.0.3'添加到gradle文件中
  • 清理,删除.gradle文件夹并重建

问题仍然存在,不确定什么地方出了问题。请分享您的想法。

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

我的app / build.gradle文件

            apply plugin: 'com.android.application'

            android {
                compileSdkVersion 27

                defaultConfig {
                    applicationId "app.resta.com.restaurantapp"
                    minSdkVersion 23
                    targetSdkVersion 27
                    versionCode 1
                    versionName "1.0"
                    multiDexEnabled true
                }
                buildTypes {
                    release {
                        minifyEnabled false
                        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
                    }
                }
                compileOptions {
                    targetCompatibility 1.7
                    sourceCompatibility 1.7
                }
            }
            repositories {
                maven { url "https://jitpack.io" }
            }
            dependencies {
                compile fileTree(dir: 'libs', include: ['*.jar'])
                testCompile 'junit:junit:4.12'
                implementation 'com.android.support:appcompat-v7:27.0.2'
                implementation 'com.android.support:design:27.0.2'
                implementation 'com.android.support:recyclerview-v7:27.0.2'

                compile 'com.github.PhilJay:MPAndroidChart:v3.0.2'
                implementation 'com.google.firebase:firebase-core:16.0.6'
                implementation 'com.google.firebase:firebase-firestore:17.1.5'
                implementation 'com.google.firebase:firebase-storage:16.0.5'
                implementation 'com.firebaseui:firebase-ui-storage:4.1.0'
                annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
                implementation 'com.android.support:multidex:1.0.3'
            }

            apply plugin: 'com.google.gms.google-services'

1 个答案:

答案 0 :(得分:0)

使用支持库#bg构建:

-target 1.8
-dontshrink
-dontoptimize
-dontnote
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,*Annotation*,EnclosingMethod
-keep class !com.hbyuan27.demo.service.DemoService { *; }
#-keep class !com.hbyuan27.demo.**.service.** { *; }

如果没有,则添加整个27.1.1,不仅要添加该通知,否则不能说明任何事情。