我收到此错误
NoClassDefFoundError: com.google.android.gms.R$styleable
我阅读了很多教程,但它对我没有帮助。
我的xml文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
我的活动是:
public class FlatOnMap extends Activity {
private GoogleMap googleMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map_activity);
try {
initilizeMap();
} catch (Exception e) {
e.printStackTrace();
}
}
private void initilizeMap() {
if (googleMap == null) {
googleMap = ((MapFragment) getFragmentManager().findFragmentById(
R.id.map)).getMap();
if (googleMap == null) {
Toast.makeText(getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT)
.show();
}
}
}
@Override
protected void onResume() {
super.onResume();
initilizeMap();
}
}
我的清单是:
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="17"/>
<permission
android:name="ua.khuta.ALHANAi.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<uses-permission android:name="ua.khuta.ALHANAi.permission.MAPS_RECEIVE"/>
<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"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.CALL_PHONE"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
>
<activity android:name=".MyActivity"
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat.Light.DarkActionBar"
android:screenOrientation="portrait"
>
<meta-data
android:name="android.app.default_searchable"
android:value=".SearchResultsActivity"/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".SearchResultsActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Light.DarkActionBar"
>
<intent-filter>
<action android:name="android.intent.action.SEARCH"/>
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable"/>
</activity>
<activity android:name=".FlatInfo"/>
<activity android:name=".FlatOnMap"/>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="myApiKey"/>
</application>
</manifest>
我的解决方案: 我已经改变了我的google play服务,并再次导入它,但我没有添加.jar文件。 1.导入模块 - &gt; google_play_servises_lib项目 2. +添加库 - &gt; google_play_servises_lib
答案 0 :(得分:1)
我看到了一些潜在的问题:
com.google.android.gms.R
代码,而不是属于您的应用的代码。<permission>
已过时;不再需要了。<uses-permission android:name="ua.khuta.ALHANAi.permission.MAPS_RECEIVE"/>
已过时您在<application>
:
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
您已在Activity
中两次宣布MyActivity
(MAIN
)为LAUNCHER
和AndroidManifest
;删除其中一个<intent-filter>...</intent-filter>
:
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>