android - 为我的项目获取gradle错误多个dex文件定义了Lcom/google/android/gms/common/api/zze

标签 android android-studio gradle build build.gradle

我在我的项目中遇到错误,当我尝试构建项目时,多个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'

最佳答案

注意:如果为minSdkVersion 20或更低版本的Multidex配置了项目,并且将其部署到运行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);
}
}

现在在您的 list 文件中添加此
<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

关于android - 为我的项目获取gradle错误多个dex文件定义了Lcom/google/android/gms/common/api/zze,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45143941/

相关文章:

java - 线程同步Java

android - 如何更改 ndk-build 命令生成的 .so 文件目录?

autocomplete - 安卓工作室 : Enum auto-completion of switch case

java - React Native Expo eas build -p android java JDK 版本错误

Android::如何在 token 过期时自动重新验证用户(电子邮件+密码验证)

java - 使用 Android 触摸屏捕捉游戏(如《愤怒的小鸟》)的 Action 或击键

gradle - 嵌套的gradle构建

gradle - 忽略Gradle Pmd插件中的优先级3、4、5违规

android - 在 espresso 测试完成时让 Android 应用程序处于最终状态

android - 在Android Studio 2.3.3中添加字体