I'm trying to run application with Google Maps v2, but it throws me error and I have no idea why:
我试着用谷歌图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)
I have Google Play Services (Rev. 25) and Support v4 added to my project. Here is my code:
我有谷歌游戏服务(Rev. 25)和支持v4添加到我的项目。这是我的代码:
manifest:
清单:
<?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>
... and activity:
…和活动:
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) {
}
}
Have you any idea what may by wrong? If you want more info notify me please
你知道什么可能是错的吗?如果你想要更多的信息,请通知我。
2 个解决方案
#1
0
I think you have layout in both library and module with same name or inflating multiple xml layout with duplicate resource id.
我认为您在库和模块中都具有相同的名称,或者使用重复的资源id来填充多个xml布局。
Find map_attrs in play-services-lib and replace with this code:
在playservice -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>
#2
0
Updating your Google Repository to version 15 via the SDK Manager should resolve the issues and eliminate the needs for the workarounds. A project clean is required.
通过SDK管理器更新您的谷歌存储库到版本15,应该解决这些问题,并消除工作区的需求。需要一个干净的项目。
Android SDK
Android SDK
This is also mentioned in issue 7432.
在第7432号问题中也提到了这一点。
#1
0
I think you have layout in both library and module with same name or inflating multiple xml layout with duplicate resource id.
我认为您在库和模块中都具有相同的名称,或者使用重复的资源id来填充多个xml布局。
Find map_attrs in play-services-lib and replace with this code:
在playservice -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>
#2
0
Updating your Google Repository to version 15 via the SDK Manager should resolve the issues and eliminate the needs for the workarounds. A project clean is required.
通过SDK管理器更新您的谷歌存储库到版本15,应该解决这些问题,并消除工作区的需求。需要一个干净的项目。
Android SDK
Android SDK
This is also mentioned in issue 7432.
在第7432号问题中也提到了这一点。