我正在使用人行横道浏览器制作android混合应用程序。
我添加了Firebase消息文件,但在某些android设备中不起作用。
这是我的错误文字。
Error:Execution failed for task ':app:transformClassesWithDexForArmv7Debug'. com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/common/api/zza;
这是我的应用程序构建文件
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 25
buildToolsVersion "25.0.1"
defaultConfig {
applicationId "com.example"
minSdkVersion 18
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'
}
}
/*crossWalk*/
productFlavors {
armv7 {
ndk {
abiFilters "armeabi-v7a", ""
}
}
x86 {
ndk {
abiFilters "x86", ""
}
}
}
}
repositories {
/*crossWalk*/
maven {
url 'https://download.01.org/crosswalk/releases/crosswalk/android/maven2'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.0.1'
compile 'org.xwalk:xwalk_core_library:10.39.235.15'
compile 'junit:junit:4.12'
compile ('com.google.firebase:firebase-messaging:9.6.1'){
exclude group: 'com.google.android.gms'
}
compile 'com.squareup.okhttp3:okhttp:3.2.0'
}
这是我的项目构建文件
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'com.google.gms:google-services:3.0.0'
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
如何重新构建此应用程序?
请帮我
最佳答案
因为Google Play服务包很大,所以应该使用multidex,因此请使用这样的multidex依赖项
android {
compileSdkVersion 25
buildToolsVersion "25.0.1"
defaultConfig {
minSdkVersion 14 //lower than 14 doesn't support multidex
targetSdkVersion 25
// Enabling multidex support.
multiDexEnabled true
}
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
并在启动器 Activity 或从Application扩展的 Activity 中对其进行初始化
public class YouApplication extends Application {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
关于android - 添加google-services后出现多个dex错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41009891/