Somnath Kayal
Somnath Kayal

Reputation: 393

Unable to setup Google Play Services

I have been stuck over a day to use the Google Play Service. This is a very bad procedure created by Google. Why it is that difficult?? I want to use Google Play Service in order to develop some apps which depends on the Map. I have been tried everything step by step, discussed on many sites but still unable to get it. I thought only the StackOverflow can help in this situation. I can't give the link of all the reference websites but i am giving some of them-
http://developer.android.com/google/play-services/setup.html#Setup
http://www.vogella.com/tutorials/AndroidGoogleMaps/article.html#installmaps
Setup Google Play Games Services
I am using Eclipse ADT Bundle. Google Play Service has a mark with a tick in Android SDK which indicates that it is installed. It is also foud in the proper directory. I am providing the snapshot of my project- enter image description here


The above snoapshot shows the activity_main.xml, Errors while Launching the application and Project Tree Structure. It also shows that google_play_service_lib has been imported.

public class MainActivity extends ActionBarActivity {

static final LatLng HAMBURG = new LatLng(53.558, 9.927);
  static final LatLng KIEL = new LatLng(53.551, 9.993);
  private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

     map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
            .getMap();
        Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
            .title("Hamburg"));
        Marker kiel = map.addMarker(new MarkerOptions()
            .position(KIEL)
            .title("Kiel")
            .snippet("Kiel is cool")
            .icon(BitmapDescriptorFactory
                .fromResource(R.drawable.ic_launcher)));

        // Move the camera instantly to hamburg with a zoom of 15.
        map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));

        // Zoom in, animating the camera.
        map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
}

The Project is not contain any error. I've also added the code into the proguard-project.txt and the android-manifest.xml is

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.latlongfrommap"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
    android:minSdkVersion="17"
    android:targetSdkVersion="19" />

<uses-permission android:name="com.vogella.android.locationapi.maps.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<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" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.latlongfrommap.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

     <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="AIzaSyAQXXXXXXXXXXXXXXpADfMsO4fF0eEXdRE" />
</application>

Also I've been generated the API Key from the console.Graphical layout of activity-main is also has an warning.enter image description here enter image description here

Please Help me out by your valuable advise. Thanking you.
EDIT:
In the official set up guide, they didn't mention that jar file should be added to the library.. I did that because I found it in many websites.. is It correct??.. The fragment tag is not detected by the activity_main.xml.. is there any problem with that??
Yes, I was right about the jar file. It should not be added. It was creating some kind of conflict. But I still have errors

FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.latlongfrommap/com.example.latlongfrommap.MainActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2314)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2388)
at android.app.ActivityThread.access$800(ActivityThread.java:148)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1292)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5312)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:377)
at android.app.Activity.setContentView(Activity.java:2154)
at android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:217)
at android.support.v7.app.ActionBarActivityDelegateICS.setContentView(ActionBarActivityDelegateICS.java:110)
at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:77)
at com.example.latlongfrommap.MainActivity.onCreate(MainActivity.java:25)
at android.app.Activity.performCreate(Activity.java:5953)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1128)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2267)
... 10 more
Caused by: java.lang.SecurityException: The Maps API requires the additional following permissions to be set in the AndroidManifest.xml to ensure a correct behavior:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
at com.google.maps.api.android.lib6.c.ck.a(Unknown Source)
at com.google.maps.api.android.lib6.c.i.a(Unknown Source)
at com.google.maps.api.android.lib6.c.el.a(Unknown Source)
at com.google.maps.api.android.lib6.c.ab.a(Unknown Source)
at com.google.maps.api.android.lib6.c.aa.a(Unknown Source)
at com.google.android.gms.maps.internal.x.onTransact(SourceFile:107)
at android.os.Binder.transact(Binder.java:380)
at com.google.android.gms.maps.internal.IMapFragmentDelegate$a$a.onCreateView(Unknown Source)
at com.google.android.gms.maps.MapFragment$a.onCreateView(Unknown Source)
at com.google.android.gms.dynamic.a$4.b(Unknown Source)
at com.google.android.gms.dynamic.a.a(Unknown Source)
at com.google.android.gms.dynamic.a.onCreateView(Unknown Source)
at com.google.android.gms.maps.MapFragment.onCreateView(Unknown Source)
at android.app.Fragment.performCreateView(Fragment.java:2053)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:870)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1045)
at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1147)
at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2118)
at android.app.Activity.onCreateView(Activity.java:5302)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
... 23 more

Upvotes: 1

Views: 2619

Answers (2)

Hatim
Hatim

Reputation: 1522

Also you need to import the one you need in gradle from these:

Google+ com.google.android.gms:play-services-plus:11.0.1
Google Account Login    com.google.android.gms:play-services-auth:11.0.1
Google Actions, Base Client Library com.google.android.gms:play-services-base:11.0.1
Google Address API  com.google.android.gms:play-services-identity:11.0.1
Google Analytics    com.google.android.gms:play-services-analytics:11.0.1
Google Awareness    com.google.android.gms:play-services-awareness:11.0.1
Google Cast com.google.android.gms:play-services-cast:11.0.1
Google Cloud Messaging  com.google.android.gms:play-services-gcm:11.0.1
Google Drive    com.google.android.gms:play-services-drive:11.0.1
Google Fit  com.google.android.gms:play-services-fitness:11.0.1
Google Location and Activity Recognition    com.google.android.gms:play-services-location:11.0.1
Google Maps com.google.android.gms:play-services-maps:11.0.1
Google Mobile Ads   com.google.android.gms:play-services-ads:11.0.1
Google Places   com.google.android.gms:play-services-places:11.0.1
Mobile Vision   com.google.android.gms:play-services-vision:11.0.1
Google Nearby   com.google.android.gms:play-services-nearby:11.0.1
Google Panorama Viewer  com.google.android.gms:play-services-panorama:11.0.1
Google Play Game services   com.google.android.gms:play-services-games:11.0.1
SafetyNet   com.google.android.gms:play-services-safetynet:11.0.1
Android Pay com.google.android.gms:play-services-wallet:11.0.1
Android Wear    com.google.android.gms:play-services-wearable:11.0.1

Upvotes: 0

Somnath Kayal
Somnath Kayal

Reputation: 393

Thank God. Finally it's done. Many websites said that, after doing all the stuff describing at the official tutorial site you need to do some extra things. Some of them are really helpful and some are not. Before you waste your complete day like me, remember the below things-

  1. "you have to add the google-play-services.jar externally to the library". That's entirely NOT TRUE. If you have already imported the google-play-services_lib project which is the first step of the official guide and again adding the jar, it will create a conflict to your program. So either you add the jar or import the google-play-services_lib project.
  2. Generate API Key using Google Developers Console. This step is really important and make sure the key has been attached to your manifest using meta tag.

    <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyAQ8XXXXXXXXXXXXXXXXXxxxxxxeEXdRE" />

To generate the key you'll need to know the package name of the project and SHA1 fringerprint which can be found by clicking the window -> Preferences -> Android -> Build.
    3. You have to add some permissions

<uses-permission android:name="com.vogella.android.locationapi.maps.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<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-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
  1. Before you do the step 4 of the official guide, you need to add the value into the string.xml which can be found at res/values directory of your project tree.

    <integer name="google_play_services_version">5089000</integer>

    where the version number can be found in sdk\extras\google\google_play_services\libproject\google-play-services_lib\res\values\version.xml

  2. the <fragment> tag of activity-main.xml may show you some awkward warning. Don't worry about it.

  3. Make sure that the Android Private Libraries option in Order & Export is checked. It actually link the google-play-services_lib project which consists all the libraries. To do that: Properties -> Build Path -> Order and Export -> check Android Private Libraries

  4. Last but not least you have to clean your project before doing anything. To do so, goto project->clean and make sure that the Build Automatically is checked.

Upvotes: 1

Related Questions