title: Use of google map API crashes my application in Android studio
body: <p>I have an application which uses the Google map API. I tried so hard to figure out why my application crashes the moment it starts to run and displays a pop-up saying, "Unfortunately, myApplicaiton has stopped." I have spent many hours trying to see where else I should look into the code. </p>
  
  <p>Here is the Gradle of my project:</p>
  
  <pre><code>// Top-level build file where you can add configuration options common to all sub-projects/modules.
  
  buildscript {
      repositories {
          jcenter()
      }
      dependencies {
          classpath 'com.android.tools.build:gradle:1.0.0'
  
          // NOTE: Do not place your application dependencies here; they belong
          // in the individual module build.gradle files
      }
  }
  
  allprojects {
      repositories {
          jcenter()
      }
  }
  </code></pre>
  
  <p>Here's the Gradle of my module app:</p>
  
  <pre><code>apply plugin: 'com.android.application'
  
  android {
      compileSdkVersion 21
      buildToolsVersion "21.1.2"
  
      defaultConfig {
          applicationId "com.example.myApplication"
          minSdkVersion 15
          targetSdkVersion 21
          versionCode 1
          versionName "1.0"
      }
      buildTypes {
          release {
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
          }
      }
      sourceSets { main { assets.srcDirs = ['src/main/assets', 'src/main/assets/'] } }
  }
  
  dependencies {
      compile fileTree(dir: 'libs', include: ['*.jar'])
      compile 'com.android.support:appcompat-v7:21.0.3'
      compile files('libs/google-play-services.jar')
      compile files('libs/android-support-4.0.jar')
  }
  </code></pre>
  
  <p>Here is the code (MainActivity.java:89-95):</p>
  
  <pre><code>protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          requestWindowFeature(Window.FEATURE_NO_TITLE);
          getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
          setContentView(R.layout.activity_main);         //(MainActivity.java:93)
          StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
                  .permitAll().build();
  </code></pre>
  
  <p>and here is the error log: </p>
  
  <pre><code>12-13 15:26:35.724    7875-7875/com.example.myApplication E/AndroidRuntime﹕ FATAL EXCEPTION: main
      java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
              at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
              at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
              at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2158)
              at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:297)
              at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
              at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
              at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
              at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
              at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
              at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
              at android.app.Activity.setContentView(Activity.java:1881)
              at com.example.selflocation.MainActivity.onCreate(MainActivity.java:93)
              at android.app.Activity.performCreate(Activity.java:5104)
              at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
              at android.app.ActivityThread.access$600(ActivityThread.java:141)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
              at android.os.Handler.dispatchMessage(Handler.java:99)
              at android.os.Looper.loop(Looper.java:137)
              at android.app.ActivityThread.main(ActivityThread.java:5039)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:511)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
              at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>and here is my  android manifest</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.selflocation"
      android:versionCode="2"
      android:versionName="1.0.1" &gt;
  
      &lt;uses-sdk
          android:minSdkVersion="8"
          android:targetSdkVersion="17" /&gt;
  
      &lt;permission
          android:name="in.wptrafficanalyzer.locationingooglemapv2.permission.MAPS_RECEIVE"
          android:protectionLevel="signature" /&gt;
  
      &lt;uses-permission android:name="in.wptrafficanalyzer.locationingooglemapv2.permission.MAPS_RECEIVE" /&gt;
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
      &lt;uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
      &lt;uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /&gt;
      &lt;uses-permission android:name="android.permission.WAKE_LOCK"/&gt;
      &lt;uses-permission android:name="android.permission.GET_TASKS" /&gt;
      &lt;uses-permission android:name="android.permission.DISABLE_KEYGUARD"/&gt;
  
      &lt;uses-feature
          android:glEsVersion="0x00020000"
          android:required="true" /&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@drawable/logo"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
          &lt;activity
              android:name="com.example.myApplication.MainActivity"
              android:label="@string/app_name" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;activity android:name="com.example.myApplication.SetHomeLocation" &gt;
          &lt;/activity&gt;
  
          &lt;receiver android:name="com.example.myApplication.BootUpReceiver" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.BOOT_COMPLETED" /&gt;
  
                  &lt;category android:name="android.intent.category.HOME" /&gt;
              &lt;/intent-filter&gt;
          &lt;/receiver&gt;
  
          &lt;receiver
              android:name="com.example.myApplication.MyAdminReceiver"
              android:permission="android.permission.BIND_DEVICE_ADMIN" &gt;
              &lt;meta-data
                  android:name="android.app.device_admin"
                  android:resource="@xml/admin" /&gt;
  
              &lt;intent-filter&gt;
                  &lt;action android:name="android.app.action.DEVICE_ADMIN_ENABLED" /&gt;
              &lt;/intent-filter&gt;
          &lt;/receiver&gt;
  
      &lt;meta-data
              android:name="com.google.android.gms.version"
              android:value="4242000" &gt;
          &lt;/meta-data&gt;
          &lt;meta-data
              android:name="com.google.android.maps.v2.API_KEY"
              android:value="xxxxxxxxxxxx" /&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>