Java.Lang.Noclassdeffounderror: Android.Support.V7.Appcompat.R$Styleable

FATAL EXCEPTION: java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$layout

I faced the same issue and fixed it.
It is issue with Dex limit. Because the dex limit is reached, it creates two dex files. Lollipop knows how to read, pre-Lollipop has no idea unless you specify it in the Application class.

Please make sure following is in place:

in build.gradle

dependencies {
compile 'com.android.support:multidex:1.0.0'
}
defaultConfig {
multiDexEnabled true
}

IMPORTANT to support pre-Lollipop:

In Manifest, under the application tag,

<application
...
android:name="android.support.multidex.MultiDexApplication">
...
</application>

Or if you have used your own Application class,
make your Application override attachBaseContext starting with

 import android.support.multidex.MultiDexApplication;
import android.support.multidex.MultiDex;

public class MyApplication extends MultiDexApplication {
// ......

@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}

Reference: https://developer.android.com/tools/building/multidex.html#mdex-gradle

java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$styleable

If you are using eclipse than just import the v7 compat library project into your work space and add it as a library to your project. Else if you are doing it from terminal than what you can do is put android-support-v7-appcompat library project (which you can find in sdk\extras\android\support\v7\appcompat) in the same directory where is your project and add this line to your project.properties file.

android.library.reference.1=../android-support-v7-appcompat

Do not forget to add both jar files v4, v7 to your project as well.

java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/appcompat/R$drawable;

Changing compile to implementation and changing 27.0.1 to 27.1.0 in my build.gradle seemed to work for me. The error and the solution seem a bit unrelated still, but it works:

Changed:

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:27.0.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:design:27.0.1'
compile "com.android.support:support-v4:27.0.1"
compile "com.android.support:support-v13:27.0.1"
compile "com.android.support:cardview-v7:27.0.1"
...
}

To:

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:27.1.0'
implementation "com.android.support:support-v4:27.1.0"
implementation "com.android.support:support-v13:27.1.0"
implementation "com.android.support:cardview-v7:27.1.0"
...
}

Exception java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$styleable

Import the support.v7.appcompat as a library project in your workspace and attach it with your project.

Try this,it will work for sure.
if you still face any issue, do comment.

NoClassDefFoundError: Failed resolution of: Landroid/support/v7/appcompat/R$styleable

You are getting that error because of the following reasons:

In your Gradle build file your app is targeting and compiling with the beta version of Android that is still in development with:

compileSdkVersion 'android-L'
buildToolsVersion '20'

as well as

minSdkVersion 20
targetSdkVersion 20

First thing to note is that this app will not run correctly (at this time) on any device without android-L flashed to it.

The real crux of your issue is in DisplayMessageActivity, it extends via inheritance
[ActionBarActivity]:(https://developer.android.com/reference/android/support/v7/app/ActionBarActivity.html) this is one of the support library classes for AppCompat.

To fix this, change your min SDK to 10 (or 14 which is ice cream sandwich), your max SDK to 19 (Kit Kat) and un-comment the appcompat-v7 library in your dependencies.

As a side note, when you declare widgets in their respective activities/fragments it's usually good practice to have their scope be outside of any methods:

EditText editText;
Button sendMessageButton;

// Then in your onCreate() method
editText = (EditText) findViewById(R.id.editText);
sendMessageButton = (Button) findViewById(R.id.sendMessageButton);

This helps reduce memory re-allocation and make your code a little more readable. Sometimes you may have to bend the rules a bit but this is the common practice.

Crash: java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$layout

I fixed the issue by using Proguard with the following config:

-keep class !android.support.v7.internal.view.menu.**,** {*;}
-dontwarn
-ignorewarnings
-dontshrink

To enable Proguard with newer versions of Gradle (in Android Studio):

android {

...

buildTypes {
debug {
...
}
release {
...
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

proguard-rules.pro is where the properties at the top go.



Related Topics



Leave a reply



Submit