【问题标题】:getting gradle error for my project Multiple dex files define Lcom/google/android/gms/common/api/zze为我的项目获取 gradle 错误多个 dex 文件定义 Lcom/google/android/gms/common/api/zze
【发布时间】:2017-07-17 12:09:27
【问题描述】:

当我尝试构建我的项目时,我的项目出现错误多个 dex 文件定义 Lcom/google/android/gms/common/api/zzeonly。下面是我的 gradle 文件。

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.3"

    defaultConfig {
        applicationId "my app id"
        minSdkVersion 15
        targetSdkVersion 25
        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'])
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.google.firebase:firebase-messaging:10.0.1'
    compile 'com.android.support:recyclerview-v7:25.3.1'
    compile 'com.jakewharton:butterknife:8.6.0'
    compile 'com.google.code.gson:gson:2.8.0'
    compile 'com.android.volley:volley:1.0.0'
    compile 'io.nlopez.smartlocation:library:3.2.9'
    compile 'com.android.support:design:25.3.1'
    testCompile 'junit:junit:4.12'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0'
}

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

【问题讨论】:

  • 在 gradle 中添加 multidex 后,我现在收到此错误。错误:任务“:app:transformClassesWithJarMergingForDebug”执行失败。 > com.android.build.api.transform.TransformException:java.util.zip.ZipException:重复条目:com/google/android/gms/common/api/zze.class 当我尝试通过设置即时安装应用程序时运行我能够生成apk并成功安装在设备上。

标签: android android-studio gradle build build.gradle


【解决方案1】:

注意:如果您的项目配置为使用 minSdkVersion 20 或更低版本的 multidex,并且您部署到运行 Android 4.4(API 级别 20)或更低版本的目标设备,Android Studio 会禁用 Instant Run。

所以,启用 multidex 如下:

android {    
defaultConfig {
    // Enabling multidex support.
    multiDexEnabled true
}  
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}

像这样创建一个类

public class Multi_Dex extends Application {
@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
}
}

现在在你的清单文件中添加这个

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

解决这个问题,就像在这个链接上描述的那样:developer.android.com/studio/build/multidex

【讨论】:

    【解决方案2】:

    试试这个

    defaultConfig {
        applicationId "my app id"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner .support.test.runner.AndroidJUnitRunner"
      multiDexEnabled true
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-15
      • 1970-01-01
      • 1970-01-01
      • 2018-07-01
      • 2017-08-14
      • 1970-01-01
      • 2018-03-18
      相关资源
      最近更新 更多