我正在尝试将Google Cloud Messaging添加到Android Studio上的应用中,但我似乎无法与该库集成。我的build.gradle文件的代码如下所示,我根据这里的建议进行了修改:http://developer.android.com/google/play-services/setup.html#Setup
我应该提一下,我也在使用Google+登录,但没有遇到任何问题。
导入时,应用无法在com.google.android.gms
(具体为common.ConnectionResult
,common.GooglePlayServicesUtil
和gcm.GoogleCloudMessaging
)内找到GCM所需的文件。
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.0.1'
defaultConfig {
minSdkVersion 9
targetSdkVersion 18
}
signingConfigs {
release {
storeFile file("release.keystore")
storePassword "****"
keyAlias "****"
keyPassword "****"
}
}
buildTypes {
release {
signingConfig signingConfigs.release
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
compile 'com.android.support:support-v4:18.0.0'
// You must install or update the Google Repository through the SDK manager to use this dependency.
// The Google Repository (separate from the corresponding library) can be found in the Extras category.
compile 'com.google.android.gms:play-services:4.2.42'
}
答案 0 :(得分:1)
我无法确定您的问题是什么,但您丢失的进口来自Google Play服务。您可以使用此(或类似)命令在Mac或Linux上列出此jar中的类:
jar tvf "/Applications/Android Studio.app/sdk/extras/google/google_play_services/libproject/google-play-services_lib/libs/google-play-services.jar" | grep 'gms/common'
以下build.gradle适用于使用Google Cloud Messaging的代码:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.android.gms:play-services:4.3.+'
compile 'com.android.support:support-v4:19.0.+'
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 12
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}