我尝试在google's guide之后在应用中集成FCM(Firebase云消息传递)。我已将google-services.json
添加到app
文件夹,并尝试添加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#com.google.android.gms.ads.AdActivity@configChanges 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>
答案 0 :(得分:0)
使用
编译com.google.android.gms:播放服务:9.6.1&#39; 编译com.google.firebase:firebase-core:9.6.1&#39;
同步gradle文件,清理并重建项目。
并将'tools:replace="android:configChanges"'
添加到AndroidManifest.xml
修改强>
删除:
tools:replace="android:icon" tools:replace="android:configChanges"
添加:
tools:replace="android:icon, android:configChanges"
答案 1 :(得分:0)
compile 'com.google.android.gms:play-services:7.3.0'
该图书馆在一个图书馆中包含了每个Google的Android库。
您永远不应该使用该库,而应该只使用您实际需要的特定库,例如:
compile 'com.google.android.gms:play-services-NAME_OF_THE_LIBRARY'
com.google.android.gms
和com.google.firebase
如果对这些库使用不同的版本,则在编译和运行时都会有很多冲突。
答案 2 :(得分:-1)
尝试添加firebase消息传递依赖
compile com.google.firebase:firebase-messaging:9.6.1