Question

Getting NoClassDefFoundError within project and in Google Maps for Android sample found in google-play-services folder.

I have tried so far:

  • Importing google-play-services_lib into workspace through wizard and making sure code is copied to directory
  • Manually copying google-play-services_lib into directory with sample, then importing into workspace
  • Copying jar into workspace
  • Google Play Services is installed on test devices (Nexus 5, Galaxy S4)
  • There is a green check next to the library under my project when going to properties > android
  • I can see the classes in source at compile time, compiles with no errors
  • Reinstalled the lib from the Android SDK Manager and made sure the key is correct in Google API console; also made sure v2 of maps was enabled for that key
  • Added proguard exceptions as per integration instructions

Any ideas?

Manifest:

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

    <uses-sdk
        android:minSdkVersion="18"
        android:targetSdkVersion="21" />

    <permission
        android:name="com.package.projectname.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.package.projectname.permission.MAPS_RECEIVE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.package.projectname.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".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>
        <activity
            android:name="com.package.projectname.MapActivity"
            android:label="@string/title_activity_map"
            android:parentActivityName="com.package.projectname.MainActivity" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.package.projectname.MainActivity" />
        </activity>

        <uses-library
            android:name="com.google.android.maps"
            android:required="true" />

        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value=“my_key_from_google_api_console” />
    </application>

</manifest>
Was it helpful?

Solution

I don't think you need the line:

    <uses-library
        android:name="com.google.android.maps"
        android:required="true" />

In fact, I think that's the name of the old maps library. Try removing it and see if that fixes your problem. Also, make sure your code is importing from com.google.android.gms.maps and com.google.android.gms.maps.model, the packages for Google Maps API V2.

UPDATE

Your build configuration isn't including the Google Play Services jar in your APK.

To fix this in IntelliJ: https://stackoverflow.com/a/17977734/1235702

To fix this in Eclipse, follow steps 3 and 4 here: https://docs.google.com/document/pub?id=19nQzvKP-CVLd7_VrpwnHfl-AE9fjbJySowONZZtNHzw (I didn't write this doc, but kudos to whoever did!)

  1. Add the Google Play Services project into your Eclipse workspace.
    • Click File -> Import..., select Android -> Existing Android Code into Workspace Browse to and select /extras/google/google_play_services/libproject/google-play-services_lib
  2. To add the dependency to Google Play Services into your project
    • Project -> Properties -> Android -> Library, Add -> google-play-services_lib

(Sorry; the markdown won't let me set the numbers to 3 and 4 explicitly.)

Screenshot from OP for posterity: Eclipse properties for Google Play Services Lib

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top