moshi: Moshi 1.9.2: Crash because Reflection in Codegen not handled in Proguard
Using 1.9.2 and the codegen, moshi uses reflection for classes with default parameters. This example with proguard enabled immediately crashes:
@JsonClass(generateAdapter = true)
data class Person(val name: String = "Peter", val age: Int = 42)
class MainActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
Moshi.Builder().build().adapter(Person::class.java).fromJson("{}")
}
}
Caused by: java.lang.NoSuchMethodException: parameter type is null
at java.lang.Class.getConstructor0(Class.java:2326)
at java.lang.Class.getDeclaredConstructor(Class.java:2170)
at com.example.moshitest.PersonJsonAdapter.a(:62)
at com.example.moshitest.PersonJsonAdapter.a(:19)
at b.a.a.u.a.a(:40)
at b.a.a.f.a(:43)
at com.example.moshitest.MainActivity.onCreate(:16)
at android.app.Activity.performCreate(Activity.java:7802)
at android.app.Activity.performCreate(Activity.java:7791)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 19 (6 by maintainers)
Any plans on a
1.9.3
or1.9.3-SNAPSHOT
release now that AS3.6.0
is stable?I think you can try building with the r8 new version 2.0.39
https://issuetracker.google.com/u/1/issues/147972078#comment9
AS 3.6.2 is out and fixes the problem!
https://androidstudio.googleblog.com/2020/03/android-studio-362-available.html:
Using snapshots is impractical: non reproducible builds unless you go extra miles to find the snapshot with the timestamp you want.
Building locally also requires extra config for all people affected, while it could be done once for everyone.
If you just want to try it, you can keep metadata annotations. Don’t recommend shipping it without checking the APK size implications first though.
It should be lower case: