Android Studio Flamingo 🐦 で Retrofit が「r8 java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType」

はい、でました。


r8 java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType

開発環境が変化した時におこる minify / proguard まわりのエラーは面倒ですね😭

 

🐦 R8 full mode がデフォルトに

そのままで「R8 full mode」だそうです。

R8 full mode by default

The last behavior change: R8 is now in full mode by default, enabling app size reductions and performance improvement. You shouldn’t need to update anything for this change, but if you encounter build or runtime failures you should double-check that your keep rules are configured correctly. For guidance on how to configure the keep rules, see Shrink, obfuscate, and optimize your app.

👉 Shrink, obfuscate, and optimize your app  |  Android Studio  |  Android Developers hatena-bookmark
👉 5 ways to prepare your app build for Android Studio Flamingo release | by Boris Farber | Android Developers | Apr, 2023 | Medium hatena-bookmark

R8 がより強く広く効いて不具合を起こす、ってことか。

 

🐦 解決方法

以下を proguard-rules.pro に追加します。Retrofit 公式に載ってました。


# Keep generic signature of Call, Response (R8 full mode strips signatures from non-kept items). 
-keep,allowobfuscation,allowshrinking interface retrofit2.Call 
-keep,allowobfuscation,allowshrinking class retrofit2.Response 
  
# With R8 full mode generic signatures are stripped for classes that are not 
# kept. Suspend functions are wrapped in continuations where the type argument 
# is used. 
-keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation

👉 After enable R8 full mode getting ParameterizedType error · Issue #3751 · square/retrofit hatena-bookmark

まずは、ひとつ解決できました。

いろいろありそうです、Flamingo。


関連ワード:  AndroidAndroidStudioGoogleGradleKotlinツール評判速報開発