添加com.google.android.gms:play-services后,Android应用无法编译

时间:2017-01-31 20:47:03

标签: android

在添加" com.google.android.gms后,应用无法编译:play-services:9.6.1"库。

build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'android-apt'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "br.com.vaptvuptapp"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    apt 'com.jakewharton:butterknife-compiler:8.2.1'
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.android.support:support-v4:23.0.1'
    compile 'com.android.support:design:23.0.1'
    compile 'com.android.support:recyclerview-v7:23.0.1'
    compile 'com.android.support:cardview-v7:23.1.1'
    compile 'com.fasterxml.jackson.core:jackson-core:2.7.4'
    compile 'com.fasterxml.jackson.core:jackson-annotations:2.7.4'
    compile 'com.fasterxml.jackson.core:jackson-databind:2.7.4'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.squareup.okhttp3:okhttp:3.2.0'
    compile 'com.facebook.android:facebook-android-sdk:4.0.0'
    compile 'com.squareup.retrofit2:retrofit:2.0.2'
    compile 'com.squareup.retrofit2:converter-jackson:2.0.2'
    compile 'com.squareup.okhttp3:logging-interceptor:3.2.0'
    compile 'com.jakewharton:butterknife:8.2.0'
    compile 'com.mobsandgeeks:android-saripaar:2.0.3'
    compile 'com.google.android.gms:play-services:9.6.1'

    compile 'com.google.firebase:firebase-auth:9.6.1'
    compile 'com.google.firebase:firebase-core:9.6.1'
    compile 'com.google.firebase:firebase-database:9.6.1'
    compile 'com.google.firebase:firebase-crash:9.6.1'
    compile 'com.google.firebase:firebase-messaging:9.6.1'
    compile 'com.firebaseui:firebase-ui:0.2.0'
    compile 'com.facebook.android:facebook-android-sdk:[4,5)'
    compile 'com.github.alorma:github-sdk:3.2.5'
    compile 'org.greenrobot:eventbus:3.0.0'
    compile 'com.google.firebase:firebase-config:9.6.1'
    compile 'com.google.firebase:firebase-messaging:9.6.1'

}

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'me.tatarka:gradle-retrolambda:3.2.5'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
    }
}

repositories {
    mavenCentral()
    jcenter()
}

apply plugin: 'com.android.application' //or apply plugin: 'java'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'com.google.gms.google-services'

堆栈是:

E/UncaughtException: java.lang.RuntimeException: Unable to start activity ComponentInfo{br.com.vaptvuptapp/br.com.vaptvuptapp.MainActivity}: android.view.InflateException: Binary XML file line #16: Error inflating class android.support.design.widget.NavigationView
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2326)
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
     at android.app.ActivityThread.access$800(ActivityThread.java:147)
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281)
     at android.os.Handler.dispatchMessage(Handler.java:102)
     at android.os.Looper.loop(Looper.java:135)
     at android.app.ActivityThread.main(ActivityThread.java:5264)
     at java.lang.reflect.Method.invoke(Native Method)
     at java.lang.reflect.Method.invoke(Method.java:372)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:900)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:695)
  Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class android.support.design.widget.NavigationView
     at android.view.LayoutInflater.createView(LayoutInflater.java:633)
     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
     at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
     at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
     at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
     at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
     at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
     at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143)
     at br.com.vaptvuptapp.MainActivity.onCreate(MainActivity.java:96)
     at android.app.Activity.performCreate(Activity.java:5975)
     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
     at android.app.ActivityThread.access$800(ActivityThread.java:147) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281) 
     at android.os.Handler.dispatchMessage(Handler.java:102) 
     at android.os.Looper.loop(Looper.java:135) 
     at android.app.ActivityThread.main(ActivityThread.java:5264) 
     at java.lang.reflect.Method.invoke(Native Method) 
     at java.lang.reflect.Method.invoke(Method.java:372) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:900) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:695) 
  Caused by: java.lang.reflect.InvocationTargetException
     at java.lang.reflect.Constructor.newInstance(Native Method)
     at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
     at android.view.LayoutInflater.createView(LayoutInflater.java:607)
     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743) 
     at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) 
     at android.view.LayoutInflater.inflate(LayoutInflater.java:504) 
     at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
     at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
     at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) 
     at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143) 
     at br.com.vaptvuptapp.MainActivity.onCreate(MainActivity.java:96) 
     at android.app.Activity.performCreate(Activity.java:5975) 
     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105) 
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269) 
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
     at android.app.ActivityThread.access$800(ActivityThread.java:147) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281) 
     at android.os.Handler.dispatchMessage(Handler.java:102) 
     at android.os.Looper.loop(Looper.java:135) 
     at android.app.ActivityThread.main(ActivityThread.java:5264) 
     at java.lang.reflect.Method.invoke(Native Method) 
     at java.lang.reflect.Method.invoke(Method.java:372) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:900) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:695) 
  Caused by: java.lang.NoClassDefFoundError: android.support.design.internal.NavigationMenuPresenter
     at android.support.design.widget.NavigationView.<init>(NavigationView.java:80)
     at android.support.design.widget.NavigationView.<init>(NavigationView.java:92)
     at java.lang.reflect.Constructor.newInstance(Native Method) 
     at java.lang.reflect.Constructor.newInstance(Constructor.java:288) 
     at android.view.LayoutInflater.createView(LayoutInflater.java:607) 
     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743) 
     at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) 
     at android.view.LayoutInflater.inflate(LayoutInflater.java:504) 
     at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
     at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
     at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) 
     at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143) 
     at br.com.vaptvuptapp.MainActivity.onCreate(MainActivity.java:96) 
     at android.app.Activity.performCreate(Activity.java:5975) 
     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105) 
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269) 
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
     at android.app.ActivityThread.access$800(ActivityThread.java:147) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281) 
     at android.os.Handler.dispatchMessage(Handler.java:102) 
     at android.os.Looper.loop(Looper.java:135) 
     at android.app.ActivityThread.main(ActivityThread.java:5264) 
     at java.lang.reflect.Method.invoke(Native Method) 
     at java.lang.reflect.Method.invoke(Method.java:372) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:900) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:695) 

我已经尝试过修改保护文件,但没有成功.. 任何人都可以帮助我吗?

编辑:相关帖子的接受答案完全是nosense。

2 个答案:

答案 0 :(得分:0)

试试这个

compile (com.google.android.gms:play-services:9.6.1){
    exclude group: 'com.android.support', module: 'design'
    exclude group: 'com.android.support', module: 'support-v4'
    exclude group: 'com.android.support', module: 'appcompat-v7'
}

我猜使用播放服务和您的代码可能存在版本冲突。 并且不要使用整个com.google.android.gms:play-services

答案 1 :(得分:0)

好吧,花了几个小时后,我做到了!

所以我的最终gradle文件:

apply plugin: 'com.android.application'
apply plugin: 'android-apt'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "br.com.vaptvuptapp"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    apt 'com.jakewharton:butterknife-compiler:8.2.1'
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.android.support:support-v4:23.0.1'
    compile 'com.android.support:design:23.0.1'
    compile 'com.android.support:recyclerview-v7:23.0.1'
    compile 'com.android.support:cardview-v7:23.1.1'
    compile 'com.fasterxml.jackson.core:jackson-core:2.7.4'
    compile 'com.fasterxml.jackson.core:jackson-annotations:2.7.4'
    compile 'com.fasterxml.jackson.core:jackson-databind:2.7.4'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.squareup.okhttp3:okhttp:3.2.0'
    compile 'com.facebook.android:facebook-android-sdk:4.0.0'
    compile 'com.squareup.retrofit2:retrofit:2.0.2'
    compile 'com.squareup.retrofit2:converter-jackson:2.0.2'
    compile 'com.squareup.okhttp3:logging-interceptor:3.2.0'
    compile 'com.jakewharton:butterknife:8.2.0'
    compile 'com.mobsandgeeks:android-saripaar:2.0.3'
    compile 'com.google.android.gms:play-services-auth:9.6.1'

    compile 'com.google.firebase:firebase-auth:9.6.1'
    compile 'com.google.firebase:firebase-core:9.6.1'
    compile 'com.google.firebase:firebase-database:9.6.1'
    compile 'com.google.firebase:firebase-crash:9.6.1'
    compile 'com.google.firebase:firebase-messaging:9.6.1'
    compile 'com.firebaseui:firebase-ui:0.2.0'
    compile 'com.github.alorma:github-sdk:3.2.5'
    compile 'org.greenrobot:eventbus:3.0.0'
    compile 'com.google.firebase:firebase-config:9.6.1'
    compile 'com.google.firebase:firebase-messaging:9.6.1'

}

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'me.tatarka:gradle-retrolambda:3.2.5'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
    }
}

repositories {
    mavenCentral()
    jcenter()
}

apply plugin: 'com.android.application' //or apply plugin: 'java'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'com.google.gms.google-services'

而且,我按照这些链接的提示:

Error inflating class android.support.design.widget.NavigationView

NoClassDefFoundError: android.support.design.internal.NavigationMenu on Android 4.2.2 (wiko)

现在一切都运转良好..谢谢大家!