LoginSignup
9
1

More than 5 years have passed since last update.

RetrofitのGoogle Protocol Buffer Converterを使っていた場合のProGuard設定メモ

Last updated at Posted at 2018-06-01

RetrofitとProtocol Buffersを連携させる場合、下記のConverterを使うケースが多いのかと思います。

Google Protocol Buffer Converter
https://github.com/square/retrofit/tree/master/retrofit-converters/protobuf

今回、Retrofit + Google Protocol Buffer Converter なAndroidプロジェクトで、ProGuardを設定しようとしたらエラーでハマったのでメモとして投稿します。

エラー内容

特にProGuardの設定なく実行させてみると、下記のエラーが吐かれました。

Caused by: java.lang.IllegalArgumentException: Found a protobuf message but jp.co.b.a.a.g$a had no parser() method or PARSER field.

parser() というメソッドが難読化されて別名になったためと思われます。

コードを追うと、
https://github.com/square/retrofit/blob/master/retrofit-converters/protobuf/src/main/java/retrofit2/converter/protobuf/ProtoConverterFactory.java#L67
ここらへんでリフレクションを使って parser() というメソッドを使うようになっているみたいです。

対策

-keepclassmembers class your.generated.class.** {
    public static ** parser();
}

.protoファイルから自動生成されたクラスに対して、 parser() というメソッドを難読化から除外することで、エラーが吐かれることなく実行できるようになりました。:grinning:

9
1
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
9
1