Fixed
Status Update
Comments
do...@traveloka.com <do...@traveloka.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>(...);
}
pa...@gmail.com <pa...@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.
pa...@gmail.com <pa...@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.
ga...@google.com <ga...@google.com> #5
It's working fine for me, thanks a lot!
pa...@google.com <pa...@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>(...);
}
ap...@google.com <ap...@google.com> #7
This is still broken for me in alpha 2. I still need to specify ProGuard rules myself.
pa...@google.com <pa...@google.com> #8
Looks like I missed part in our .gradle file.
pa...@gmail.com <pa...@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.
Description
Java version "1.8.0_121"
Jetifier version: 1.0.0-beta04
Let there be a Library Foo with the following 'proguard-rules.txt' file:
# DBFlow
-keep class * extends com.raizlabs.android.dbflow.config.DatabaseHolder { *; }
-dontwarn com.raizlabs.android.dbflow.**
# Note: the configuration keeps the entry point 'com.raizlabs.android.dbflow.config.FlowManager$GlobalDatabaseHolder { FlowManager$GlobalDatabaseHolder(com.raizlabs.android.dbflow.config.FlowManager$1); }', but not the descriptor class 'com.raizlabs.android.dbflow.config.FlowManager$1'
-keep class com.raizlabs.android.dbflow.config.FlowManager$*
When trying to jetify this library:
./jetifier-standalone -i /Users/someuser/Downloads/foo/foo.aar -o newfoo.aar
The Jetifier fails with the following output:
Exception in thread "main" java.util.regex.PatternSyntaxException: Illegal repetition near index 147
com/raizlabs/android/dbflow/.*
# Note: the configuration keeps the entry point 'com/raizlabs/android/dbflow/config/FlowManager$GlobalDatabaseHolder { FlowManager$GlobalDatabaseHolder(com/raizlabs/android/dbflow/config/FlowManager$1); }'
^
at java.util.regex.Pattern.error(Pattern.java:1955)
at java.util.regex.Pattern.closure(Pattern.java:3157)
at java.util.regex.Pattern.sequence(Pattern.java:2134)
at java.util.regex.Pattern.expr(Pattern.java:1996)
at java.util.regex.Pattern.compile(Pattern.java:1696)
at java.util.regex.Pattern.<init>(Pattern.java:1351)
at java.util.regex.Pattern.compile(Pattern.java:1028)
at com.android.tools.build.jetifier.core.type.TypesMap.matchOldProguardForNewTypes(TypesMap.kt:112)
[...]
If i remove the notes, the new 'proguard-rules.txt' looks like this:
# DBFlow
-keep class * extends com.raizlabs.android.dbflow.config.DatabaseHolder { *; }
-dontwarn com.raizlabs.android.dbflow.**
-keep class com.raizlabs.android.dbflow.config.FlowManager$*
And this runs through the jetifier just fine. Please provide a fix for this issue, since i have to patch my dependencies currently in order to make AndroidX work for me.