简体   繁体   中英

Google MapFragment is blank (white) with Could not find class 'maps.j.k'

I'm trying to build the official android google map api v2 sample on a (gingerbread 2.3.5) phone . I added android-support-v4.jar to official sample project.

I took the sample from the official tutorial in <android-sdk>/extras/google-play-services/samples/maps

I copied the sample app in Eclipse, reference the google-play-services_lib project as an Android library, and build the whole thing with the Android SDK 4.1.2 (api 16).

Unfortunately, ahen I launch the app the map is blank and I don't have any exception or message. The only thing I got are those suspicious lines in the logcat :

    Unable to resolve superclass of Lmaps/a/du; (411)                     
    Link of class 'Lmaps/a/du;' failed                                    
    Unable to resolve superclass of Lmaps/a/ej; (2363)                    
    Link of class 'Lmaps/a/ej;' failed                                    
    Unable to resolve superclass of Lmaps/j/k; (2379)                     
    Link of class 'Lmaps/j/k;' failed                                     

ERR Could not find class 'maps.j.k', referenced from method maps.y.ae.a
VFY: unable to resolve new-instance 3571 (Lmaps/j/k;) in Lmaps/y/ae;

I suspect that my project structure in eclipse 3.8 is somewhat messed up.

I tried the following things (even the most idiotic) to no avail.

1. Invalid api key ?

I generated a "debug.keystore" with keytool and updated the eclipse preference (Android/Build/Keystore). Of course, I registered that new keystore/SHA1 and get a new api key that I used in the AndroidManifest file

2. Wrong project target ?

I tried to build my two projects with the following targets :

  • Android 4.2.1
  • Google Api 4.2.1

3. adding google-play-services_lib as a project dependency

I tried to add google-play-services_lib as a project dependency on top of being added as an android library in the demo build path. And tick the matching export checkbox.

4. test google maps api v2 on the phone

I downloaded trulia real estate app that is said to use the v2 api on the phone to be sure that the phone is compatible with the new api

Here is the manifest for the sample app

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.mapdemo"
    android:versionCode="1"
    android:versionName="1.0" >
    <permission
        android:name="com.example.mapdemo.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />
    <uses-permission android:name="com.example.mapdemo.permission.MAPS_RECEIVE" />
    <!-- Copied from Google Maps Library/AndroidManifest.xml. -->
    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="16" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <!-- External storage for caching. -->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <!-- My Location -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <!-- Maps API needs OpenGL ES 2.0. -->
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />
    <!-- End of copy. -->
    <application
        android:hardwareAccelerated="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/demo_title" >
        <!-- You must insert your own Google Maps for Android API v2 key in here. -->
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="XXXXXXXX" />
        <activity android:name=".MainActivity" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".BasicMapActivity"
            android:label="@string/basic_map" />
        <activity
            android:name=".CameraDemoActivity"
            android:label="@string/camera_demo" />
        <activity
            android:name=".EventsDemoActivity"
            android:label="@string/events_demo" />
        <activity
            android:name=".GroundOverlayDemoActivity"
            android:label="@string/groundoverlay_demo" />
        <activity
            android:name=".LayersDemoActivity"
            android:label="@string/layers_demo" />
        <activity
            android:name=".LocationSourceDemoActivity"
            android:label="@string/locationsource_demo" />
        <activity
            android:name=".MarkerDemoActivity"
            android:label="@string/marker_demo" />
        <activity
            android:name=".OptionsDemoActivity"
            android:label="@string/options_demo" />
        <activity
            android:name=".PolygonDemoActivity"
            android:label="@string/polygon_demo" />
        <activity
            android:name=".PolylineDemoActivity"
            android:label="@string/polyline_demo" />
        <activity
            android:name=".ProgrammaticDemoActivity"
            android:label="@string/programmatic_demo" />
        <activity
            android:name=".TileOverlayDemoActivity"
            android:label="@string/tile_overlay_demo" />
        <activity
            android:name=".UiSettingsDemoActivity"
            android:label="@string/uisettings_demo" />
        <activity
            android:name=".RawMapViewDemoActivity"
            android:label="@string/raw_mapview_demo" />
        <activity
            android:name=".RetainMapActivity"
            android:label="@string/retain_map" />
        <activity
            android:name=".MultiMapDemoActivity"
            android:label="@string/multi_map_demo" />
    </application>
</manifest>

Here are some screenshots of my project structure/build path.

项目结构

目标和图书馆

建立路径

I think maybe you make something wrong when you apply the api KEY. I have the same problem, and at last I found that I turn on the incorrect service. at https://code.google.com/apis/console/ ,

There are Google Maps API v2 and Google Maps Android API v2 .

You should use Google Maps Android API v2 .

I had exactly the same problem (all configurations the same, maps.jk stuff in the logcat). However, for me choosing Google APIs as build target solved it. But that was Google APIs 4.2, so I suggest that you install the update and try with the more recent target.

I resolved this issue by changing de targetSdkVersion with de last targetSdkVersion avaiable, at the AndroiMainfest.xml file.

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

Are you using ProGuard? Usually class names like "a", "b", etc. are a result of ProGuard obfuscating class names, and maybe the Maps API breaks when that happens. If that's the case, you will either have to disable ProGuard or add some -keep lines to your proguard.cfg file. This post shows what those lines might look like.

In my case it was due to 2 issues

  1. on my phone the latest Google Maps app was not installed (in fact there was no google maps at all)
  2. I didnt have all the required permissions set in my manifest

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

As documented in https://developers.google.com/maps/documentation/android/start#installing_the_google_maps_android_v2_api

http://developer.android.com/sdk/index.html -这是android..try中adt包的链接,下载并重新开始..可能你的ADT有问题。

检查您已启用Google Maps Android API v2的控制台API

I was dealing with same issue. I tried to implement the com.example.mapdemo and had a heck of a time.

I copied the code of the BasicMapActivity to a clean new project and made the Libraries look as above.

Basically, I couldn't get either to work. I got the "Authorization failure" error in the debugger.

Then, today, I prepared new keys specifically for each project with the specific com.example.xxx after the semicolon when preparing the key in the Google Console.

I did Project->Clean at every step.

I ran it in debugger first, then just Run. And, if I remember, a few times after making the change to the manifest.

Then, finally, they worked. It seemed, in the end, to require a key for each specific project.

Here's what worked for me. When you use the Google APIs Console to create your API key, be sure to append ;com.example.mapdemo to the SHA1 fingerprint. (I was using something else more appropriate for another app I'm currently developing.) What clued me in on this solution was an authorization error in the LogCat.

In my case I added LocationSource Interface so I can get location data but i forgot to add :

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

at Manifest file.

不要忘记使用单独的键来调试和发布应用程序的版本!

If you have already tried everything, try to uninstall and reinstall again your app: on my phone (S3 mini), after the first launch with the wrong key, I corrected it, but it didn't work until a complete uninstallation. Maybe some sort of caching is used.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM