ClassNotFoundException:com.google.android.gms.location.internal.ParcelableGeofence with Maps APIv2

时间:2014-07-18 05:53:32

标签: android google-maps google-play-services google-maps-api-2

我正在尝试创建一个显示地图并放大当前位置的Android应用程序(目前只是尝试让缩放工作),并且我在过去3天内遇到此错误:

java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.location.internal.ParcelableGeofence" on path: DexPathList[[zip file "/system/framework/com.android.media.remotedisplay.jar", zip file "/system/framework/com.android.location.provider.jar", zip file "/data/app/com.google.android.gms-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.google.android.gms-1, /vendor/lib, /system/lib]]

代码:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_map);
    map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
            .getMap();

    map.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
        @Override
        public void onMapLoaded() {
            map.setMyLocationEnabled(true);
            LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
//                map.animateCamera(CameraUpdateFactory.zoomBy(8));
        }
    });
}

在我的MainActivity.java和布局中:

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

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

清单中的相关组件:                         

<uses-permission     android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.PREVENT_POWER_KEY" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

<uses-sdk
    android:minSdkVersion="18"
    android:targetSdkVersion="18" />
<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />
<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen"
    android:uiOptions="">
    <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="XXX" />

感谢您的任何想法。到目前为止,大多数建议似乎表明API密钥存在一些问题 - 因此我从Google API控制台多次更改了API密钥,重新生成了我的debug.keystore并重新生成密钥无效。

更新:这是我的build.gradle:     apply plugin:'android'

android {     compileSdkVersion 19     buildToolsVersion“19.1.0”

defaultConfig {
    minSdkVersion 19
    targetSdkVersion 19
}
buildTypes {
    release {
        debug {
        }

        release {
        }
        runProguard false
//            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
}
sourceSets {
    androidTest {
        java.srcDirs = ['androidTest/java']
        androidTest.setRoot('androidTest')
    }
}
}

dependencies {
compile 'com.android.support:support-v4:20.0.0'
compile 'com.android.support:appcompat-v7:19.+'
compile 'com.google.android.gms:play-services:5.0.77'
androidTestCompile 'junit:junit:3.+'
}

1 个答案:

答案 0 :(得分:1)

我也遇到了这个问题,因为大约在你开始接受它的那一刻。到现在为止,我仍然无法解释或解决它,但我发现如果你没有设置myLocationEnable(true);地图将正确加载。这对我来说仍然是个问题,因为我需要查看我的位置,但我希望它会对你有所帮助。