2017-07-17 16 views
0

我收到我的項目錯誤多個dex文件定義Lcom/google/android/gms/common/api/zzeonly當我試圖建立我的項目。以下是我的gradle文件。我的項目獲取gradle錯誤多個dex文件定義Lcom/google/android/gms/common/api/zze

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' 
+0

我在gradle中添加multidex後出現這個錯誤。 錯誤:任務':app:transformClassesWithJarMergingForDebug'的執行失敗。 > com.android.build.api.transform.TransformException:java.util.zip.ZipException:重複條目:com/google/android/gms/common/api/zze.class 當我嘗試安裝應用程序通過設置即時運行我能夠生成apk併成功安裝在設備上。 – AndroidDev

回答

0

試試這個

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

注意:如果您的項目配置爲multidex用的minSdkVersion 20或更低,並部署到目標上運行的是Android 4.4(API級別20)以下,Android設備Studio禁用即時運行。

因此,使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); 
} 
} 

現在在manifiest文件中添加此

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

解決這個問題s,就像在這個鏈接上描述的一樣:developer.android.com/studio/build/multidex

相關問題