首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Android -设置Google Play服务和Firebase - Gradle构建错误

Android -设置Google Play服务和Firebase - Gradle构建错误
EN

Stack Overflow用户
提问于 2018-07-31 04:31:39
回答 1查看 701关注 0票数 0

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

The errors

按照these的说明,并参考docs进行设置,我遇到了apply plugins属性的问题:

由于我不知道的原因,它不能正确获取(关于版本错误),即使当你点击'Add FCM to your app‘(紫色)时,这个属性是自动填充的。如您所见,它在URL中没有任何版本号。我还遇到了implementation 'com.google.firebase:firebase-messaging:17.1.0'属性的问题。

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

AndroidManifest.xml

代码语言:javascript
复制
<?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 (项目)

代码语言:javascript
复制
// 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 (应用程序)

代码语言:javascript
复制
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

完整错误消息

请通过更新谷歌服务插件的版本(有关最新版本的信息可在获得)或将com.google.android.gms版本更新到15.0.1来修复版本冲突。

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-07-31 04:36:01

更改此设置:

代码语言:javascript
复制
classpath 'com.google.gms:google-services:3.1.1'

如下所示:

代码语言:javascript
复制
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服务Gradle插件已经更新到3.0.0(这是第一个版本)。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51601865

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档