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