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

后端 未结 10 1778
忘掉有多难
忘掉有多难 2020-11-27 21:33

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         


        
相关标签:
10条回答
  • 2020-11-27 22:06

    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.
    0 讨论(0)
  • 2020-11-27 22:06

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

    0 讨论(0)
  • 2020-11-27 22:07

    Look at John Oleynik's steps: www.stackoverflow.com/a/15709686/20146 . That worked for me.

    0 讨论(0)
  • 2020-11-27 22:08

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

    package="com.google.android.gms"
    
    0 讨论(0)
  • 2020-11-27 22:09

    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.

    0 讨论(0)
  • 2020-11-27 22:13

    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

    0 讨论(0)
提交回复
热议问题