1

I am using google Maps in my android application. I have created the key and added necessary permissions in manifest file:

Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest package="com..."
          xmlns:android="http://schemas.android.com/apk/res/android">

    <uses-permission android:name="com....MAPS_RECEIVE"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
    <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-feature
        android:glEsVersion="0x00020000"
        android:required="true"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme.NoActionBar">

        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/google_maps_key"/>
        <activity
            android:name=".activities.MainActivity"
            android:windowSoftInputMode="stateHidden">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>

</manifest>

google-maps-api.xml:

<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">
    AIzaSyAjGQ-...
</string>

Also, I have added the following depedency compile 'com.google.android.gms:play-services:8.4.0' to compile, which is working:

app.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "com..."
        minSdkVersion 21
        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'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.3.0'
    compile 'com.google.android.gms:play-services:8.4.0'
}

I have also added google-services.json to PROJECT_NAME/app/:

enter image description here

But when the app is started, I get this message in debugger:

GoogleService failed to initialize, status: 10, Missing an expected resource: 'R.string.google_app_id' for initializing Google services.  Possible causes are missing google-services.json or com.google.gms.google-services gradle plugin.

I have followed steps on this link, but regarding my case, what could I miss to configure?

Community
  • 1
  • 1
Kapparino
  • 988
  • 11
  • 33

3 Answers3

3

I think

  1. you should add the plugin to the bottom of your app-level build.gradle:

apply plugin: 'com.google.gms.google-services'

  1. Add the dependency to your project-level build.gradle:

classpath 'com.google.gms:google-services:1.5.0-beta2'

For more information Check this

Edited:

New build.gradle looks like

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"

defaultConfig {
    applicationId "com..."
    minSdkVersion 21
    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'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.google.android.gms:play-services:8.4.0'
}
M D
  • 47,665
  • 9
  • 93
  • 114
  • Ok, but where exactly in the that gradle file ? Project or Module ? And where in the code ? – Kapparino May 13 '16 at 12:58
  • `apply plugin: 'com.google.gms.google-services'` in what section ? Between what parentheses ? – Kapparino May 13 '16 at 13:02
  • @Kapparino check this link in my answer and do as the step say. add `apply plugin: 'com.google.gms.google-services'` in just below `apply plugin: 'com.android.application'` – M D May 13 '16 at 13:03
  • I don't understand where this goes `apply plugin: 'com.google.gms.google-services'`, on the what line in the file, between what parentheses: android { defaultConfig, buildType {} } ? – Kapparino May 13 '16 at 13:04
  • 1
    Omg I have found it. Under `apply plugin: 'com.android.application'` – Kapparino May 13 '16 at 13:05
  • With this updates, I'm getting `Found com.google.android.gms:play-services:8.4.0, but version 8.3.0 is needed for the google-services plugin.` So I should use 8.3.0 or 8.4.0 ? – Kapparino May 13 '16 at 13:07
0

i had the same issue. i tried to solve it.but no luck.if you have backup project use that one.

snehasish
  • 171
  • 2
  • 10
0
  1. You need to place the configuration file generated by this Link.

  2. Then you need to Get Configuration file From This and Download it file named google.json.

  3. Then you need to put that file into your project at app/ or mobile/ directory of your Android.

And as you need to add apply plugin: 'com.google.gms.google-services' exact below of apply plugin: 'com.android.application' as in MD's answer Build.Gradle file.

After that Build->Clean your project.

And make sure you have string resource available with API_KEY in it named <string name="google_maps_key">Your Api Key</string>.

Community
  • 1
  • 1
Jay Rathod
  • 11,131
  • 6
  • 34
  • 58