TRY ANDROID DEV

Android アプリ開発のコーディングネタ。あとエンジニアとしての活動

古いプロジェクトをgradleバージョン上げて再ビルドしたらproguardでエラー

背景

古いプロジェクトをgradleバージョン上げて再ビルドしたらproguardでエラーが出たので対応方法をメモ。

修正した内容

gradle plugin 1.3 -> 3.2.1
compileSdkVersion 21 -> 26
buildToolVersion 23.0.0 -> 27.0.3

発生したエラー

14:53:18   Class       = [com/google/android/gms/iid/zzd]
14:53:18   Method      = [<init>(Landroid/content/Context;Ljava/lang/String;)V]
14:53:18   Exception   = [java.lang.IllegalArgumentException] (Stacks have different current sizes [1] and [0])
14:53:18 Warning: Exception while processing task java.io.IOException: java.lang.IllegalArgumentException: Stacks have different current sizes [1] and [0]
14:53:18 :app:transformClassesAndResourcesWithProguardForDevRelease FAILED
14:53:18 
14:53:18 FAILURE: Build failed with an exception.

対応内容

com.google.android.gms 以下のクラスが難読化できなかったようなので、 proguardの設定ファイルに以下の記載を追加して難読化を回避。

-keep class com.google.android.gms.** { *; }

結果

ビルドできた。

補足

-dontoptimize(最適化なし)でもビルドは通るらしい。 けどgoogleさんのライブラリをそもそも難読化処理する必要があるのか。。

(参考:proguard manual)