【问题标题】:Android - Set up Google Play Services and Firebase - Gradle build errorAndroid - 设置 Google Play 服务和 Firebase - Gradle 构建错误
【发布时间】:2018-07-30 20:31:38
【问题描述】:

我在项目中遇到了包括 Google 服务在内的问题。

错误

按照these 的说明,也参考docs 进行设置,我遇到了apply plugins 属性的问题: 由于我不知道的原因,即使当您点击“将 FCM 添加到您的应用”(紫色)时该属性是自动填充,它也无法正确获取(版本错误)。如您所见,它的 URL 中没有任何版本号。 我也遇到了implementation 'com.google.firebase:firebase-messaging:17.1.0' 属性的问题。

我将添加清单和 gradle 文件以供参考:

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.nationscompanies.uordermobile">
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.VIBRATE"/>
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        android:fullBackupContent="@xml/backup_descriptor">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <service
            android:name=".MyAndroidFirebaseMessagingService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT"/>
            </intent-filter>
        </service>
        <service
            android:name=".MyAndroidFirebaseInstanceIdService">
            <intent-filter>
                <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
            </intent-filter>
        </service>
    </application>
</manifest>


build.gradle(项目)

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'
        classpath 'com.google.gms:google-services:3.1.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}


build.gradle(应用程序)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.nationscompanies.uordermobile"
        minSdkVersion 22
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    api 'com.google.android.gms:play-services-gcm:15.0.1'
    api 'com.google.firebase:firebase-core:16.0.1'
    api 'com.google.firebase:firebase-messaging:17.1.0'
}

apply plugin: 'com.google.gms.google-services' // this is the line that gets autofilled when you click on the 'Add FCM to your app' button from Firebase manager


完整的错误信息

请通过更新 google-services 插件的版本(有关最新版本的信息可在 https://bintray.com/android/android-tools/com.google.gms.google-services/ 获得)或将 com.google.android.gms 的版本更新到 15.0 来解决版本冲突。 1.

然后是一个巨大的错误列表:

【问题讨论】:

    标签: android firebase gradle google-play-services


    【解决方案1】:

    改变这个:

    classpath 'com.google.gms:google-services:3.1.1'
    

    进入这个:

    classpath 'com.google.gms:google-services:4.0.2'
    

    防止出现版本冲突错误。

    点击这里了解更多信息:

    https://android-developers.googleblog.com/2018/05/announcing-new-sdk-versioning.html

    从所有 Play 服务和 Firebase 库的版本 15 开始,每个匹配 com.google.android.gms:play-services-*com.google.firebase:firebase-* 的 Maven 依赖项不再需要具有相同的版本号才能在构建时和运行时正常工作。

    为了支持版本控制的这一变化,Play services Gradle 插件已更新为3.0.0(这是第一个版本)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-05
      • 2017-10-18
      • 1970-01-01
      • 2014-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多