Status Update
Comments
ch...@google.com <ch...@google.com>
ch...@google.com <ch...@google.com> #2
yq...@gmail.com <yq...@gmail.com> #3
Seems like this is already fixed in master as a side effect of
You'd want to add the snapshot repository to your repositories
block:
maven {
url "https://ci.android/com/builds/submitted/6080026/androidx_snapshot/latest/repository/"
}
then switch to androidx.fragment:fragment-ktx:1.3.0-SNAPSHOT
.
We'll look into cherry picking the changes into Fragment 1.2.0
ch...@google.com <ch...@google.com> #4
yq...@gmail.com <yq...@gmail.com> #5
Great, thanks for confirming.
While there isn't any specific changes needed for this issue (as the issue was already fixed before this bug was filed), I do want to explain what exactly is going to happen from a release process:
First, we'll be cherry picking in the changes needed into a Fragment 1.2.0-rc05 release (it was too late to hit rc04, which already went out earlier today). Namely, these two changes:
https://android-review.googlesource.com/1178750/ https://android-review.googlesource.com/1183079/ (this was the fix for the bug mentioned in , FWIW)comment#3
Secondly, we've added additional testing (in an unrelated, but fortuitously timed effort) specifically to cover this case to ensure this doesn't happen again in
ch...@google.com <ch...@google.com> #6
I'm curious why you need to limit the check to Build.VERSION.SDK_INT >= 17?
sg...@google.com <sg...@google.com> #8
-keepclassmembers,allowobfuscation class * extends androidx.savedstate.SavedStateRegistry.AutoRecreated {
<init>();
}
However, that is using the fully qualified and not the binary name of the AutoRecreated inner class.
I will create a CL, so that going forward using androidx.lifecycle:lifecycle-viewmodel-savedstate should not require additional keep rules.
Description
androidx.lifecycle: 2.2.0-alpha01
<Steps to reproduce>
1. Based on new empty activity project, add following ViewModel class.
```
class MainViewModel(
private val savedStateHandle: SavedStateHandle
): ViewModel()
```
2. Modify MainActivity as followings.
```
class MainActivity : AppCompatActivity() {
private lateinit var viewModel: MainViewModel
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
viewModel = ViewModelProviders.of(
this,
SavedStateVMFactory(this)
).get(MainViewModel::class.java)
}
}
```
3. Add a keep rule for MainViewModel.
-keep class com.example.savedstateviewmodelsample.MainViewModel { *; }
4. Enable r8 fullMode and run app, then the app crash with the following error.
com.example.savedstateviewmodelsample E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.savedstateviewmodelsample, PID: 15365
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.savedstateviewmodelsample/com.example.savedstateviewmodelsample.MainActivity}: java.lang.IllegalArgumentException: ClassOnRecreation must have default constructor in order to be automatically recreated
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.IllegalArgumentException: ClassOnRecreation must have default constructor in order to be automatically recreated
at androidx.savedstate.SavedStateRegistry.runOnNextRecreation(:177)
at androidx.lifecycle.AbstractSavedStateVMFactory.create(:71)
at androidx.lifecycle.ViewModelProvider.get(:162)
at androidx.lifecycle.ViewModelProvider.get(:130)
at com.example.savedstateviewmodelsample.MainActivity.onCreate(:20)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.NoSuchMethodException: <init> []
at java.lang.Class.getConstructor0(Class.java:2327)
at java.lang.Class.getDeclaredConstructor(Class.java:2166)
at androidx.savedstate.SavedStateRegistry.runOnNextRecreation(:175)
at androidx.lifecycle.AbstractSavedStateVMFactory.create(:71)
at androidx.lifecycle.ViewModelProvider.get(:162)
at androidx.lifecycle.ViewModelProvider.get(:130)
at com.example.savedstateviewmodelsample.MainActivity.onCreate(:20)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)