1

After upgrading from appcompat-v7 version 20 to 21.0.3, my Android app started crashing on launch on a Samsung Galaxy Nexus running Android 4.3. (It runs fine on a Galaxy S5 with Android 5.0).

Here's the top of my stacktrace:

java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$attr
        at android.support.v7.app.ActionBarActivityDelegateBase.ensureSubDecor(ActionBarActivityDelegateBase.java:263)
        at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:225)
        at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
        at com.xxx.ui.LoginChoiceActivity.onCreate(LoginChoiceActivity.java:39)

I believe this problem is reported and discussed to exhaustion here. Several commenters on that issue managed to work around it with various -keep incantations in their proguard config files. So I tried the same thing and managed to get rid of the crashes, but I can't understand what caused the fix.

I'm using Android Studio 1.1.0. I added the following to build.gradle:

proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
minifyEnabled true

And this is my proguard-rules.pro file:

# Works regardless of whether this is commented out or not.
#-keep class ** {*;}

# We know these reference classes that we don't have. It's ok.
-dontwarn com.flurry.**,com.millennialmedia.**

-dontoptimize
-dontshrink
-dontobfuscate

I'm not happy with a bugfix/workaround that I don't understand, so does anyone have a clue what ProGuard is doing for me?

Tore Olsen
  • 2,153
  • 2
  • 22
  • 35

1 Answers1

0

add this lines in your proguard-rules.pro file to keep supportv7 from progurd

-keep class android.support.v7.** { *; }
-keep interface android.support.v7.** { *; }
-dontwarn android.support.**

and read this issue

Hamid Zandi
  • 2,714
  • 24
  • 32