无法在 Android 的 API 级别 2.2 上使用 GCM

Unable to use GCM on API level 2.2 in Android

我想在 API 级别 2.2 上使用 GCM,但 Android Studio 给出错误

Error:Execution failed for task ':app:processDebugManifest'.

Manifest merger failed : uses-sdk:minSdkVersion 8 cannot be smaller than version 9 declared in library D:\New folder\AndroidStudioProjects\GCMExample\app\build\intermediates\exploded-aar\com.google.android.gms\play-services.3.0\AndroidManifest.xml Suggestion: use tools:overrideLibrary="com.google.android.gms.all" to force usage

我知道将我的 compiledSdkVersion 更改为 9 将解决错误,但我想在我的 App

上支持 API 级别 2.2

我读了这个GoogleLink

https://developers.google.com/cloud-messaging/android/client

它说:

GCM requires devices running Android 2.2 or higher that also have the Google Play Store application installed, or an emulator running Android 2.2 with Google APIs.

我的 build.gradle 文件:

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
    applicationId "com.example.hogo.gcmapp"
    minSdkVersion 8
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.google.android.gms:play-services-gcm:8.3.0'
}

那么,为什么我无法在 API 级别 2.2 上使用 GCM?

我做错了什么?

提前致谢...

这取决于您使用的 GCM-API。您引用的下面的 bullet point 说:

However, if you want to continue to use new GCM features that are distributed through Google Play Services, the device must be running Android 2.3 or higher, or you can use an emulator running Android 2.3 with Google APIs.

你编译 *.gms:play-services-gcm:8.3.0 显然是随播放服务一起分发的。因此,如果您真的想支持 2.2 设备,您需要旧的和已弃用的 GCM-APIs,但由于只有 0.2% of all Android devices 仍在使用该版本,您可以使用 SDK 10 并从 GCM 的所有功能中受益现在提供。

小伙伴们,问题终于解决了。

只需打开独立 SDK 管理器并选中底部的 已过时 复选框

您将在下面的图片中看到过时的 Froyo 库。

之后就跟着这个 post :

How to add Google Play Services for Froyo to the project using Gradle?

就是这样。

也看看这个post:

Is Google Play Services for Froyo compatible with Android 2.3 and higher?

希望对大家有所帮助:)