我正在尝试将FCM(Firebase Cloud Messaging)集成到应用中,并遵循google's guide。我已将google-services.json
添加到app
文件夹,并试图添加SDK。将Firebase SDK添加到应用时出错
继指导,我在build.gradle (Project)
写道:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.2'
classpath 'com.google.gms:google-services:3.0.0'
}
}
而且在build.gradle(Module: mobile)
:
dependencies
{
compile 'com.android.support:support-v4:21.0.3'
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:cardview-v7:21.0.3'
compile 'com.android.support:recyclerview-v7:21.0.3'
compile 'com.google.android.gms:play-services:7.3.0'
(...)
compile 'com.google.firebase:firebase-core:9.6.1'
compile fileTree(dir: 'libs', include: ['*.jar'])
}
apply plugin: 'com.google.gms.google-services'
这是问题的开始时间。一年级同步后,会出现一个错误消息说:Error:(34, 0) Version: 7.3.0 is lower than the minimum version (9.0.0) required for google-services plugin.
我试图通过改变compile 'com.google.android.gms:play-services:7.3.0'
到compile 'com.google.android.gms:play-services:9.0.0'
又一次新的错误,那我不知道如何解决错误更新...:
Error:orientation|screenSize|screenLayout|uiMode|smallestScreenSize) from AndroidManifest.xml:79:4-113
Error:orientation|screenLayout|uiMode|screenSize|smallestScreenSize).
Error:Execution failed for task ':mobile:processDebugManifest'.
> Manifest merger failed : Attribute activity#[email protected] value=(keyboard|keyboardHidden|orientation|screenSize|screenLayout|uiMode|smallestScreenSize) from AndroidManifest.xml:79:4-113
is also present at [com.google.android.gms:play-services-ads-lite:9.0.0] AndroidManifest.xml:28:13-122 value=(keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize).
Suggestion: add 'tools:replace="android:configChanges"' to <activity> element at AndroidManifest.xml:77:3-79:116 to override.
对不起。 Android新手在这里。感谢所有未来的帮助!
编辑: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.www.appname"
android:installLocation="auto">
<!-- versionCode, versionName, minSdkVersion, targetSdkVersion properties are set via Gradle script -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> <!-- allows the API to access Google web-based services -->
<uses-feature android:glEsVersion="0x00020000" android:required="false" />
<application
android:name=".Application"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:hardwareAccelerated="true"
android:allowBackup="true"
tools:replace="android:icon, android:configChanges">
<activity
android:name="com.www.appname.activity.MainActivity"
android:label="@string/app_name"
android:launchMode="standard">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.www.appname.activity.DetailActivity"
android:label="@string/title_detail"
android:launchMode="standard" />
<activity
android:name="com.www.appname.activity.MapActivity"
android:label="@string/title_map"
android:launchMode="standard" />
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|screenLayout|uiMode|smallestScreenSize" />
<provider
android:name="com.www.appname.content.SearchRecentSuggestionsProvider"
android:authorities="ccom.www.appname.content.SearchRecentSuggestionsProvider"
android:exported="false" />
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
<meta-data android:name="com.google.android.gms.analytics.globalConfigResource" android:resource="@xml/analytics_global_tracker" />
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="@string/maps_api_key" />
</application>
</manifest>
感谢您的回答。我不知道如果我把工具:更换=“机器人:在正确的地方configChanges我把它添加到: \t'<应用 \t \t机器人:名字=” CityGuideApplication” \t \t机器人:图标= “@纹理贴图/ ic_launcher” \t \t机器人:标签= “@字符串/ APP_NAME” \t \t机器人:主题= “@风格/ Theme.CityGuide.Blue” \t \t安卓硬件加速= “真” \t \t android:allowBackup =“true” \t \t tools:replace =“android:icon” \t \t tools:replace =“android:configChanges”>' – Harkadya
@Harkadya,好像没问题。如果可以的话,请在问题中发布完整的清单文件以确保。 – Vyacheslav
但出现新错误: '错误:属性“替换”绑定到名称空间“http://schemas.android.com/tools”已经为元素“应用程序”指定。 '错误:配置项目'mobile'时发生问题。 >解析提供的清单文件时出现异常' – Harkadya