我是GCM的新手并且是第一次尝试它。 我按照谷歌指导我们的文档。 我尝试使用如下设置的gradle文件构建和运行项目:
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'com.google.gms:google-services:2.0.0-beta2'
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.google.android.gms:play-services:8.4.0'
}
但是我得到了下一个错误:
错误:任务':app:processDebugGoogleServices'执行失败。 请通过更新google-services插件的版本(https://bintray.com/android/android-tools/com.google.gms.google-services/上提供有关最新版本的信息)或将com.google.android.gms的版本更新为8.3.0来修复版本冲突。&# 34;
当我尝试将其更改为8.3.0或8.3+时,我收到此错误:
错误:任务':app:processDebugResources'执行失败。 com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:Process' command' /Users/sarigbrand/Library/Android/sdk/build-tools/23.0.0 / AAPT''完成非零退出值1
错误:(18)标记属性名称包含无效字符'>' 错误:(14)标记属性名称包含无效字符'>'。"
此问题使我的debug.manifest全部变红并且充满错误,我的项目根本没有同步
我试过的其他事情:
我尝试下载gradle 2.10或从包装文件中运行它(在重新安装之前我被要求这样做):
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sarigbrand.pushnotification"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="23" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<permission
android:name="com.example.sarigbrand.pushnotification>.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.sarigbrand.pushnotification>.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" /> <!-- Permissions required for GCM -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.sarigbrand.pushnotification.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>
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.example.gcm" />
</intent-filter>
</receiver>
<service
android:name="com.example.sarigbrand.pushnotification.MyGcmListenerService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<service
android:name="com.example.sarigbrand.pushnotification.MyInstanceIDListenerService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID" />
</intent-filter>
</service>
<!-- Include the AdActivity and InAppPurchaseActivity configChanges and themes. -->
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
<activity
android:name="com.google.android.gms.ads.purchase.InAppPurchaseActivity"
android:theme="@style/Theme.IAPTheme" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name="com.google.android.gms.appinvite.PreviewActivity"
android:exported="true"
android:theme="@style/Theme.AppInvite.Preview" >
<intent-filter>
<action android:name="com.google.android.gms.appinvite.ACTION_PREVIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.google.android.gms.auth.api.signin.internal.SignInHubActivity"
android:excludeFromRecents="true"
android:exported="false"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<service
android:name="com.google.android.gms.auth.api.signin.RevocationBoundService"
android:exported="true"
android:permission="com.google.android.gms.auth.api.signin.permission.REVOCATION_NOTIFICATION" />
<provider
android:name="com.google.android.gms.measurement.AppMeasurementContentProvider"
android:authorities="com.example.sarigbrand.pushnotification.google_measurement_service"
android:exported="false" />
<receiver
android:name="com.google.android.gms.measurement.AppMeasurementReceiver"
android:enabled="true" >
<intent-filter>
<action android:name="com.google.android.gms.measurement.UPLOAD" />
</intent-filter>
</receiver>
<service
android:name="com.google.android.gms.measurement.AppMeasurementService"
android:enabled="true"
android:exported="false" />
</application>
答案 0 :(得分:2)
从项目级build.gradle
:
classpath 'com.google.gms:google-services:2.0.0-beta2'
使用此功能在app build.gradle
:
compile 'com.google.android.gms:play-services-gcm:8.4.0'
这对我有用