android - 添加google-services后出现多个dex错误

标签 android gradle crosswalk

我正在使用人行横道浏览器制作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/

相关文章:

android - 依赖项无法解析 : com. github.barteksc :android-pdf-viewer:2. 8.1

javascript - 如果 Crosswalk 更新其内部浏览器,我的应用程序会丢失 localStorage 数据吗?

android - 如何将现有资源/绘图/xml 文件转换为图标?

android - ACTION_IMAGE_CAPTURE 和 EXTRA_OUTPUT 创建已处理的 "Handling Media Storage Error"

android - 从通知启动 Activity 并返回到上一个 Activity

android - 嵌入式 Crosswalk 增加了 Android 上分配的内存

android - 在 Android 上的人行横道 WebView 中以编程方式设置 Cookie

android - 如何为 Calabash-android 使用自定义 keystore ?

androidTest编译某个库的androidTest文件夹下的文件

gradle - 添加项目依赖项时如何告诉Gradle从项目而不是源jar中获取源?