[英]Android error: java.lang.NoClassDefFoundError: com.google.android.gms.R$string
[英]Android Error: SDK23 v SDK19 - java.lang.NoClassDefFoundError: com.google.android.gms.R$string
我的Android應用程序使用Google Maps,並且可以對SDK23和SDK19設備進行良好的編譯。 它可以在SDK23(LG G4)上正常運行,但會生成此錯誤SDK19設備(三星Galaxy 4)=> java.lang.NoClassDefFoundError:com.google.android.gms.R $ string
這些是我的依賴項: Android Studio依賴項
我的清單文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.volkerpetersen.sailingrace">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"></uses-feature>
<application
android:name=".GlobalParameters"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Holo.Light.DarkActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".start_timerActivity"
android:label="@string/title_activity_start_timer"
android:parentActivityName=".MainActivity"
android:windowSoftInputMode="stateHidden"
android:screenOrientation="portrait">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.volkerpetersen.sailingrace.MainActivity" />
</activity>
<activity
android:name=".start_raceActivity"
android:label="@string/title_activity_start_race"
android:parentActivityName=".MainActivity"
android:theme="@android:style/Theme.Holo.NoActionBar" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.volkerpetersen.sailingrace.MainActivity" />
</activity>
<activity
android:name=".start_mapActivity"
android:label="@string/title_activity_start_map"
android:theme="@android:style/Theme.Holo.Light.DarkActionBar">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.volkerpetersen.sailingrace.MainActivity" />
</activity>
<activity
android:name=".SailingRacePreferences"
android:screenOrientation="portrait"
android:label="@string/title_activity_setting"
android:noHistory="true"
android:parentActivityName=".MainActivity"
android:theme="@android:style/Theme.Holo.Light.DarkActionBar">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.volkerpetersen.sailingrace.MainActivity" />
</activity>
<receiver android:name=".SailTimerAPI"></receiver>
<!--
The API key for Google Maps-based APIs is defined as a string resource using the <meta-data> tag
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyDzCAa-hibdRJ-NdOnIRK-IG5uN2U3kv9c" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<!-- original code replaced with above
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
-->
</application>
當我搜索此錯誤時,我找不到解決方案/答案,為什么我的應用程序可以在SDK23下編譯/正常運行,但是會在SDK19下生成此運行時錯誤。
任何幫助將不勝感激!
請嘗試清理您的項目,然后從App Gradle中刪除最后2個依賴項:play-services gcm a identities
終於解決了這個問題。
我需要將清單從編譯'com.google.android.gms:play-services:8.4.0'降級到較早版本的編譯'com.google.android.gms:play-services:8.3.0'以確保兼容性與兩個設備上的設備軟件一起使用。
該應用程序現在可以在SDK19和SDK23手機上運行。 感謝Mounir為我指出正確的方向。 非常感激!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.