我尝试使用Google Maps v2运行应用程序,但它会引发错误,我不明白为什么:
java.lang.NoSuchFieldError: No static field MapAttrs_liteMode of type I in class Lcom/google/android/gms/R$styleable; or its superclasses (declaration of 'com.google.android.gms.R$styleable' appears in /data/app/com.example.OKM-1/base.apk)
at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2169)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:300)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:381)
at android.app.Activity.setContentView(Activity.java:2144)
at com.example.OKM.presentation.view.MainMapActivity.onCreate(MainMapActivity.java:21)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2405)
at android.app.ActivityThread.access$800(ActivityThread.java:149)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1324)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:211)
at android.app.ActivityThread.main(ActivityThread.java:5317)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1016)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
我已将Google Play服务(第25版)和支持v4添加到我的项目中。 这是我的代码:
清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.OKM">
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="21"/>
<permission
android:name="com.example.OKM.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.OKM.permission.MAPS_RECEIVE" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Required to show current location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Required OpenGL ES 2.0. for Maps V2 -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application android:icon="@drawable/icon"
android:label="@string/app_name"
android:allowBackup="true">
<activity android:name=".presentation.view.MainMapActivity">
<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.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="@string/mapsKey" />
</application>
</manifest>
......和活动:
package com.example.OKM.presentation.view;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.example.OKM.R;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.example.OKM.presentation.presenter.MainMapPresenter;
public class MainMapActivity extends FragmentActivity implements OnMapReadyCallback{
private MainMapPresenter mainMapPresenter;
private SupportMapFragment map;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_map_activity);
if(map == null){
map = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
map.getMapAsync(this);
}
mainMapPresenter = new MainMapPresenter(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
}
}
你知道可能有什么不对吗?如果您想了解更多信息,请通知我
答案 0 :(得分:0)
我认为您在库和模块中都有相同名称或布局的布局 使用重复的资源ID扩充多个xml布局。
在play-services-lib中查找map_attrs并替换为此代码:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="MapAttrs">
<attr name="mapType" format="enum">
<enum name="none" value="0"/>
<enum name="normal" value="1"/>
<enum name="satellite" value="2"/>
<enum name="terrain" value="3"/>
<enum name="hybrid" value="4"/>
</attr>
<attr name="cameraBearing" format="float"/>
<attr name="cameraTargetLat" format="float"/>
<attr name="cameraTargetLng" format="float"/>
<attr name="cameraTilt" format="float"/>
<attr name="cameraZoom" format="float"/>
<attr name="liteMode" format="boolean"/>
<attr name="uiCompass" format="boolean"/>
<attr name="uiRotateGestures" format="boolean"/>
<attr name="uiScrollGestures" format="boolean"/>
<attr name="uiTiltGestures" format="boolean"/>
<attr name="uiZoomControls" format="boolean"/>
<attr name="uiZoomGestures" format="boolean"/>
<attr name="useViewLifecycle" format="boolean"/>
<attr name="zOrderOnTop" format="boolean"/>
<attr name="uiMapToolbar" format="boolean"/>
<attr name="ambientEnabled" format="boolean"/>
</declare-styleable>
</resources>
答案 1 :(得分:0)