title: Google Maps Android API v2 throws GooglePlayServicesNotAvailableException, out of date, SupportMapFragment.getMap() returns null
body: <p>I am trying to incorporate the new Google Maps Android API v2 into an application using the Android Support Library.
  I've gone through many iteration to try to get somewhere to work and now I have given up and thought I should ask here.</p>
  
  <p>I went to the API Console, created a project, enabled Google Maps API v2 for Android, created a debug KEY as required and pasted it on the manifest. No authentication problems or anything like that. Pretty sure I did this right.</p>
  
  <p>In my project's <code>libs</code> folder I put <code>android-support-v4.jar</code> (via project right-click->Android->Add Support Library...). In Eclipse I did File->Import->Android->Existing Android Code Into Workspace and imported the latest (rev 3) of android-sdk/google/google_play_services/libproject/google-play-services_lib. Then I added it as a dependency library to my project (project right-click->Properties->Android->Add it as a library dependency on the bottom.</p>
  
  <p>In my manifest I have:</p>
  
  <pre><code>&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" ...&gt;
      &lt;permission
        android:name="myapp.permission.MAPS_RECEIVE"
        android:protectionLevel="signature"/&gt;
  
      &lt;All the uses-permission required like INTERNET, ACCESS_NETWORK_STATE, WRITE_EXTERNAL_STORAGE, FINE AND COARSE LOCATION, etc&gt;
      &lt;uses-permission android:name="myapp.permission.MAPS_RECEIVE"/&gt;
      &lt;uses-feature android:glEsVersion="0x00020000" android:required="true"/&gt;
      &lt;application ...&gt;
          ...
          &lt;uses-library android:name="com.google.android.maps" /&gt;
          &lt;meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AI..."/&gt;
      &lt;/application&gt;
  </code></pre>
  
  <p>In my mainview.xml I have:</p>
  
  <pre><code>&lt;fragment
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/map"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     class="com.google.android.gms.maps.SupportMapFragment" /&gt;
  </code></pre>
  
  <p>Now on MainView.java I have:</p>
  
  <pre><code>import android.support.v4.app.Fragment;
  import android.support.v4.app.FragmentActivity;
  import android.support.v4.app.FragmentManager;
  import android.support.v4.app.FragmentTransaction;
  import com.google.android.gms.maps.GoogleMap;
  import com.google.android.gms.maps.SupportMapFragment;
  
  public class MainView extends FragmentActivity ... {
      private GoogleMap mMap;
  
      @Override
      protected void onResume() {
          ...
          Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.map);
          SupportMapFragment mapFragment = (SupportMapFragment)fragment;
          mMap = mapFragment.getMap();
          //PROBLEM: mMap is null here even though mapFragment is not
      }
  }
  </code></pre>
  
  <p>Then I thought I probably need to initialize the fragments so I added in my <code>onCreate</code> after setting the content view:</p>
  
  <pre><code>//Fragments
  FragmentManager manager = getSupportFragmentManager(); 
  FragmentTransaction transaction = manager.beginTransaction();
  transaction.add(R.id.map, SupportMapFragment.newInstance());
  transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
  transaction.commit();
  </code></pre>
  
  <p>Then I said, maybe it's not <code>SupportMapFragment</code> but I actually should refer to the actual fragment, and in my <code>onResume</code> I did:</p>
  
  <pre><code>Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.map);
  SupportMapFragment mapFragment = (SupportMapFragment)fragment;
  
  //Fragments
  FragmentManager manager = getSupportFragmentManager(); 
  FragmentTransaction transaction = manager.beginTransaction();
  transaction.add(R.id.map, mapFragment);
  transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
  transaction.commit();
  
  mMap = mapFragment.getMap();
  </code></pre>
  
  <p><code>mMap</code> is again null after this.</p>
  
  <p>Then I saw there is a <code>MapsInitializer</code> class, so I thought maybe I should call that first.</p>
  
  <p>So I added the code before getting the fragment in the above code:</p>
  
  <pre><code>try {
      MapsInitializer.initialize(this);
  } catch (GooglePlayServicesNotAvailableException e) {
      e.printStackTrace();
  }
  </code></pre>
  
  <p>With this Logcat reported the warning (line 313 is the <code>MapsInitializer.initialize(this)</code>):</p>
  
  <pre><code>com.google.android.gms.common.GooglePlayServicesNotAvailableException
      at com.google.android.gms.internal.n.c(Unknown Source)
      at com.google.android.gms.internal.n.a(Unknown Source)
      at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
      at myapp.activities.MainView.inflateSelectedViewAndSetData(MainView.java:313)
      at myapp.activities.MainView.onClick(MainView.java:642)
      at android.view.View.performClick(View.java:3153)
      at android.view.View$PerformClick.run(View.java:12148)
      at android.os.Handler.handleCallback(Handler.java:587)
      at android.os.Handler.dispatchMessage(Handler.java:92)
      at android.os.Looper.loop(Looper.java:152)
      at android.app.ActivityThread.main(ActivityThread.java:4615)
      at java.lang.reflect.Method.invokeNative(Native Method)
      at java.lang.reflect.Method.invoke(Method.java:491)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
      at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>Throughout my attempts Logcat would report the following warning:</p>
  
  <pre><code>Google Play services out of date.  Requires 2010100 but found 1013
  </code></pre>
  
  <p>This could be a/the culprit but I found no solution.</p>
  
  <p>At this point I am out of ideas. I read several threads <a href="https://stackoverflow.com/questions/13696620/google-maps-android-api-v2-authorization-failure">here</a>, <a href="https://stackoverflow.com/questions/13691943/this-app-wont-run-unless-you-update-google-play-services-via-bazaar">here</a>, <a href="https://plus.google.com/+AndroidDevelopers/posts/Tyz491d96Ci" rel="nofollow noreferrer">here</a> but none of the suggestions resolved the problem. On the latter they suggest not including the project dependency and just including the jar file. Well, that did not work either using either <code>google-play-services.jar</code> from the <code>google-play-services_lib/libs</code> folder or exporting my own jar from that project.</p>
  
  <p>By the way I am running on an actual device (2.3.5 and a tablet with 3.2), not the emulator.</p>
  
  <p>Any help wholeheartedly appreciated. :)</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>The solution is below by qubit.</p>
  
  <p>As far exporting the library dependency, a neat way to not have to deal with it (which is a pain when dealing with repositories) is to use <a href="http://fjep.sourceforge.net/" rel="nofollow noreferrer">FatJar</a> and export the <code>google_play_services_lib</code> project (which I DID NOT create a local copy from because when it updates I don't want to re-import), and include tha output fat jar file in your project as another jar file. 
  NOTE: When choosing which jar files to include in the fat jar, I had to exclude the <code>annotations.jar</code> file as it was already pre-included and was causing errors for duplication. 
  Now all I have to do is include the <code>google_play_services_rev_3.jar</code> in my project's <code>libs</code> folder and I am good to go.</p>