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

时间:2016-12-07 05:14:40

标签: android gradle crosswalk

我使用人行横道浏览器制作Android混合应用程序。 我添加了firebase消息文件,但它在某些Android设备中不起作用。 这是我的错误文本。

  

错误:任务':app:transformClassesWithDexForArmv7Debug'执行失败。    com.android.build.api.transform.TransformException:com.android.ide.common.process.ProcessException:java.util.concurrent.ExecutionException:com.android.dex.DexException:多个dex文件定义Lcom / google / android /克/普通/ 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
}

如何重新构建此应用程序? 请帮帮我

1 个答案:

答案 0 :(得分:0)

因为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'
}

并在您的启动器活动或从Application初始化它的活动

public class YouApplication extends Application {

@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
}

}