java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable in android
Asked Answered
E

10

13

I tried a demo on displaying google maps v2 in android.

The java code is,

package com.example.gpslocator;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}    
}

The Xml code is,

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>

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

I added API key in manifest.xml,

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.gpslocator"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="3"
    android:targetSdkVersion="17" />

<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" />
<!--
 The following two permissions are not required to use
 Google Maps Android API v2, but are recommended.
-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<permission
    android:name="com.example.mapdemo.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

<uses-permission android:name="com.example.mapdemo.permission.MAPS_RECEIVE" />

<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="com.example.gpslocator.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="MY_API_KEY" />
</application>

</manifest>

When I tried to run my Application closes of suddenly. When I debug, It showed me the error, "java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable". I added google-play-services.jar file to my application.

The logcat is,

04-09 05:33:53.677: E/Trace(1053): error opening trace file: No such file or directory (2)
04-09 05:33:53.807: W/ActivityThread(1053): Application com.example.gpslocator is waiting for the debugger on port 8100...
04-09 05:33:53.878: I/System.out(1053): Sending WAIT chunk
04-09 05:33:54.207: I/dalvikvm(1053): Debugger is active
04-09 05:33:54.288: I/System.out(1053): Debugger has connected
04-09 05:33:54.288: I/System.out(1053): waiting for debugger to settle...
04-09 05:33:54.487: I/System.out(1053): waiting for debugger to settle...
04-09 05:33:54.697: I/System.out(1053): waiting for debugger to settle...
04-09 05:33:54.897: I/System.out(1053): waiting for debugger to settle...
04-09 05:33:55.097: I/System.out(1053): waiting for debugger to settle...
04-09 05:33:55.297: I/System.out(1053): waiting for debugger to settle...
04-09 05:33:55.498: I/System.out(1053): waiting for debugger to settle...
04-09 05:33:55.708: I/System.out(1053): waiting for debugger to settle...
04-09 05:33:55.907: I/System.out(1053): waiting for debugger to settle...
04-09 05:33:56.167: I/System.out(1053): waiting for debugger to settle...
04-09 05:33:56.367: I/System.out(1053): debugger has settled (1344)
04-09 05:34:06.097: W/dalvikvm(1053): VFY: unable to resolve static field 867 (MapAttrs) in Lcom/google/android/gms/R$styleable;
04-09 05:34:06.097: D/dalvikvm(1053): VFY: replacing opcode 0x62 at 0x000e
04-09 05:40:21.278: D/AndroidRuntime(1053): Shutting down VM
04-09 05:40:21.278: W/dalvikvm(1053): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
04-09 05:40:21.398: E/AndroidRuntime(1053): FATAL EXCEPTION: main
04-09 05:40:21.398: E/AndroidRuntime(1053): java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
04-09 05:40:21.398: E/AndroidRuntime(1053):     at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
04-09 05:40:21.398: E/AndroidRuntime(1053):     at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
04-09 05:40:21.398: E/AndroidRuntime(1053):     at android.app.Activity.onCreateView(Activity.java:4716)
04-09 05:40:21.398: E/AndroidRuntime(1053):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
04-09 05:40:21.398: E/AndroidRuntime(1053):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
04-09 05:40:21.398: E/AndroidRuntime(1053):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
04-09 05:40:21.398: E/AndroidRuntime(1053):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
04-09 05:40:21.398: E/AndroidRuntime(1053):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
04-09 05:40:21.398: E/AndroidRuntime(1053):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
04-09 05:40:21.398: E/AndroidRuntime(1053):     at android.app.Activity.setContentView(Activity.java:1881)
04-09 05:40:21.398: E/AndroidRuntime(1053):     at com.example.gpslocator.MainActivity.onCreate(MainActivity.java:12)
04-09 05:40:21.398: E/AndroidRuntime(1053):     at android.app.Activity.performCreate(Activity.java:5104)
04-09 05:40:21.398: E/AndroidRuntime(1053):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
04-09 05:40:21.398: E/AndroidRuntime(1053):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
04-09 05:40:21.398: E/AndroidRuntime(1053):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
04-09 05:40:21.398: E/AndroidRuntime(1053):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
04-09 05:40:21.398: E/AndroidRuntime(1053):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
04-09 05:40:21.398: E/AndroidRuntime(1053):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-09 05:40:21.398: E/AndroidRuntime(1053):     at android.os.Looper.loop(Looper.java:137)
04-09 05:40:21.398: E/AndroidRuntime(1053):     at android.app.ActivityThread.main(ActivityThread.java:5041)
04-09 05:40:21.398: E/AndroidRuntime(1053):     at java.lang.reflect.Method.invokeNative(Native Method)
04-09 05:40:21.398: E/AndroidRuntime(1053):     at java.lang.reflect.Method.invoke(Method.java:511)
04-09 05:40:21.398: E/AndroidRuntime(1053):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-09 05:40:21.398: E/AndroidRuntime(1053):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-09 05:40:21.398: E/AndroidRuntime(1053):     at dalvik.system.NativeStart.main(Native Method)
04-09 05:40:26.487: I/Process(1053): Sending signal. PID: 1053 SIG: 9

In properties-->Android-->

enter image description here

Please any one help me out. Am I missing any reference?

Exhibition answered 9/4, 2013 at 5:44 Comment(0)
W
29

See the answer here:
Google Maps Android API v2 - Sample Code crashes
While the question lists a different exception, the answer specifically mentions your exact problem.

Specifically, it's important to import google-play-services_lib as a project:
Select File > Import > Android > Existing Android Code Into Workspace and click Next.
Select Browse..., enter [android-sdk-folder]/extras/google/google_play_services/libproject/google-play-services_lib, and click Finish.
(See https://developers.google.com/maps/documentation/android/intro under "Sample Code")
Then follow the instructions from the linked answer:

  • Import the actual source for the "google-play-services_lib" project and link it as an >Android library.
    • Do this through Project -> Properties -> Android -> Library, Add -> google-play-services_lib (you can right click on your project and choose Properties, then select Android).
    • Do not add it as a dependent Project through the "Java Build Path" for your project, that didn't work for me.
Weeden answered 9/4, 2013 at 5:54 Comment(6)
Tried the same. That didnot solve the Problem. I added all the references, but, could not get the solution....Exhibition
Nope, can't get it to fail that way. You said you added google-play-services.jar - have you tried instead doing "project properties->android->library" and then adding the google-play-services_lib project?Weeden
Yes. but it is showing as the reference was not considered. Please have a look at the image I attached.Exhibition
Did you actually import google-play-services_lib (as a project) into Eclipse? See developers.google.com/maps/documentation/android/intro under "Sample Code"Weeden
did not work for me, followed all steps and still complains about the same errorAuxiliaries
I'm using Titanium Studio and there is no Android menu into File > Import some ideas?Kirbee
R
6

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

package="com.google.android.gms"
Reprehension answered 22/4, 2013 at 21:59 Comment(1)
I thought that will always be the case if you import Google Play Services Lib?Delaryd
H
1

When you import google-play-services_lib, check "copy the project into workspace". It works for me!

Hamby answered 24/5, 2013 at 6:15 Comment(0)
K
1

I had this same issue, and I was able to solve it by right-clicking the google-play-services_lib project and refreshing. For some reason the project wasn't synced with Eclipse which was causing the error.

Korten answered 14/6, 2013 at 15:40 Comment(0)
S
1

I have the same issue.

But What I did is I used com.google.android.gms Version Code this 3265130

Rather than using com.google.android.gms Version Code this 4452000, Which is the latest one, I don't know what the issue is But its work for me.

[Follow the steps given by Alexander]

Might be work well with new Updates.

enter image description here

Might be work well with new Updates.

enter image description here

Smothers answered 21/5, 2014 at 12:55 Comment(0)
I
0

The file path to the google-play-services_lib project must have only [A-Z,a-z] not ÄÖÜ. I have moved it to D:\google-play-services_lib\ than imported it new and it works!

Sorry for my English ;-)

Irreverence answered 5/5, 2013 at 20:14 Comment(0)
L
0

import both google-play-services_lib & demo project to workspace; cope android-support-v4.jar to "libs" folder under demo project; and then: project properties->android->library" and then adding the google-play-services_lib

Lind answered 2/9, 2013 at 11:31 Comment(0)
N
0

Look at John Oleynik's steps: https://mcmap.net/q/95375/-google-maps-android-api-v2-sample-code-crashes . That worked for me.

Negation answered 11/1, 2014 at 16:8 Comment(0)
E
0

When you've imported project google-play-services_lib to your IDE don't forget to check its properties. google-play-services_lib shall be build with the same version of Android SDK that you use for your project. For example your project and google-play-services are both build with Android 4.4.2. After that you should see that the lib is correctly built.

Finally, you should add the following meta tag to the AndroidManifest.xml inside the <application> ... </application> tags:

<meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
Ehman answered 3/2, 2014 at 18:24 Comment(0)
D
0

I had many problems with that maps. But finaly succes, build! I dont use eclipse, just command line. First I tougth that I just copy to myProject/libs/ files from google-play-services_lib/libs and ececute ant debug ... After install on android emulator I get error java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable

Day later afer hours serching solution:

1)First I copy catalog sdk/extras/google/.../google-play-services_lib to my myProject catalog.

2)Do an android update project --target <your target> -p myProject/google-play-services_lib like user dzeikei said (to check targets exec: android list target)

3)edit file "project.properties" in folder myProject, and add this line in the end android.library.reference.1=google-play-services_lib or execute android update project --target android-19 --path myProject --library myProject/google-play-services_lib

4)ant clean, ant debug .... but there was some errors e.g. return null etc(make headache). but after that ant create bin and gen folders in folder myProject/google-play-services_lib

5)ater searching many solutions for ages to faind why ant debug returned errors I finaly piece off and just copy catalogs bin and gen from myProject/google-play-services_lib/ to myProject/bin and myProject/gen

6)then delete line I was added previously at point 3. above #android.library.reference.1=google-play-services_lib, and copy file myProject/google-play-services_lib/libs/google-play-services.jar to myProject/libs/google-play-services.jar

7)execute ant debug

adb install -r bin/myProject-debug.apk

and finaly saw google map in my projectApplication on android emulator :)

Of course other stuf like API_KEY or adding and permisions from google maps tutorial I done before I compile project. To see map without promt eg. "Instal Goodle Play Services" use emulator with google services already instaled. I used Google APIs(Google Inc.) from AVD Manager list. I hope this help You.

Demers answered 27/9, 2014 at 10:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.