-1
01-19 20:30:59.245 18242-18242/kianyang.scbg E/GMPM: 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.
01-19 20:30:59.245 18242-18242/kianyang.scbg E/GMPM: Scheduler not set. Not logging error/warn.
01-19 20:30:59.295 18242-18290/kianyang.scbg E/GMPM: Uploading is not possible. App measurement disabled

My code compiles successfully. But Google Maps cannot start. What is the problem? This error shows up when I try to compile. But the compile is fine, it just cannot start Google Maps.

MapsActivity.java

package kianyang.scbg;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MapsActivity extends FragmentActivity{

    private GoogleMap mMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        // Obtain the SupportMapFragment and get notified when the map is ready to be used.
      setUpMapIfNeeded();
    }

@Override
    protected  void onResume(){
    super.onResume();
    setUpMapIfNeeded();

}

    private  void setUpMapIfNeeded(){

        if(mMap==null){

            mMap=((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map))
                    .getMap();

            if(mMap!=null){
                setUpMap();
            }
        }




    }
    /**
     * Manipulates the map once available.
     * This callback is triggered when the map is ready to be used.
     * This is where we can add markers or lines, add listeners or move the camera. In this case,
     * we just add a marker near Sydney, Australia.
     * If Google Play services is not installed on the device, the user will be prompted to install
     * it inside the SupportMapFragment. This method will only be triggered once the user has
     * installed Google Play services and returned to the app.
     */
   private void setUpMap(){
       mMap.addMarker(new MarkerOptions().position(new LatLng(2.215035, 102.245443)).title("Marker"));
   }
}

Here is my manifest file. There is another intent inside it; just ignore it. Please help checking the Google Maps code.

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

    <permission
        android:name="kianyang.scbg.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <user-permission android:name="kianyang.scbg.permission.MAPS_RECEIVE" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />



    <!--
         The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
         Google Maps Android API v2, but you must specify either coarse or fine
         location permissions for the 'MyLocation' functionality. 
    -->
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyAljcGmDttsvHZjgpjFlsrsSfjTc6D9lkM" />

        <activity
            android:name=".Home"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Searchactivity"
            android:label="@string/title_activity_searchactivity">
            <intent-filter>
                <action android:name="kianyang.scbg.Searchactivity" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Vendoractivity"
            android:label="@string/title_activity_vendoractivity">
            <intent-filter>
                <action android:name="kianyang.scbg.Vendoractivity" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Cartactivity"
            android:label="@string/title_activity_cartactivity">
            <intent-filter>
                <action android:name="kianyang.scbg.Cartactivity" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Loginactivity"
            android:label="@string/title_activity_loginactivity">
            <intent-filter>
                <action android:name="kianyang.scbg.Loginactivity" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Signupactivity"
            android:label="@string/title_activity_signupactivity">
            <intent-filter>
                <action android:name="kianyang.scbg.Signupactivity" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name=".save_info_layout"
            android:label="@string/title_activity_save_info_layout" />
        <activity android:name=".DisplayProduct" />

        <intent-filter>
            <action android:name="kianyang.scbg.Locationactivity" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
        <!--
             The API key for Google Maps-based APIs is defined as a string resource.
             (See the file "res/values/google_maps_api.xml").
             Note that the API key is linked to the encryption key used to sign the APK.
             You need a different API key for each encryption key, including the release key that is used to
             sign the APK for publishing.
             You can define the keys for the debug and release targets in src/debug/ and src/release/. 
        -->
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version"/>
        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/google_maps_key" />

        <activity
            android:name=".MapsActivity"
            android:label="@string/title_activity_maps"></activity>
    </application>

</manifest>
Eric Galluzzo
  • 3,191
  • 1
  • 20
  • 20
huhush
  • 43
  • 6

2 Answers2

0

You seem to be missing the Google Maps API key in your .XML file (this allows you to access the google servers). The dev blog for setting up maps for android is Here, step #4 describes how to acquire a key.

tacoswin
  • 1
  • 1
0

For this error you may be missing either the google-services.json which you can get in this link or you are missing the proper plugin com.google.gms.google-services. Check the build.gradle file if you have this line compile com.google.android.gms:play-services:8.4.0(8.4.0 is the latest version but it can be 8.3.0 or lower). If not, you can download it through SDK Manager.

Note: You need SD card if you will use com.google.android.gms:play-services:8.4.0 for further explanation, see this link.

gerardnimo
  • 1,444
  • 8
  • 10