0

我試圖將Google Cloud Messaging添加到Android Studio上的應用程序,但似乎無法與該庫集成。下面是我的build.gradle文件的代碼,我根據這裏的建議修改了這些代碼:http://developer.android.com/google/play-services/setup.html#Setup無法將Google Cloud Messaging與Android Studio上的Android項目集成

我應該提到,我也在使用Google+登錄,而不是任何問題。

該應用程序是無法找到所需的文件裏面com.google.android.gms(特別common.ConnectionResultcommon.GooglePlayServicesUtilgcm.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:[email protected]' 
    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

庫中的min SDK版本是什麼? –

+0

這是什麼版本的Android Studio? –

回答

1

我不能肯定地說你的問題是什麼,但你是來自谷歌缺少進口三合一服務。您可以列出從這個罐子在Mac或Linux與此有關的類(或類似)命令:

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正常工作與我的代碼,使用谷歌雲消息:

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 
    } 
}