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

不羁岁月 提交于 2019-11-27 22:14:14
Laurent Meyer

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.

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.

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

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' }

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!