Android Studio Flamingo 2022.2.1 Caused by java.lang.RuntimeException: Missing type parameter
如果你 Android Studio 升級到 Flamingo 2022.2.1 版本,請注意以下內容: 升級後的 Android Studio 使用 Gradle 8.0.0。這個版本的 Gradle 引入了 R8 完整模式(R8 full mode),該模式預設是開啟的。R8 是一個用於縮減、模糊處理和最佳化應用程式的工具。這表示你的應用程式在編譯時會受到更強大的最佳化處理。 你應該特別注意您的應用程式是否會受到這些變化的影響。一個普遍受到影響的第三方 lib 套件是 GSON。GSON 是一個常用的 JSON 序列化/反序列化庫,它可能會出現以下相關錯誤,例如: Caused by java.lang.RuntimeException: Missing type parameter 或是因為 SerializedName 導致在獲取資料欄位時呈現 null,目前 KT 加入 Google 官方提供新的 Proguard 規則,已確定 Gson 在混淆時能正常工作,避免出現相關問題。完整設定請參考下方資訊連結內容。 最後,鼓勵大家在遇到問題時彼此分享解決方案,透過共享經驗,省去踩坑的除錯時間,歡迎大家留言,討論您遇到的問題以及您是如何解決的,一起改善開發流程。 GSON ##---------------Begin: proguard configuration for Gson ---------- # Gson uses generic type information stored in a class file when working with fields. Proguard # removes such information by default, so configure it to keep all of it. -keepattributes Signature # For using GSON @Expose annotation -keepattributes *Annotation* # Gson specific classes -dontwarn sun.misc.** #-keep class com.google.gson.stream.** { *; } # Application classes that wi...