java.lang.noclassdeffounderror: com.google.android.gms.R$styleable
Asked Answered
B

12

53

I am creating an android application using google maps. here is the code:

MapFragActivity.java

 import android.os.Bundle;
    import android.support.v4.app.FragmentActivity;
    import com.google.android.gms.maps.GoogleMap;
    import com.google.android.gms.maps.SupportMapFragment;

    public class MapFragActivity extends FragmentActivity {

    private GoogleMap map;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_map_frag);

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

AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.him.mapfrag_rnd"
        android:versionCode="1"
        android:versionName="1.0" >

        <uses-sdk
            android:minSdkVersion="11"
            android:targetSdkVersion="15" />


        <permission
            android:name="com.him.mapfrag_rnd.permission.MAPS_RECEIVE"
            android:protectionLevel="signature" />

        <uses-permission android:name="com.him.mapfrag_rnd.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="com.google.android.providers.gsf.permission.READ_GSERVICES" />

          <uses-feature
            android:glEsVersion="0x00020000"
            android:required="true" />


        <application
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name=".MapFragActivity"
                android:label="@string/title_activity_map_frag" >
                <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="my_api_key" />

        </application>

    </manifest>

activity_map_frag.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

    <fragment
      android:id="@+id/map"
      android:name="com.google.android.gms.maps.SupportMapFragment"
      android:layout_width="match_parent"
      android:layout_height="match_parent" />

    </RelativeLayout>

when I try this code I get an error, here is the log:

01-17 10:01:17.685: E/AndroidRuntime(8923): FATAL EXCEPTION: main
    01-17 10:01:17.685: E/AndroidRuntime(8923): java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
    01-17 10:01:17.685: E/AndroidRuntime(8923):     at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
    01-17 10:01:17.685: E/AndroidRuntime(8923):     at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
    01-17 10:01:17.685: E/AndroidRuntime(8923):     at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:279)
    01-17 10:01:17.685: E/AndroidRuntime(8923):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:669)
    01-17 10:01:17.685: E/AndroidRuntime(8923):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
    01-17 10:01:17.685: E/AndroidRuntime(8923):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
    01-17 10:01:17.685: E/AndroidRuntime(8923):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
    01-17 10:01:17.685: E/AndroidRuntime(8923):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
    01-17 10:01:17.685: E/AndroidRuntime(8923):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:272)
    01-17 10:01:17.685: E/AndroidRuntime(8923):     at android.app.Activity.setContentView(Activity.java:1835)
    01-17 10:01:17.685: E/AndroidRuntime(8923):     at com.him.mapfrag_rnd.MapFragActivity.onCreate(MapFragActivity.java:16)
    01-17 10:01:17.685: E/AndroidRuntime(8923):     at android.app.Activity.performCreate(Activity.java:4470)
    01-17 10:01:17.685: E/AndroidRuntime(8923):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
    01-17 10:01:17.685: E/AndroidRuntime(8923):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
    01-17 10:01:17.685: E/AndroidRuntime(8923):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
    01-17 10:01:17.685: E/AndroidRuntime(8923):     at android.app.ActivityThread.access$600(ActivityThread.java:127)
    01-17 10:01:17.685: E/AndroidRuntime(8923):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
    01-17 10:01:17.685: E/AndroidRuntime(8923):     at android.os.Handler.dispatchMessage(Handler.java:99)
    01-17 10:01:17.685: E/AndroidRuntime(8923):     at android.os.Looper.loop(Looper.java:137)
    01-17 10:01:17.685: E/AndroidRuntime(8923):     at android.app.ActivityThread.main(ActivityThread.java:4511)
    01-17 10:01:17.685: E/AndroidRuntime(8923):     at java.lang.reflect.Method.invokeNative(Native Method)
    01-17 10:01:17.685: E/AndroidRuntime(8923):     at java.lang.reflect.Method.invoke(Method.java:511)
    01-17 10:01:17.685: E/AndroidRuntime(8923):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:986)
    01-17 10:01:17.685: E/AndroidRuntime(8923):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:753)
    01-17 10:01:17.685: E/AndroidRuntime(8923):     at dalvik.system.NativeStart.main(Native Method)

when I make some changes in MapFragActivity.java, then map is displayed. here are the changes:

package com.him.mapfrag_rnd;

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

    import com.google.android.gms.maps.SupportMapFragment;

    public class MapFragActivity extends FragmentActivity {

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            //setContentView(R.layout.activity_map_frag);
          SupportMapFragment fragment = new SupportMapFragment();
          getSupportFragmentManager().beginTransaction().add(android.R.id.content, fragment).commit();
        }
    }

The change I have done is commented the setContentView. I have followed all the required steps and still I am getting and error. if uncomment the setContentView() then again I get the error.

Please HELP!!!

Balthasar answered 17/1, 2013 at 4:51 Comment(5)
i have Answer about this issue in [Here][1] [1]: #13691528Risinger
I have the same problem. Here is the answer #15894643 works for me!Tennessee
@Risinger you forget the Important questioning as the Consensus on the need for you code extends the classes and implement correctly interfaces to reach and importance of undeniably conditions. Its the priority in my company. I reduce 85% of code refactoring with this solution.Hickory
I want to add something: The path to your workspace should not contain space. I had my workspace in Google Drive desktop folder in Windows; and because of the space between "Google" and "Drive", my GoogleMap project repeatedly crashed with this error - R stylable not found. I tried all the solutions in stack overflow and internet, but to no avail. Then I created a new workspace in Dropbox folder (thanks to a comment somewhere), and it worked. It's weird.Clos
#34593349Hakon
S
40

What you have to do is include a Google Play Services library to your project. Google has very good instructions here:

Also, there is a quick start which I found very useful while trying to get Google Maps v2 to work.

Secund answered 1/2, 2013 at 3:0 Comment(4)
Hi.. I have imported only jar file, as I am getting a very big problem when I import the whole play service library then, it gives me No Project found to import errorCrimea
@GauravArora What do you mean "No Project found to import". What IDE are you using - Android Studio or Eclipse? Did you import google-play-services lib from sdk/android/extras/google/google_play_services/libproject?Dewy
Yes, from the SDK LocationCrimea
@Balthasar but how you can solve the organizational code level, the monitoring of consumer preferences facilitates the creation of the many bugs, and a lot of issues. Survey of the variables are involved?Hickory
P
74

If you are using Intellij Idea,

  1. Select your project from project panel
  2. Hit F4 in order to open the project structure window
  3. Select Modules from left panel, then hit + button then select "import module" and navigate to "ANDROID-SDK"/extras/google/google_play_services/libproject/google-play-services_lib. By doing this this project will be added to Modules alongside with your project
  4. Select your project, then select "Dependencies" (it's a Tab) from right panel. Click + button then "3 Module dependencies..." and select "google-play-services_lib".
  5. Click + button again then "1 jars or directories..." and navigate to "/libs" folder in the above path and select "google-play-services.jar".
  6. Click ok and close project structure window.

Note: Make sure you have not added "google-play-services_lib" project as library in "Libraries" (left panel under Modules). If you have, you can go to "Libraries and simply remove it. Google Play Library Should Not Appear In Libraries.

Note 2: You can copy the whole google-play-services_lib directory to your own project if you wish to have it in version control or similar.

Pulp answered 5/4, 2013 at 5:48 Comment(4)
I also had to check the export box for the google-play-services.jar to get my project working.Rheumy
I tried these steps in IntelliJ, but I get the following build error: "Android Dex: UNEXPECTED TOP-LEVEL EXCEPTION: Android Dex: java.lang.IllegalArgumentException: already added: Landroid/UnusedStub;"Dewy
@dart please make sure you have no duplicate libraries. For example, If you are using SDK of Facebook it has it's own support library in it's libs folder. If you are using support library in your project then compiler throws error. Solution is, point your project and Facebook (and other modules if you have) to a (one) support library.Pulp
I have solved this problem setting Anrdoid SDK to 8 (was 18). May be it's a clue.Burney
S
40

What you have to do is include a Google Play Services library to your project. Google has very good instructions here:

Also, there is a quick start which I found very useful while trying to get Google Maps v2 to work.

Secund answered 1/2, 2013 at 3:0 Comment(4)
Hi.. I have imported only jar file, as I am getting a very big problem when I import the whole play service library then, it gives me No Project found to import errorCrimea
@GauravArora What do you mean "No Project found to import". What IDE are you using - Android Studio or Eclipse? Did you import google-play-services lib from sdk/android/extras/google/google_play_services/libproject?Dewy
Yes, from the SDK LocationCrimea
@Balthasar but how you can solve the organizational code level, the monitoring of consumer preferences facilitates the creation of the many bugs, and a lot of issues. Survey of the variables are involved?Hickory
C
6

I think you have to import the whole Google Play Service library to your IDE, not only the .jar

try it ;-)

Copula answered 18/1, 2013 at 19:21 Comment(2)
Hi.. I have imported only jar file, as I am getting a very big problem when I import the whole play service library then, it gives me No Project found to import error.Crimea
try to solve it then... I think this is the right solution! encouragement!Copula
N
6

I have the same error. I use Android Studio and Gradle thus there are not too many things to configure or improve. I have done almost all things but they all did not work for me. The last one works: replace entire package play-services by smaller ones. In my case:

Replace (in build.gradle file):

compile 'com.google.android.gms:play-services:8.4.0'

by:

// Google Cloud Messaging
compile 'com.google.android.gms:play-services-gcm:8.4.0'

// Google Location
compile 'com.google.android.gms:play-services-location:8.4.0'
Necessitous answered 3/3, 2016 at 23:6 Comment(0)
A
6

i have also got this error in android studio and i had already included play services alpha 3 with gradle alpha5, what i did wrong was i have included multidex.

in gradle

multiDexEnabled true

and in Application class's onCreate

MultiDex.install(this);

but i forgot to extends Application class with MultiDexApplication

because MultiDexApplication has not been extended so that it can't include gms and any other dex classes so it's giving error at starting of gms String.

Hope this helps

Arbour answered 7/4, 2016 at 14:52 Comment(0)
C
5

I solved the issue by first checking the play services lib is added correctly and adding this data in manifest file under application tag <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

Collazo answered 11/2, 2014 at 8:48 Comment(0)
M
4

Check AndroidManifest.xml file of your google-play-services_lib project. Should be:

package="com.google.android.gms"
Michaelis answered 22/4, 2013 at 21:41 Comment(1)
Is it? package name is different for projects... its wrong do not cheatBoito
Y
2
  1. Use Android SDK Manager download "google play services"

  2. import it into your workspace (path: android-sdk root/extras/google/google_play_service/libproject/google-play-service_lib)

  3. project Properties -> android -> Library add google-play-service_lib

  4. Build path -> Order and Export check Android private libraries

Yusuk answered 30/5, 2013 at 10:15 Comment(0)
T
1

I solved this error by checking "Copy projects into workspace" while importing the Google Play Services lib.
More info here: http://developer.android.com/google/play-services/setup.html

Temper answered 20/4, 2013 at 7:49 Comment(1)
This worked for me. Actually, I had only imported the google play services from my previous workspace but had not copied into existing workspace :D Anyways, thanks :)Jugendstil
A
1

I have followed the Link http://www.vogella.com/tutorials/AndroidGoogleMaps/article.html

and added the google-play-services_lib library project to my application. It was working great up to yesterday. But to day i have got the exception mentioned above. It is because of the absence of google play library or my project not able to access the files from the library. I rebuilt my project but it was not succeeded. Then i rebuilt the google-play-services_lib library project but no hope. Then i tried the "build all" option in eclipse and it works fine.

enter image description here

Agentival answered 12/2, 2015 at 13:26 Comment(0)
K
1

If you are using split Google Play Services (see here : https://developers.google.com/android/guides/setup#split)

You must include the base play services to your gradle file:

compile 'com.google.android.gms:play-services-base:7.5.0'

Using slipt Play Services prevent the 65k error and make your app smaller

Kuntz answered 8/7, 2015 at 0:46 Comment(0)
S
1

This two google play service add into the build.gradle Its worked for me.. compile 'com.google.android.gms:play-services-appindexing:8.1.0' compile 'com.google.android.gms:play-services:8.1.0'

Sheerlegs answered 24/12, 2015 at 12:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.