java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable in android
See the answer here:
Google Maps Android API v2 - Sample Code crashes
While the question lists a different exception, the answer specifically mentions your exact problem.
Specifically, it's important to import google-play-services_lib
as a project:
Select File > Import > Android > Existing Android Code Into Workspace
and click Next.
Select Browse..., enter [android-sdk-folder]/extras/google/google_play_services/libproject/google-play-services_lib
, and click Finish.
(See https://developers.google.com/maps/documentation/android/intro under "Sample Code")
Then follow the instructions from the linked answer:
- Import the actual source for the "google-play-services_lib" project and link it as an >Android library.
- Do this through Project -> Properties -> Android -> Library, Add -> google-play-services_lib (you can right click on your project and choose Properties, then select Android).
- Do not add it as a dependent Project through the "Java Build Path" for your project, that didn't work for me.
java.lang.noclassdeffounderror: com.google.android.gms.R$styleable
What you have to do is include a Google Play Services library to your project. Google has very good instructions here:
- http://developer.android.com/google/play-services/setup.html
Also, there is a quick start which I found very useful while trying to get Google Maps v2 to work.
- https://docs.google.com/document/pub?id=19nQzvKP-CVLd7_VrpwnHfl-AE9fjbJySowONZZtNHzw
java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable (PROJECT ADDED!!)
It seems everything is fine in your code, Do following:
clean and build and
then first uninstall and then install the app.
And see if it works.
google GCM android crashes ( java.lang.NoClassDefFoundError: com.google.android.gms.R$string )
I had same problem.You are probably facing it on devices prior 5.0 version.The reason why this happen is that version prior to android 5.0 use Dalvik and by default, Dalvik limits apps to a single classes.dex bytecode file per APK.The solution is to use multidex support.
Include in your build.gradle dependencies this:
compile 'com.android.support:multidex:1.0.0'
public class MyApp extends MultiDexApplication {
@Override
public void onCreate() {
super.onCreate();
}
}
than in your Manifest add MultiDexApplication class
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.multidex.myapplication">
<application
...
android:name=".MyApp">
...
</application>
</manifest>
Note: If you already have your application class just extend it with MultiDexApplication class
java.lang.NoClassDefFoundError: com.google.android.gms.R$string
I look into my code many time, and I look at each library I am using and I was able to fix it.
First, like @BrainMiz said mutiDexEnabled should set it off. I just comment it instead of set it as false.
defaultConfig {
applicationId "com.package.name"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
//multiDexEnabled true
}
Second, it is the dependencies.
Since I don't have any jar in my libs folder I remove
compile fileTree(dir: 'libs', include: ['*.jar'])
also remove all not being used gms library, only add the one that being used. I have to give some credits to @Radix because I did found some error in my code regarding to the code that where I check if the device has google play store.
dependencies {
//compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'org.twitter4j:twitter4j-core:4.0.2'
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:appcompat-v7:23.1.1'
//compile 'com.google.android.gms:play-services:8.4.0'
compile 'com.android.support:design:23.1.1'
compile 'com.squareup.okhttp:okhttp:2.5.0'
//compile 'com.android.support:support-v4:23.1.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.isseiaoki:simplecropview:1.0.8'
compile 'com.qozix:tileview:2.0.7'
compile 'com.android.support:cardview-v7:23.1.1'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
}
android : java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
1. Try to remove this line:
class="com.google.android.gms.maps.SupportMapFragment"
from the fragment in the XML file, it shouldn't be there.
2. Change this permission:
<permission
android:name="android.os.Bundle.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
to this:
<permission
android:name="com.example.mapdemo.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
if com.example.mapdemo
is your project package.
if not change it to your project package in this permission and this:
<uses-permission android:name="com.example.mapdemo.permission.MAPS_RECEIVE" />
NoClassDefFoundError: com.google.android.gms.R$styleable
I see some potential issues:
- You might have imported
com.google.android.gms.R
somewhere in your
code and not the one that belongs to your app. - The
<permission>
on your manifest is obsolete; not needed anymore. <uses-permission android:name="ua.khuta.ALHANAi.permission.MAPS_RECEIVE"/>
is obsoleteYou are missing this inside your
<application>
:<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />You have declared an
Activity
(MyActivity
) as aMAIN
andLAUNCHER
twice in yourAndroidManifest
; remove one of the<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>
Related Topics
Android Mapactivity:Couldn't Get Connection Factory Client
How to Make My Own Custom Dialer in an Android Phone
Is Proguard.Cfg Needed for Library Projects
Occured an Internal_Error When Requestemail from Googlesigninoptions Android
Getlastknownlocation() Returns Null
How to Give Everyone Access to Firestore Database, But Only via App
How to Add Crosswalk Webview in My Own Android Library Module
How to Shutdown an Android Mobile Programmatically
Can't Update Android Studio - Only Download
Action Buttons Doesn't Show Up on Action Bar
Move Up Text View Only When Virtual Keyboard Open on Android
How to Implement Autocompletetextview with Listview
Outlook - Read Another User's Calendar
How to Get Documents in an Android Directory That Phonegap Will See
Java.Lang.Numberformatexception: Invalid Int: "" in Android
Android Xml Rounded Clipped Corners
If I Call Getmeasuredwidth() or Getwidth() for Layout in Onresume They Return 0