My Android app uses Google Maps and compiles fine for both an SDK23 and SDK19 device. It runs fine on the SDK23 (LG G4) but generates this error SDK19 device (Samsung Galaxy 4) => java.lang.NoClassDefFoundError:com.google.android.gms.R$string
These are my dependencies: Android Studio Dependencies
My Manifest file:
<?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>
When I searched for this error I couldn't find a solution/answer why my app compiles/runs fine under SDK23, but generates this run-time error under SDK19.
Any help will be appreciated!
请尝试清理您的项目,然后从App Gradle中删除最后2个依赖项:play-services gcm a identities
Finally solved this problem.
I needed to downgraded the Manifest from compile 'com.google.android.gms:play-services:8.4.0' to the older version compile 'com.google.android.gms:play-services:8.3.0' to ensure compatibility with the device software on both devices.
The App now runs on the SDK19 and SDK23 phone. Thanks Mounir for pointing me in the right direction. Much appreciated!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.