LoginSignup
16
12

More than 5 years have passed since last update.

Proguard有効でビルドを行ったアプリを起動するとIllegalStateException: You need to use a Theme.AppCompat theme...

Last updated at Posted at 2015-10-22

TL;DR

  • AppCompat v23.1.0でのバグです
  • Proguardの設定にページの下にあるものを付け足してください

症状

Proguardを有効にしたアプリを起動時に

ComponentInfo{com.example.test/com.example.test.activity.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

みたいなエラーが出て起動できなくなってしまいました。

エラーメッセージを確認

You need to use a Theme.AppCompat theme (or descendant) with this activity. (このActivityにはTheme.AppCompatかそれを継承したものを使用してね)と書かれていたので、AndroidManifest.xmlstyles.xmlを確認しました。
MainAcitivtyAppCompatActivityを継承しています。

<application
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"
    >
    <activity
        android:name=".activity.MainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.FullScreen"
        >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
...
</application>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
</style>

<style name="AppTheme.FullScreen" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
</style>

きちんとTheme.AppCompatを継承したものを使用しています。
そもそも、前におこなったリリースビルドは問題なく起動していますし、このファイルには少なくとも前回リリースビルドを作成した時から手を加えていません。

原因

調べているとAOSPのIssueTrackerにある投稿を見つけました

Bug: appcompat-v7:23.1.0 has dynamic themes issues with proguard
https://code.google.com/p/android/issues/detail?id=190237&

そういえば、ちょうどAppCompatのライブラリを23.1.0にあげていました。

解決方法

上のTrackerにある通り、以下をproguard-rules.proに追加してください

proguard-rules.pro
-keep class com.google.android.gms.** { *; }
-keep public class com.google.android.gms.**
-dontwarn com.google.android.gms.**
-keep class android.support.v7.** { *; }
-keep interface android.support.v7.** { *; }
16
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
12