Status Update
Comments
[Deleted User] <[Deleted User]> #2
I'm sorry! More info:
Kotlin 1.3.5.0
lifecyle = 2.2.0-rc02
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:${versions.lifecycle}"
implementation "androidx.lifecycle:lifecycle-extensions:${versions.lifecycle}"
implementation "androidx.lifecycle:lifecycle-common-java8:${versions.lifecycle}"
class VideoModel(val app: Application) : AndroidViewModel(app) {
// do something
}
Kotlin 1.3.5.0
lifecyle = 2.2.0-rc02
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:${versions.lifecycle}"
implementation "androidx.lifecycle:lifecycle-extensions:${versions.lifecycle}"
implementation "androidx.lifecycle:lifecycle-common-java8:${versions.lifecycle}"
class VideoModel(val app: Application) : AndroidViewModel(app) {
// do something
}
uc...@google.com <uc...@google.com>
js...@google.com <js...@google.com> #3
This is lifecyle-viewmodel-kts build dependency, where lifecycle-viewmodel is added (as API).
This is lifecycle-viewmodel build, and there proguard rule is applied to all build types.
and finally, this is the configuration:
```
-keepclassmembers,allowobfuscation class * extends androidx.lifecycle.AndroidViewModel {
<init>(android.app.Application);
}
```
Because of that rule, at least instance initializer of your class that extends AndroidViewModel would be kept as long as that class itself is used/kept somehow. That's one notable difference between `-keepclassmemebers` v.s. other keep directives such as `-keep` or `-keepclasseswithmembers`.
But those rules are coming from the library, so I assume it's been there for a while (though you're using lifecycle 2.2.0-rc02, is it something you recently upgraded?) Then, the difference we should track is why `VideoModel` was kept at AGP 3.5.2 and is not now at AGP 3.6.0-beta04.
Could you add the following rule to your `proguard-rules.pro` and build your app again with AGP 3.5.2?
```
-whyareyoukeeping class **.VideoModel
```
To make sure rules from lifecycle-viewmodel is included as well, could you also add the following to literally print all configurations?
```
-printconfiguration all-configurations.txt
```
If you think it reveals too much details of your apps, you can send it to jsjeon@google.com privately, instead of posting it here. Thanks.
[Deleted User] <[Deleted User]> #4
Thank you!
I added printconfiguration all-configurations.txt then compare on AS all-configurations-3.5.2.txt vs all-configurations-3.6.0-beta04.txt. Proguard config of ViewModel was consumed.
The different:
all-configurations-3.6.0-beta04.txt
# When editing this file, update the following files as well:
# - META-INF/com.android.tools/proguard/coroutines.pro
# - META-INF/proguard/coroutines.pro
all-configurations-3.5.2.txt
# Files in this directory will be ignored starting with Android Gradle Plugin 3.6.0+
# When editing this file, update the following files as well for AGP 3.6.0+:
# - META-INF/com.android.tools/proguard/coroutines.pro
# - META-INF/com.android.tools/r8-upto-1.6.0/coroutines.pro
and all-configurations-3.6.0-beta04.txt missed that was added in all-configurations-3.5.2.txt.
This the part missing:
# This is a configuration file for ProGuard.
#http://proguard.sourceforge.net/index.html#manual/usage.html
#
# Starting with version 2.2 of the Android plugin for Gradle, this file is distributed together with
# the plugin and unpacked at build-time. The files in $ANDROID_HOME are no longer maintained and
# will be ignored by new version of the Android plugin for Gradle.
# Optimization is turned off by default. Dex does not like code run
# through the ProGuard optimize steps (and performs some
# of these optimizations on its own).
# Note that if you want to enable optimization, you cannot just
# include optimization flags in your own project configuration file;
# instead you will need to point to the
# "proguard-android-optimize.txt" file instead of this one from your
# project.properties file.
-dontoptimize
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose
# Preserve some attributes that may be required for reflection.
-keepattributes *Annotation*,Signature,InnerClasses,EnclosingMethod
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService
-keep public class com.google.android.vending.licensing.ILicensingService
-dontnote com.android.vending.licensing.ILicensingService
-dontnote com.google.vending.licensing.ILicensingService
-dontnote com.google.android.vending.licensing.ILicensingService
# For native methods, seehttp://proguard.sourceforge.net/manual/examples.html#native
-keepclasseswithmembernames class * {
native <methods>;
}
# Keep setters in Views so that animations can still work.
-keepclassmembers public class * extends android.view.View {
void set*(***);
*** get*();
}
# We want to keep methods in Activity that could be used in the XML attribute onClick.
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
# For enumeration classes, seehttp://proguard.sourceforge.net/manual/examples.html#enumerations
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keepclassmembers class * implements android.os.Parcelable {
public static final ** CREATOR;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
# Preserve annotated Javascript interface methods.
-keepclassmembers class * {
@android.webkit.JavascriptInterface <methods>;
}
# The support libraries contains references to newer platform versions.
# Don't warn about those in case this app is linking against an older
# platform version. We know about them, and they are safe.
-dontnote android.support.**
-dontnote androidx.**
-dontwarn android.support.**
-dontwarn androidx.**
# This class is deprecated, but remains for backward compatibility.
-dontwarn android.util.FloatMath
# Understand the @Keep support annotation.
-keep class android.support.annotation.Keep
-keep class androidx.annotation.Keep
-keep @android.support.annotation.Keep class * {*;}
-keep @androidx.annotation.Keep class * {*;}
-keepclasseswithmembers class * {
@android.support.annotation.Keep <methods>;
}
-keepclasseswithmembers class * {
@androidx.annotation.Keep <methods>;
}
-keepclasseswithmembers class * {
@android.support.annotation.Keep <fields>;
}
-keepclasseswithmembers class * {
@androidx.annotation.Keep <fields>;
}
-keepclasseswithmembers class * {
@android.support.annotation.Keep <init>(...);
}
-keepclasseswithmembers class * {
@androidx.annotation.Keep <init>(...);
}
# These classes are duplicated between android.jar and org.apache.http.legacy.jar.
-dontnote org.apache.http.**
-dontnote android.net.http.**
# These classes are duplicated between android.jar and core-lambda-stubs.jar.
-dontnote java.lang.invoke.**
I have another project that has the same config but it hadn't the problem with AGP 3.6.0-beta04. I will try to investigate more.
I think it can the same this problem before:https://issuetracker.google.com/issues/112324130
Below is the full log
E/TAG: java.lang.RuntimeException: Cannot create an instance of class com.myapp.screenrecorder.taskmedia.video.s
at androidx.lifecycle.M.a(ViewModelProvider.java:9)
at androidx.lifecycle.I.a(SavedStateViewModelFactory.java:4)
at androidx.lifecycle.Q.a(ViewModelProvider.java:8)
at com.myapp.screenrecorder.taskmedia.video.b.invoke(com.android.tools.r8.jetbrains.kotlin-style lambda group:1)
at kotlin.l.getValue(Lazy.kt:2)
at com.myapp.screenrecorder.taskmedia.video.VideoFragment.e(VideoFragment.kt:1)
at com.myapp.screenrecorder.taskmedia.video.g.c(VideoFragment.kt:11)
at kotlin.coroutines.jvm.internal.a.a(ContinuationImpl.kt:3)
at kotlinx.coroutines.K.a(Dispatched.kt:18)
at com.myapp.simplefilechooser.g.a(Unknown Source:20)
at kotlinx.coroutines.a.a(AbstractCoroutine.kt:21)
at kotlinx.coroutines.d.a(Unknown Source:16)
at com.myapp.screenrecorder.taskmedia.video.VideoFragment.d0(VideoFragment.kt:1)
at com.myapp.screenrecorder.taskmedia.video.VideoFragment.a(VideoFragment.kt:18)
at androidx.fragment.app.T.a(FragmentStateManager.java:51)
at androidx.fragment.app.K.a(FragmentManager.java:176)
at androidx.fragment.app.K.a(FragmentManager.java:426)
at androidx.fragment.app.K.a(FragmentManager.java:373)
at androidx.fragment.app.K.c(FragmentManager.java:38)
at androidx.fragment.app.K.c(FragmentManager.java:22)
at androidx.fragment.app.K.b(FragmentManager.java:49)
at androidx.fragment.app.K.c(FragmentManager.java:42)
at androidx.fragment.app.k.e(Fragment.java:6)
at androidx.fragment.app.T.a(FragmentStateManager.java:56)
at androidx.fragment.app.K.a(FragmentManager.java:177)
at androidx.fragment.app.K.h(FragmentManager.java:4)
at androidx.fragment.app.K.a(FragmentManager.java:257)
at androidx.fragment.app.K.b(FragmentManager.java:47)
at androidx.fragment.app.K.c(FragmentManager.java:42)
at androidx.fragment.app.w.a(FragmentController.java:9)
at androidx.fragment.app.m.onStart(FragmentActivity.java:5)
at androidx.appcompat.app.v.onStart(AppCompatActivity.java:1)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1392)
at android.app.Activity.performStart(Activity.java:7157)
at android.app.ActivityThread.handleStartActivity(ActivityThread.java:2952)
at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:180)
at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:165)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:142)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1823)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:198)
at android.app.ActivityThread.main(ActivityThread.java:6729)
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> [class android.app.Application]
at java.lang.Class.getConstructor0(Class.java:2327)
at java.lang.Class.getConstructor(Class.java:1725)
at androidx.lifecycle.M.a(ViewModelProvider.java:5)
at androidx.lifecycle.I.a(SavedStateViewModelFactory.java:4)
at androidx.lifecycle.Q.a(ViewModelProvider.java:8)
at com.myapp.screenrecorder.taskmedia.video.b.invoke(com.android.tools.r8.jetbrains.kotlin-style lambda group:1)
at kotlin.l.getValue(Lazy.kt:2)
at com.myapp.screenrecorder.taskmedia.video.VideoFragment.e(VideoFragment.kt:1)
at com.myapp.screenrecorder.taskmedia.video.g.c(VideoFragment.kt:11)
at kotlin.coroutines.jvm.internal.a.a(ContinuationImpl.kt:3)
at kotlinx.coroutines.K.a(Dispatched.kt:18)
at com.myapp.simplefilechooser.g.a(Unknown Source:20)
at kotlinx.coroutines.a.a(AbstractCoroutine.kt:21)
at kotlinx.coroutines.d.a(Unknown Source:16)
at com.myapp.screenrecorder.taskmedia.video.VideoFragment.d0(VideoFragment.kt:1)
at com.myapp.screenrecorder.taskmedia.video.VideoFragment.a(VideoFragment.kt:18)
at androidx.fragment.app.T.a(FragmentStateManager.java:51)
at androidx.fragment.app.K.a(FragmentManager.java:176)
at androidx.fragment.app.K.a(FragmentManager.java:426)
at androidx.fragment.app.K.a(FragmentManager.java:373)
at androidx.fragment.app.K.c(FragmentManager.java:38)
at androidx.fragment.app.K.c(FragmentManager.java:22)
at androidx.fragment.app.K.b(FragmentManager.java:49)
at androidx.fragment.app.K.c(FragmentManager.java:42)
at androidx.fragment.app.k.e(Fragment.java:6)
at androidx.fragment.app.T.a(FragmentStateManager.java:56)
at androidx.fragment.app.K.a(FragmentManager.java:177)
at androidx.fragment.app.K.h(FragmentManager.java:4)
at androidx.fragment.app.K.a(FragmentManager.java:257)
at androidx.fragment.app.K.b(FragmentManager.java:47)
at androidx.fragment.app.K.c(FragmentManager.java:42)
at androidx.fragment.app.w.a(FragmentController.java:9)
at androidx.fragment.app.m.onStart(FragmentActivity.java:5)
at androidx.appcompat.app.v.onStart(AppCompatActivity.java:1)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1392)
at android.app.Activity.performStart(Activity.java:7157)
at android.app.ActivityThread.handleStartActivity(ActivityThread.java:2952)
at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:180)
at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:165)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:142)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1823)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:198)
at android.app.ActivityThread.main(ActivityThread.java:6729)
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)
I added printconfiguration all-configurations.txt then compare on AS all-configurations-3.5.2.txt vs all-configurations-3.6.0-beta04.txt. Proguard config of ViewModel was consumed.
The different:
all-configurations-3.6.0-beta04.txt
# When editing this file, update the following files as well:
# - META-INF/com.android.tools/proguard/
# - META-INF/proguard/
all-configurations-3.5.2.txt
# Files in this directory will be ignored starting with Android Gradle Plugin 3.6.0+
# When editing this file, update the following files as well for AGP 3.6.0+:
# - META-INF/com.android.tools/proguard/
# - META-INF/com.android.tools/r8-upto-1.6.0/
and all-configurations-3.6.0-beta04.txt missed that was added in all-configurations-3.5.2.txt.
This the part missing:
# This is a configuration file for ProGuard.
#
#
# Starting with version 2.2 of the Android plugin for Gradle, this file is distributed together with
# the plugin and unpacked at build-time. The files in $ANDROID_HOME are no longer maintained and
# will be ignored by new version of the Android plugin for Gradle.
# Optimization is turned off by default. Dex does not like code run
# through the ProGuard optimize steps (and performs some
# of these optimizations on its own).
# Note that if you want to enable optimization, you cannot just
# include optimization flags in your own project configuration file;
# instead you will need to point to the
# "proguard-android-optimize.txt" file instead of this one from your
# project.properties file.
-dontoptimize
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose
# Preserve some attributes that may be required for reflection.
-keepattributes *Annotation*,Signature,InnerClasses,EnclosingMethod
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService
-keep public class com.google.android.vending.licensing.ILicensingService
-dontnote com.android.vending.licensing.ILicensingService
-dontnote com.google.vending.licensing.ILicensingService
-dontnote com.google.android.vending.licensing.ILicensingService
# For native methods, see
-keepclasseswithmembernames class * {
native <methods>;
}
# Keep setters in Views so that animations can still work.
-keepclassmembers public class * extends android.view.View {
void set*(***);
*** get*();
}
# We want to keep methods in Activity that could be used in the XML attribute onClick.
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
# For enumeration classes, see
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keepclassmembers class * implements android.os.Parcelable {
public static final ** CREATOR;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
# Preserve annotated Javascript interface methods.
-keepclassmembers class * {
@android.webkit.JavascriptInterface <methods>;
}
# The support libraries contains references to newer platform versions.
# Don't warn about those in case this app is linking against an older
# platform version. We know about them, and they are safe.
-dontnote android.support.**
-dontnote androidx.**
-dontwarn android.support.**
-dontwarn androidx.**
# This class is deprecated, but remains for backward compatibility.
-dontwarn android.util.FloatMath
# Understand the @Keep support annotation.
-keep class android.support.annotation.Keep
-keep class androidx.annotation.Keep
-keep @android.support.annotation.Keep class * {*;}
-keep @androidx.annotation.Keep class * {*;}
-keepclasseswithmembers class * {
@android.support.annotation.Keep <methods>;
}
-keepclasseswithmembers class * {
@androidx.annotation.Keep <methods>;
}
-keepclasseswithmembers class * {
@android.support.annotation.Keep <fields>;
}
-keepclasseswithmembers class * {
@androidx.annotation.Keep <fields>;
}
-keepclasseswithmembers class * {
@android.support.annotation.Keep <init>(...);
}
-keepclasseswithmembers class * {
@androidx.annotation.Keep <init>(...);
}
# These classes are duplicated between android.jar and org.apache.http.legacy.jar.
-dontnote org.apache.http.**
-dontnote android.net.http.**
# These classes are duplicated between android.jar and core-lambda-stubs.jar.
-dontnote java.lang.invoke.**
I have another project that has the same config but it hadn't the problem with AGP 3.6.0-beta04. I will try to investigate more.
I think it can the same this problem before:
Below is the full log
E/TAG: java.lang.RuntimeException: Cannot create an instance of class com.myapp.screenrecorder.taskmedia.video.s
at androidx.lifecycle.M.a(ViewModelProvider.java:9)
at androidx.lifecycle.I.a(SavedStateViewModelFactory.java:4)
at androidx.lifecycle.Q.a(ViewModelProvider.java:8)
at com.myapp.screenrecorder.taskmedia.video.b.invoke(com.android.tools.r8.jetbrains.kotlin-style lambda group:1)
at kotlin.l.getValue(Lazy.kt:2)
at com.myapp.screenrecorder.taskmedia.video.VideoFragment.e(VideoFragment.kt:1)
at com.myapp.screenrecorder.taskmedia.video.g.c(VideoFragment.kt:11)
at kotlin.coroutines.jvm.internal.a.a(ContinuationImpl.kt:3)
at kotlinx.coroutines.K.a(Dispatched.kt:18)
at com.myapp.simplefilechooser.g.a(Unknown Source:20)
at kotlinx.coroutines.a.a(AbstractCoroutine.kt:21)
at kotlinx.coroutines.d.a(Unknown Source:16)
at com.myapp.screenrecorder.taskmedia.video.VideoFragment.d0(VideoFragment.kt:1)
at com.myapp.screenrecorder.taskmedia.video.VideoFragment.a(VideoFragment.kt:18)
at androidx.fragment.app.T.a(FragmentStateManager.java:51)
at androidx.fragment.app.K.a(FragmentManager.java:176)
at androidx.fragment.app.K.a(FragmentManager.java:426)
at androidx.fragment.app.K.a(FragmentManager.java:373)
at androidx.fragment.app.K.c(FragmentManager.java:38)
at androidx.fragment.app.K.c(FragmentManager.java:22)
at androidx.fragment.app.K.b(FragmentManager.java:49)
at androidx.fragment.app.K.c(FragmentManager.java:42)
at androidx.fragment.app.k.e(Fragment.java:6)
at androidx.fragment.app.T.a(FragmentStateManager.java:56)
at androidx.fragment.app.K.a(FragmentManager.java:177)
at androidx.fragment.app.K.h(FragmentManager.java:4)
at androidx.fragment.app.K.a(FragmentManager.java:257)
at androidx.fragment.app.K.b(FragmentManager.java:47)
at androidx.fragment.app.K.c(FragmentManager.java:42)
at androidx.fragment.app.w.a(FragmentController.java:9)
at androidx.fragment.app.m.onStart(FragmentActivity.java:5)
at androidx.appcompat.app.v.onStart(AppCompatActivity.java:1)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1392)
at android.app.Activity.performStart(Activity.java:7157)
at android.app.ActivityThread.handleStartActivity(ActivityThread.java:2952)
at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:180)
at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:165)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:142)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1823)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:198)
at android.app.ActivityThread.main(ActivityThread.java:6729)
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> [class android.app.Application]
at java.lang.Class.getConstructor0(Class.java:2327)
at java.lang.Class.getConstructor(Class.java:1725)
at androidx.lifecycle.M.a(ViewModelProvider.java:5)
at androidx.lifecycle.I.a(SavedStateViewModelFactory.java:4)
at androidx.lifecycle.Q.a(ViewModelProvider.java:8)
at com.myapp.screenrecorder.taskmedia.video.b.invoke(com.android.tools.r8.jetbrains.kotlin-style lambda group:1)
at kotlin.l.getValue(Lazy.kt:2)
at com.myapp.screenrecorder.taskmedia.video.VideoFragment.e(VideoFragment.kt:1)
at com.myapp.screenrecorder.taskmedia.video.g.c(VideoFragment.kt:11)
at kotlin.coroutines.jvm.internal.a.a(ContinuationImpl.kt:3)
at kotlinx.coroutines.K.a(Dispatched.kt:18)
at com.myapp.simplefilechooser.g.a(Unknown Source:20)
at kotlinx.coroutines.a.a(AbstractCoroutine.kt:21)
at kotlinx.coroutines.d.a(Unknown Source:16)
at com.myapp.screenrecorder.taskmedia.video.VideoFragment.d0(VideoFragment.kt:1)
at com.myapp.screenrecorder.taskmedia.video.VideoFragment.a(VideoFragment.kt:18)
at androidx.fragment.app.T.a(FragmentStateManager.java:51)
at androidx.fragment.app.K.a(FragmentManager.java:176)
at androidx.fragment.app.K.a(FragmentManager.java:426)
at androidx.fragment.app.K.a(FragmentManager.java:373)
at androidx.fragment.app.K.c(FragmentManager.java:38)
at androidx.fragment.app.K.c(FragmentManager.java:22)
at androidx.fragment.app.K.b(FragmentManager.java:49)
at androidx.fragment.app.K.c(FragmentManager.java:42)
at androidx.fragment.app.k.e(Fragment.java:6)
at androidx.fragment.app.T.a(FragmentStateManager.java:56)
at androidx.fragment.app.K.a(FragmentManager.java:177)
at androidx.fragment.app.K.h(FragmentManager.java:4)
at androidx.fragment.app.K.a(FragmentManager.java:257)
at androidx.fragment.app.K.b(FragmentManager.java:47)
at androidx.fragment.app.K.c(FragmentManager.java:42)
at androidx.fragment.app.w.a(FragmentController.java:9)
at androidx.fragment.app.m.onStart(FragmentActivity.java:5)
at androidx.appcompat.app.v.onStart(AppCompatActivity.java:1)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1392)
at android.app.Activity.performStart(Activity.java:7157)
at android.app.ActivityThread.handleStartActivity(ActivityThread.java:2952)
at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:180)
at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:165)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:142)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1823)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:198)
at android.app.ActivityThread.main(ActivityThread.java:6729)
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)
[Deleted User] <[Deleted User]> #5
The different file size after exported
[Deleted User] <[Deleted User]> #6
The problem was resolved after clear project + rebuild and add the rule -keep class **VideoModel. But I hope this can add or process automatically as AGP 3.5.2 instead of manual adding,
The finally file size is 4,179KB. I don't know why before file size is 3804KB, maybe the cause is the part missing of proguard.
Thank you!
The finally file size is 4,179KB. I don't know why before file size is 3804KB, maybe the cause is the part missing of proguard.
Thank you!
sg...@google.com <sg...@google.com> #7
Thanks for reporting back, that you found a workaround. I still wonder why an additional rule was needed.
As jsjeon@google.com mentioned in b/144514795#comment3 the rule:
-keepclassmembers,allowobfuscation class * extends androidx.lifecycle.AndroidViewModel {
<init>(android.app.Application);
}
should come from the aar, but it does not show up in your -printconfiguration output, which seems strange.
To test I created a "Basic Activity" app, and added
dependencies {
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0-rc02"
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0-rc02"
implementation "androidx.lifecycle:lifecycle-common-java8:2.2.0-rc02"
}
and when I add -printconfiguration the rule above is in the file - you should see that as well.
It would be interesting to understand why this does not work. I am not that familiar with androidx.lifecycle, but I don't think you should need the rule '-keep class **VideoModel'. I wonder if you could try the following without that rule:
1. Add the rule '-whyareyoukeeping class **VideoModel' and build release. The output from -whyareyoukeeping goes to stdout for the build.
2. Look at the mapping file app/build/outputs/mapping/release/mapping.txt for the build from 1), and look for you ViewModel class.
3. If the above still crash at runtime try the rule '-keep,allowobfuscation class **VideoModel'
4. Look at the mapping file app/build/outputs/mapping/release/mapping.txt for the build from 3), and look for you ViewModel class.
As jsjeon@google.com mentioned in
-keepclassmembers,allowobfuscation class * extends androidx.lifecycle.AndroidViewModel {
<init>(android.app.Application);
}
should come from the aar, but it does not show up in your -printconfiguration output, which seems strange.
To test I created a "Basic Activity" app, and added
dependencies {
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0-rc02"
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0-rc02"
implementation "androidx.lifecycle:lifecycle-common-java8:2.2.0-rc02"
}
and when I add -printconfiguration the rule above is in the file - you should see that as well.
It would be interesting to understand why this does not work. I am not that familiar with androidx.lifecycle, but I don't think you should need the rule '-keep class **VideoModel'. I wonder if you could try the following without that rule:
1. Add the rule '-whyareyoukeeping class **VideoModel' and build release. The output from -whyareyoukeeping goes to stdout for the build.
2. Look at the mapping file app/build/outputs/mapping/release/mapping.txt for the build from 1), and look for you ViewModel class.
3. If the above still crash at runtime try the rule '-keep,allowobfuscation class **VideoModel'
4. Look at the mapping file app/build/outputs/mapping/release/mapping.txt for the build from 3), and look for you ViewModel class.
[Deleted User] <[Deleted User]> #8
Thank you!
I build all cases with AGP 3.6.0-beta04 and this the result:
-keepclassmembers,allowobfuscation class * extends androidx.lifecycle.AndroidViewModel {
<init>(android.app.Application);
}
or '-whyareyoukeeping class **VideoModel
But it still crashed at runtime because it missed this in the mapping.txt
android.app.Application app -> c
1:1:void <init>(android.app.Application):17:17 -> <init>
.........................................................
When adding rule '-keep,allowobfuscation class **VideoModel'. It worked fine because it added full.
I build all cases with AGP 3.6.0-beta04 and this the result:
-keepclassmembers,allowobfuscation class * extends androidx.lifecycle.AndroidViewModel {
<init>(android.app.Application);
}
or '-whyareyoukeeping class **VideoModel
But it still crashed at runtime because it missed this in the mapping.txt
android.app.Application app -> c
1:1:void <init>(android.app.Application):17:17 -> <init>
.........................................................
When adding rule '-keep,allowobfuscation class **VideoModel'. It worked fine because it added full.
js...@google.com <js...@google.com> #9
Sorry for asking similar things again, but there were some miscommunication at comment #7 v.s. comment #3 . Building the all with AGP 3.6.0-beta04, along with -whyareyoukeeping rule doesn't make any changes because we're chasing why certain things have been kept at AGP 3.5.2 v.s. not kept at AGP 3.6.0-beta04. That's why I asked, at comment #3 , building your app with the working version, AGP 3.5.2, along with -whyareyoukeeping rule so that we can see why it's been kept there.
So, again, from comment #7 ,
> 1. Add the rule '-whyareyoukeeping class **VideoModel' and build release. The output from -whyareyoukeeping goes to stdout for the build.
This actually meant, building with AGP 3.5.2, not AGP 3.6.0-beta04 (because we knew beta version is not keeping something on that hierarchy).
> 3. If the above still crash at runtime try the rule '-keep,allowobfuscation class **VideoModel'
But, this one meant AGP 3.6.0-beta04, in order to see if renaming matters v.s. it's literally missing to trace fundamental components. And, that's what you already tested, thanks.
------
But... you can hold on doing another build and experiment, since I feel like we're chasing a wrong target. The reason we kept asking you to chase why your **.ViewModel was kept or not was, mainly because that seems like the one we're missing according to comment #1 and comment #2 . But, comment #8 indicated the lack of initializer in AndroidViewModel (btw, it's not Application according to the attached image), and indeed, looking back the call stack at comment #4 , there were two errors: one is,
E/TAG: java.lang.RuntimeException: Cannot create an instance of class com.myapp.screenrecorder.taskmedia.video.s
at androidx.lifecycle.M.a(ViewModelProvider.java:9)
at androidx.lifecycle.I.a(SavedStateViewModelFactory.java:4)
at androidx.lifecycle.Q.a(ViewModelProvider.java:8)
and the other is:
Caused by: java.lang.NoSuchMethodException: <init> [class android.app.Application]
at java.lang.Class.getConstructor0(Class.java:2327)
at java.lang.Class.getConstructor(Class.java:1725)
at androidx.lifecycle.M.a(ViewModelProvider.java:5)
Indeed, there are many reflective instance creations in ViewModelProvider, e.g.,https://android.googlesource.com/platform/frameworks/support/+/refs/heads/androidx-master-dev/lifecycle/lifecycle-viewmodel/src/main/java/androidx/lifecycle/ViewModelProvider.java#267 and that's why they provide rules like https://android.googlesource.com/platform/frameworks/support/+/refs/heads/androidx-master-dev/lifecycle/lifecycle-viewmodel/proguard-rules.pro
------
More interestingly, according to comment #4 ,
So, again, from
> 1. Add the rule '-whyareyoukeeping class **VideoModel' and build release. The output from -whyareyoukeeping goes to stdout for the build.
This actually meant, building with AGP 3.5.2, not AGP 3.6.0-beta04 (because we knew beta version is not keeping something on that hierarchy).
> 3. If the above still crash at runtime try the rule '-keep,allowobfuscation class **VideoModel'
But, this one meant AGP 3.6.0-beta04, in order to see if renaming matters v.s. it's literally missing to trace fundamental components. And, that's what you already tested, thanks.
------
But... you can hold on doing another build and experiment, since I feel like we're chasing a wrong target. The reason we kept asking you to chase why your **.ViewModel was kept or not was, mainly because that seems like the one we're missing according to
E/TAG: java.lang.RuntimeException: Cannot create an instance of class com.myapp.screenrecorder.taskmedia.video.s
at androidx.lifecycle.M.a(ViewModelProvider.java:9)
at androidx.lifecycle.I.a(SavedStateViewModelFactory.java:4)
at androidx.lifecycle.Q.a(ViewModelProvider.java:8)
and the other is:
Caused by: java.lang.NoSuchMethodException: <init> [class android.app.Application]
at java.lang.Class.getConstructor0(Class.java:2327)
at java.lang.Class.getConstructor(Class.java:1725)
at androidx.lifecycle.M.a(ViewModelProvider.java:5)
Indeed, there are many reflective instance creations in ViewModelProvider, e.g.,
------
More interestingly, according to
which I believe came from:
Not seeing `-dontoptimize` at 3.6.0-beta04.txt means it's using
Maybe that came from other dependent libraries. Then, I guess the issue was just hidden even with AGP 3.5.2
------
According to
class MyActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
// Create a ViewModel the first time the system calls an activity's onCreate() method.
// Re-created activities receive the same MyViewModel instance created by the first activity.
val model = ViewModelProviders.of(this)[MyViewModel::class.java]
model.getUsers().observe(this, Observer<List<User>>{ users ->
// update UI
})
}
}
and there, type reference, e.g., MyViewModel::class.java, made that type being kept, and then trigger -keepclassmembers rules with <init>. That's how ViewModelProvider can reflectively instantiate users' view model. Could you let us know how your **.VideoModel is used?
[Deleted User] <[Deleted User]> #10
You can ignore #4 for now.
ViewModelProviders.of is deprecated so I am using
class VideoFragment : Fragment() {
private val videoModel: VideoModel by lazy(LazyThreadSafetyMode.NONE) {
ViewModelProvider(this).get(VideoModel::class.java)
}
............................
private fun loadVideos() {
val videos = videoModel.getVideos()
}
}
class VideoModel(val app: Application) : AndroidViewModel(app) {
suspend fun getVideos(): List<MediaItem> = withContext(ioDispatcher) {
val appSettings = AppSettings.getInstance(app)
if (appSettings.locationStorageType == 0) {
traverseInternalStorage(appSettings.videoDirectory)
} else {
traverseRemovableStorage(appSettings.externalStorageUri?.toUri())
}
}
..................
}
My config in build.gradle
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
manifestPlaceholders += [crashlyticsEnabled: true]
}
}
gradle.properties
org.gradle.parallel=true
org.gradle.caching=true
android.enableJetifier=true
android.useAndroidX=true
android.enableR8.fullMode=true
android.debug.obsoleteApi=true
kapt.incremental.apt=true
Now my proguard-rules.pro config
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public class * extends com.bumptech.glide.AppGlideModule
-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
**[] $VALUES;
public *;
}
-keep class com.coremedia.iso.** { *; }
-keep class com.googlecode.mp4parser.** { *; }
-keep class com.mp4parser.** { *; }
-keep class org.mp4parser.aspectj.internal.** { *; }
-keep class org.mp4parser.aspectj.lang.** { *; }
-keep class org.mp4parser.aspectj.runtime.** { *; }
-dontwarn com.googlecode.mp4parser.authoring.tracks.mjpeg.OneJpegPerIframe
# For Kotlin coroutines
# ServiceLoader support
-keepnames class kotlinx.coroutines.internal.MainDispatcherFactory {}
-keepnames class kotlinx.coroutines.CoroutineExceptionHandler {}
-keepnames class kotlinx.coroutines.android.AndroidExceptionPreHandler {}
-keepnames class kotlinx.coroutines.android.AndroidDispatcherFactory {}
# Most of volatile fields are updated with AFU and should not be mangled
-keepclassmembernames class kotlinx.** {
volatile <fields>;
}
#https://github.com/Kotlin/kotlinx.coroutines/issues/858
-keep @interface kotlin.coroutines.jvm.internal.** { *; }
# In-app
-keep class com.android.vending.billing.**
-keepattributes *Annotation*
-keepattributes SourceFile,LineNumberTable
-keep public class * extends java.lang.Exception
# Avoid runtime app crash
-keep,allowobfuscation **VideoModel
AGP 3.5.2 I didn't added any rule for VideoModel it worked fine.
AGP 3.6.0-beta04 I need to add rule -keep,allowobfuscation **VideoModel to the app doesn't error at runtime.
I have another project it using the AndroidViewModel and same code but when build with AGP 3.6.0-beta04, it worked as AGP 3.5.2 (didn't need to add a proguard rule for ViewModel).
I think it had a problem for my project. Because this didn't happen on all project.
Thank for your supporting!
ViewModelProviders.of is deprecated so I am using
class VideoFragment : Fragment() {
private val videoModel: VideoModel by lazy(LazyThreadSafetyMode.NONE) {
ViewModelProvider(this).get(VideoModel::class.java)
}
............................
private fun loadVideos() {
val videos = videoModel.getVideos()
}
}
class VideoModel(val app: Application) : AndroidViewModel(app) {
suspend fun getVideos(): List<MediaItem> = withContext(ioDispatcher) {
val appSettings = AppSettings.getInstance(app)
if (appSettings.locationStorageType == 0) {
traverseInternalStorage(appSettings.videoDirectory)
} else {
traverseRemovableStorage(appSettings.externalStorageUri?.toUri())
}
}
..................
}
My config in build.gradle
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
manifestPlaceholders += [crashlyticsEnabled: true]
}
}
gradle.properties
org.gradle.parallel=true
org.gradle.caching=true
android.enableJetifier=true
android.useAndroidX=true
android.enableR8.fullMode=true
android.debug.obsoleteApi=true
kapt.incremental.apt=true
Now my proguard-rules.pro config
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public class * extends com.bumptech.glide.AppGlideModule
-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
**[] $VALUES;
public *;
}
-keep class com.coremedia.iso.** { *; }
-keep class com.googlecode.mp4parser.** { *; }
-keep class com.mp4parser.** { *; }
-keep class org.mp4parser.aspectj.internal.** { *; }
-keep class org.mp4parser.aspectj.lang.** { *; }
-keep class org.mp4parser.aspectj.runtime.** { *; }
-dontwarn com.googlecode.mp4parser.authoring.tracks.mjpeg.OneJpegPerIframe
# For Kotlin coroutines
# ServiceLoader support
-keepnames class kotlinx.coroutines.internal.MainDispatcherFactory {}
-keepnames class kotlinx.coroutines.CoroutineExceptionHandler {}
-keepnames class kotlinx.coroutines.android.AndroidExceptionPreHandler {}
-keepnames class kotlinx.coroutines.android.AndroidDispatcherFactory {}
# Most of volatile fields are updated with AFU and should not be mangled
-keepclassmembernames class kotlinx.** {
volatile <fields>;
}
#
-keep @interface kotlin.coroutines.jvm.internal.** { *; }
# In-app
-keep class com.android.vending.billing.**
-keepattributes *Annotation*
-keepattributes SourceFile,LineNumberTable
-keep public class * extends java.lang.Exception
# Avoid runtime app crash
-keep,allowobfuscation **VideoModel
AGP 3.5.2 I didn't added any rule for VideoModel it worked fine.
AGP 3.6.0-beta04 I need to add rule -keep,allowobfuscation **VideoModel to the app doesn't error at runtime.
I have another project it using the AndroidViewModel and same code but when build with AGP 3.6.0-beta04, it worked as AGP 3.5.2 (didn't need to add a proguard rule for ViewModel).
I think it had a problem for my project. Because this didn't happen on all project.
Thank for your supporting!
js...@google.com <js...@google.com>
[Deleted User] <[Deleted User]> #12
I return to report: All my projects had this problem with AS 3.6.0 official and the newest version of ViewModel. Maybe, you should investigate again.
Thanks!
Thanks!
js...@google.com <js...@google.com> #13
Please take a look at the other issue marked as a dup and try R8 2.0.39 as mentioned at
Description
Build #AI-192.6817.14.36.5994180, built on November 8, 2019
Runtime version: 1.8.0_212-release-1586-b04 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0
GC: ParNew, ConcurrentMarkSweep
Memory: 1237M
Cores: 8
Registry: ide.new.welcome.screen.force=true
I had the problem with AndroidViewModel and ViewModel after upgraded to AS 3.6.0-beta04 (using AGP same the version of AS 3.6.0-beta04).
I tried restoring to AGP 3.5.2, it hadn't this problem. Seems R8 or gradle was removed the contructor of ViewModel
E/TAG: java.lang.RuntimeException: Cannot create an instance of class com.myapp.screenrecorder.taskmedia.video.l
at androidx.lifecycle.p0.a(ViewModelProvider.java:9)
at androidx.lifecycle.l0.a(SavedStateViewModelFactory.java:4)
at androidx.lifecycle.u0.a(ViewModelProvider.java:9)
at androidx.lifecycle.u0.a(ViewModelProvider.java:2)