Verified
Status Update
Comments
bi...@google.com <bi...@google.com>
jo...@gmail.com <jo...@gmail.com> #2
Also we need to add following for activities and fragments using VIewModel with to start:
## Android architecture components: ViewModel
-keepclassmembers class * extends android.arch.lifecycle.ViewModel {
<init>(...);
}
## Android architecture components: ViewModel
-keepclassmembers class * extends android.arch.lifecycle.ViewModel {
<init>(...);
}
jo...@gmail.com <jo...@gmail.com> #3
Update:
Managed to gethttps://github.com/googlesamples/android-architecture-components/tree/master/BasicSample working with the following set of rules:
## Android architecture components: Lifecycle
# generated GenericLifecycleObserver and it's empty constructor is considered to be unused by proguard
-keepclasseswithmembers class * implements android.arch.lifecycle.GenericLifecycleObserver {
<init>(...);
}
# keep Lifecycle State and Event enums with fields
-keepclassmembers class android.arch.lifecycle.Lifecycle$* { *; }
# keep methods annotated with @OnLifecycleEvent even if they seem to be unused
# (Mostly for LiveData.LifecycleBoundObserver.onStateChange(), but who knows)
-keepclassmembers class * {
@android.arch.lifecycle.OnLifecycleEvent *;
}
# ViewModel's empty constructor is considered to be unused by proguard
-keepclassmembers class * extends android.arch.lifecycle.ViewModel {
<init>(...);
}
Not quite sure if it's the final version (I think we can prettify it a bit), but everything seems to work fine.
Managed to get
## Android architecture components: Lifecycle
# generated GenericLifecycleObserver and it's empty constructor is considered to be unused by proguard
-keepclasseswithmembers class * implements android.arch.lifecycle.GenericLifecycleObserver {
<init>(...);
}
# keep Lifecycle State and Event enums with fields
-keepclassmembers class android.arch.lifecycle.Lifecycle$* { *; }
# keep methods annotated with @OnLifecycleEvent even if they seem to be unused
# (Mostly for LiveData.LifecycleBoundObserver.onStateChange(), but who knows)
-keepclassmembers class * {
@android.arch.lifecycle.OnLifecycleEvent *;
}
# ViewModel's empty constructor is considered to be unused by proguard
-keepclassmembers class * extends android.arch.lifecycle.ViewModel {
<init>(...);
}
Not quite sure if it's the final version (I think we can prettify it a bit), but everything seems to work fine.
jo...@gmail.com <jo...@gmail.com> #4
Update:
https://github.com/googlesamples/android-architecture-components/tree/master/GithubBrowserSample also works fine with the same set of rules, added Okio, okHttp3, GSON and Dagger2 for Android rules
Please confirm it works fine for everyone.
I have a pull request for googlesamples/android-architecture-components ready, waiting for your feedback on this issue.
Please confirm it works fine for everyone.
I have a pull request for googlesamples/android-architecture-components ready, waiting for your feedback on this issue.
ar...@google.com <ar...@google.com> #5
It's working fine for me, thanks a lot!
ar...@google.com <ar...@google.com> #6
Update:
slightly modified the config I proivided:
## Android architecture components: Lifecycle
# LifecycleObserver's empty constructor is considered to be unused by proguard
-keepclassmembers class * implements android.arch.lifecycle.LifecycleObserver {
<init>(...);
}
# ViewModel's empty constructor is considered to be unused by proguard
-keepclassmembers class * extends android.arch.lifecycle.ViewModel {
<init>(...);
}
# keep Lifecycle State and Event enums values
-keepclassmembers class android.arch.lifecycle.Lifecycle$State { *; }
-keepclassmembers class android.arch.lifecycle.Lifecycle$Event { *; }
# keep methods annotated with @OnLifecycleEvent even if they seem to be unused
# (Mostly for LiveData.LifecycleBoundObserver.onStateChange(), but who knows)
-keepclassmembers class * {
@android.arch.lifecycle.OnLifecycleEvent *;
}
It turns out that generated GenericLifecycleObserver is unreachable after obfuscation because it is created using reflection by adding "_LifecycleAdapter" to LifecycleObserver class name (which is definitely changed). This leads to Lifecycle using fallback ReflectiveGenericLifecycleObserver (a little slower because of looking for your callback methods with reflection in order to call them). So we might just as well lose GenericLifecycleObserver generated by apt.
Another option is to keep both LifecycleObserver and generated GenericLifecycleObserver to improve performance. In that case replace
-keepclassmembers class * implements android.arch.lifecycle.LifecycleObserver {
<init>(...);
}
with
-keep class * implements android.arch.lifecycle.LifecycleObserver {
<init>(...);
}
slightly modified the config I proivided:
## Android architecture components: Lifecycle
# LifecycleObserver's empty constructor is considered to be unused by proguard
-keepclassmembers class * implements android.arch.lifecycle.LifecycleObserver {
<init>(...);
}
# ViewModel's empty constructor is considered to be unused by proguard
-keepclassmembers class * extends android.arch.lifecycle.ViewModel {
<init>(...);
}
# keep Lifecycle State and Event enums values
-keepclassmembers class android.arch.lifecycle.Lifecycle$State { *; }
-keepclassmembers class android.arch.lifecycle.Lifecycle$Event { *; }
# keep methods annotated with @OnLifecycleEvent even if they seem to be unused
# (Mostly for LiveData.LifecycleBoundObserver.onStateChange(), but who knows)
-keepclassmembers class * {
@android.arch.lifecycle.OnLifecycleEvent *;
}
It turns out that generated GenericLifecycleObserver is unreachable after obfuscation because it is created using reflection by adding "_LifecycleAdapter" to LifecycleObserver class name (which is definitely changed). This leads to Lifecycle using fallback ReflectiveGenericLifecycleObserver (a little slower because of looking for your callback methods with reflection in order to call them). So we might just as well lose GenericLifecycleObserver generated by apt.
Another option is to keep both LifecycleObserver and generated GenericLifecycleObserver to improve performance. In that case replace
-keepclassmembers class * implements android.arch.lifecycle.LifecycleObserver {
<init>(...);
}
with
-keep class * implements android.arch.lifecycle.LifecycleObserver {
<init>(...);
}
jo...@gmail.com <jo...@gmail.com> #7
This is still broken for me in alpha 2. I still need to specify ProGuard rules myself.
jo...@gmail.com <jo...@gmail.com> #8
Looks like I missed part in our .gradle file.
jo...@gmail.com <jo...@gmail.com> #9
Can you verify which version of architecture components was this fixed in? We are using alpha3, and we still need to provide our own proguard rules because otherwise the lifecycle callbacks get stripped.
bi...@google.com <bi...@google.com> #10
alpha-4
bi...@google.com <bi...@google.com> #11
I still have an issue with these proguard rules inserted.
java.lang.NoSuchMethodError: No virtual method setRetainInstance(Z)V in class Landroid/arch/lifecycle/HolderFragment; or its super classes (declaration of 'android.arch.lifecycle.HolderFragment' appears in /data/app/package_name/base.apk)
java.lang.NoSuchMethodError: No virtual method setRetainInstance(Z)V in class Landroid/arch/lifecycle/HolderFragment; or its super classes (declaration of 'android.arch.lifecycle.HolderFragment' appears in /data/app/package_name/base.apk)
bi...@google.com <bi...@google.com> #12
still present in alpha9
ar...@google.com <ar...@google.com> #13
Unfortunately still not fixed up until today, not sure why it has been marked as fixed.
jo...@gmail.com <jo...@gmail.com> #14
still present in alpha 9
bi...@google.com <bi...@google.com> #15
With alpha9 I am getting a lot of this when proguarding:
Warning: android.arch.lifecycle.Transformations: can't find referenced class android.arch.core.util.Function
Warning: android.arch.lifecycle.Transformations: can't find referenced class android.arch.core.util.Function
jo...@gmail.com <jo...@gmail.com> #16
Addendum to comment #15 :
Happens when using alpha9 + support 26.1.0 but not with alpha9 + support 26.0.0
Happens when using alpha9 + support 26.1.0 but not with alpha9 + support 26.0.0
bi...@google.com <bi...@google.com> #17
Yep you have to use alpha9-1 + support lib 26.1.0, or alpha9 + support 26.0.0
This class was moved in that release.
This class was moved in that release.
jo...@gmail.com <jo...@gmail.com> #18
To others: could you please share what is broken for you?
bi...@google.com <bi...@google.com> #19
So with minifyEnabled set to true and with 26.1.0 support library and alpha9-1 android arch, this is the error I still get when I create a release build apk.
java.lang.NoSuchMethodError: No virtual method setRetainInstance(Z)V in class Landroid/arch/lifecycle/HolderFragment; or its super classes (declaration of 'android.arch.lifecycle.HolderFragment' appears in /data/app/package.name/base.apk )
java.lang.NoSuchMethodError: No virtual method setRetainInstance(Z)V in class Landroid/arch/lifecycle/HolderFragment; or its super classes (declaration of 'android.arch.lifecycle.HolderFragment' appears in /data/app/
jo...@gmail.com <jo...@gmail.com> #20
seems like a minify tool issue.
bi...@google.com <bi...@google.com> #21
Hello from the tooling side :) Do we have repro steps for this? Can someone attach a full stack trace for this NoSuchMethodError? Is setRetainInstance called reflectively?
jo...@gmail.com <jo...@gmail.com> #22
minifyEnabled set to true and with 26.1.0 support library and alpha9-1 android arch. After building a release apk, installing it, and launching it, it crashes with the following stacktrace.
Stacktrace:
09-29 13:52:13.205 30730 30730 E AndroidRuntime: java.lang.NoSuchMethodError: No virtual method setRetainInstance(Z)V in class Landroid/arch/lifecycle/HolderFragment; or its super classes (declaration of 'android.arch.lifecycle.HolderFragment' appears in /data/app/package_name==/base.apk)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.arch.lifecycle.HolderFragment.<init>(HolderFragment.java:52)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.arch.lifecycle.HolderFragment$HolderFragmentManager.createHolderFragment(HolderFragment.java:148)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.arch.lifecycle.HolderFragment$HolderFragmentManager.holderFragmentFor(HolderFragment.java:186)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.arch.lifecycle.HolderFragment.holderFragmentFor(HolderFragment.java:89)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.arch.lifecycle.ViewModelStores.of(ViewModelStores.java:53)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.arch.lifecycle.ViewModelProviders.of(ViewModelProviders.java:90)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at com.test.fragments.MyFragment.setUpGui(MyFragment.java:170)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at com.test.fragments.MyFragment.onActivityCreated(MyFragment.java:140)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.support.v4.app.Fragment.performActivityCreated(Fragment.java:2363)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1442)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1740)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1809)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:799)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2580)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2367)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2322)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2229)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3221)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3171)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.support.v4.app.FragmentController.dispatchActivityCreated(FragmentController.java:192)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:560)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:177)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1333)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.app.Activity.performStart(Activity.java:6992)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2780)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.app.ActivityThread.-wrap11(Unknown Source:0)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:105)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.os.Looper.loop(Looper.java:164)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:6541)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Stacktrace:
09-29 13:52:13.205 30730 30730 E AndroidRuntime: java.lang.NoSuchMethodError: No virtual method setRetainInstance(Z)V in class Landroid/arch/lifecycle/HolderFragment; or its super classes (declaration of 'android.arch.lifecycle.HolderFragment' appears in /data/app/package_name==/base.apk)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.arch.lifecycle.HolderFragment.<init>(HolderFragment.java:52)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.arch.lifecycle.HolderFragment$HolderFragmentManager.createHolderFragment(HolderFragment.java:148)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.arch.lifecycle.HolderFragment$HolderFragmentManager.holderFragmentFor(HolderFragment.java:186)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.arch.lifecycle.HolderFragment.holderFragmentFor(HolderFragment.java:89)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.arch.lifecycle.ViewModelStores.of(ViewModelStores.java:53)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.arch.lifecycle.ViewModelProviders.of(ViewModelProviders.java:90)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at com.test.fragments.MyFragment.setUpGui(MyFragment.java:170)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at com.test.fragments.MyFragment.onActivityCreated(MyFragment.java:140)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.support.v4.app.Fragment.performActivityCreated(Fragment.java:2363)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1442)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1740)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1809)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:799)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2580)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2367)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2322)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2229)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3221)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3171)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.support.v4.app.FragmentController.dispatchActivityCreated(FragmentController.java:192)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:560)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:177)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1333)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.app.Activity.performStart(Activity.java:6992)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2780)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.app.ActivityThread.-wrap11(Unknown Source:0)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:105)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.os.Looper.loop(Looper.java:164)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:6541)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
09-29 13:52:13.205 30730 30730 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
bi...@google.com <bi...@google.com> #23
Are you able to reproduce the issue on an example project that you could share with us?
Looking at the stack trace and corresponding source code, there are direct (statically known) calls all the way from ViewModelProviders.of(...) to HolderFragment.setRetainInstance(...) and I was unable to reproduce the problem.
When you open your APK in Studio with "Build -> Analyze APK", how many dex files are there in the APK? Can you see the setRetainInstance method in android.arch.lifecycle.HolderFragment?
Looking at the stack trace and corresponding source code, there are direct (statically known) calls all the way from ViewModelProviders.of(...) to HolderFragment.setRetainInstance(...) and I was unable to reproduce the problem.
When you open your APK in Studio with "Build -> Analyze APK", how many dex files are there in the APK? Can you see the setRetainInstance method in android.arch.lifecycle.HolderFragment?
si...@gmail.com <si...@gmail.com> #24
I see one dex file. And yes I can see setRetainInstance method in android.arch.lifecycle.HolderFragment
Description
Photos cast using the styled media receivers and the custom media receiver (CC1AD845) fail to load across all of our apps that cast. These have worked for many years and appear to have broken in the last few days (at most 1 week).
List steps to reproduce the issue, if known.
It would appear that MEDIA_TYPE_PHOTO casting of image/jpeg and image/png content types now fail. I have not tried other image formats.
1. Create a MediaInfo (id=photourl,contenttype=image/jpeg, streamtype=none(0), metadata=photo(4))
2. Pass the MediaInfo to CastSession.load(mediainfo, b) where b=true|false, it doesn't matter
I see the following errors after the load command:
W/MediaControlChannel: received unexpected error: Invalid Request.
Status{statusCode=unknown status code: 2100, resolution=null}
Which version of the Cast SDK are you using?
Fails with both v2 and CAF APIs using v18.1 and v19.0 of com.google.android.gms:play-services-cast Android libraries.
On which version(s) of the OS (iOS, Android) do you observe the problem?
Android
I've attached a logcat from the Android session. The failure is at 2021-04-23 11:41:40.108.