14

Some users of my app are experiencing this crash, it appears to possibly be related to Samsung devices. Has anyone else experienced this issue and found a solution?

java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$layout
       at android.support.v7.app.ActionBarActivityDelegateBase.ensureSubDecor(ActionBarActivityDelegateBase.java:297)
       at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:225)
       at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
       at com.afollestad.impression.ui.MainActivity.onCreate(MainActivity.java:160)
       at android.app.Activity.performCreate(Activity.java:5451)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2359)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2453)
       at android.app.ActivityThread.access$900(ActivityThread.java:173)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:136)
       at android.app.ActivityThread.main(ActivityThread.java:5579)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:515)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
       at dalvik.system.NativeStart.main(NativeStart.java)

Line 160 sets the Activity's content view. The content view is this:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.afollestad.lessen.ui.MainActivity"
    android:fitsSystemWindows="true">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:minHeight="?attr/actionBarSize"
            android:background="?colorPrimary"
            app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:popupTheme="?popup_theme" />

        <FrameLayout
            android:id="@+id/content_frame"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </LinearLayout>

    <FrameLayout
        android:layout_width="@dimen/navigation_drawer_width"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        android:layout_gravity="start">

        <fragment
            android:id="@+id/navigation_drawer"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:name="com.afollestad.impression.fragments.NavDrawerFragment"
            tools:layout="@layout/fragment_navdrawer"
            android:tag="NAV_DRAWER" />

    </FrameLayout>

</android.support.v4.widget.DrawerLayout>

The fragment is a simple list fragment.

5
  • 1
    Can you show code? basically, point out what's MainActivity.java:160? Dec 23, 2014 at 5:27
  • Have you used obfuscation? (Proguard) Dec 23, 2014 at 5:32
  • @MagicalPhoenixϡ I haven't, no
    – afollestad
    Dec 23, 2014 at 5:35
  • Ohk... just found this thread. :/. and this solution, but that works for issue due to proguard shrink mostly :/ Dec 23, 2014 at 5:36
  • @MagicalPhoenixϡ thanks, that lead me in the right direction
    – afollestad
    Dec 24, 2014 at 19:35

4 Answers 4

24

I know that issue was solved but if you arrive on this thread, it could be that it doesn't solve your problem in one particular combination:

  • All works on 5.0 devices
  • It doesn't work on 4.x
  • You think you enable MultiDex
  • Proguard doesn't seem to be a problem

It happened to me and I searched for 3 hours. I hope it'll help some. To enable MultiDex on 4.x devices, it is not enough to modify the build: you have to subclass the Application class. Just follow that and that

Hope it helps.

0
8

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.

2
  • 1
    ,can you please explain me the thing like why this type of issue occurs? and why need to put this into the proguard file to get it resolved. I just need explanation. Thanks Jun 22, 2015 at 6:22
  • THANK YOU! Ive been looking for a solution to this problem for an hour and this is the easiest way to implement proguard without having to include all of my libraries.
    – mober13
    Aug 17, 2015 at 15:05
3

If you use multidex in your application, extend your Application class from MultiDexApplication

1

if you're using api compat support-v7, any libraries whose reference to it should be marked exclude module: 'support-v4'

for example:

compile('com.android.support:cardview-v7:22.2.0') { exclude module: 'support-v4' }

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.