[英]Android - Set up Google Play Services and Firebase - Gradle build error
我的项目中遇到了包括Google服务在内的问题。
错误
按照这些说明进行操作,并同时参考文档进行设置,我遇到了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。
更改此:
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服务Gradle插件已更新为
3.0.0
(第一个版本)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.