App crashes on startup after updating Xamarin.AndroidX.ViewPager2.1.0.0.14 → Xamarin.AndroidX.ViewPager2.1.0.0.15
Android application type
Classic Xamarin.Android (MonoAndroid12.0, etc.)
Affected platform version
VS 2022 17.3.3 (build 10) for Mac
Description
My app with Target Framework Android 12.1 (Sv2) (API level 32) and Minimum Android Version 4.4 (API level 19) is built with the packages below. The app loads and runs perfectly on my Android test devices when I build with package Xamarin.AndroidX.ViewPager2.1.0.0.14. When I upgrade the package to Xamarin.AndroidX.ViewPager2.1.0.0.15 (no other changes), my app crashes immediately when attempting to open the app on my Android 5.1 and Android 6.0 test devices (other devices not tested to reproduce this problem).
I am building with the following packages / versions:
- Xamarin.Essentials 1.7.3
- Xamarin.Forms 5.0.0.2515
- Xamarin.AndroidX.Core 1.7.0.2 (cannot upgrade because of Xamarin.Forms 5.0.0.2515 constraint)
- Xamarin.AndroidX.Activity 1.4.0.3 (cannot upgrade because of Xamarin.AndroidX.Core 1.7.0.2 constraint)
- Xamarin.AndroidX.ViewPager 1.0.0.13 (cannot upgrade because of constraints)
- Xamarin.AndroidX.CustomView 1.1.0.12 (cannot upgrade because of constraints)
- Xamarin.AndroidX.RecyclerView 1.2.1.6 (Cannot upgrade because of constraints)
Reverting to Xamarin.AndroidX.ViewPager2.1.0.0.14 restores normal working behavior of my app. I am unable to upgrade to Xamarin.AndroidX.ViewPager2.1.0.0.16 because of the following constraints:
Unable to find a version of 'Xamarin.AndroidX.Core' that is compatible with 'Xamarin.AndroidX.Activity 1.5.1 constraint: Xamarin.AndroidX.Core (>= 1.8.0.1)', 'Xamarin.AndroidX.Core.Core.Ktx 1.8.0.1 constraint: Xamarin.AndroidX.Core (>= 1.8.0.1)', 'Xamarin.AndroidX.CustomView 1.1.0.13 constraint: Xamarin.AndroidX.Core (>= 1.8.0.1)', 'Xamarin.AndroidX.Loader 1.1.0.14 constraint: Xamarin.AndroidX.Core (>= 1.8.0.1)', 'Xamarin.AndroidX.RecyclerView 1.2.1.7 constraint: Xamarin.AndroidX.Core (>= 1.8.0.1)', 'Xamarin.AndroidX.ViewPager 1.0.0.14 constraint: Xamarin.AndroidX.Core (>= 1.8.0.1)', 'Xamarin.AndroidX.ViewPager2 1.0.0.16 constraint: Xamarin.AndroidX.Core (>= 1.8.0.1)'.
Steps to Reproduce
- Build app release build with package Xamarin.AndroidX.ViewPager2.1.0.0.14
- Deploy release build to Android test device (Android 5.1 and Android 6.0 devices easily reproduce the issue)
- Open app
- Observe working app
- Update package Xamarin.AndroidX.ViewPager2.1.0.0.14 -> Xamarin.AndroidX.ViewPager2.1.0.0.15 (no other changes)
- Build app release build with package Xamarin.AndroidX.ViewPager2.1.0.0.15 (no other changes)
- Deploy release build to Android test device
- Open app
- Observe app crash immediately upon opening
- Revert to package Xamarin.AndroidX.ViewPager2.1.0.0.14 (no other changes)
- Build app release build with Xamarin.AndroidX.ViewPager2.1.0.0.14
- Open app
- Observe working app
Did you find any workaround?
Work-around is to revert to package Xamarin.AndroidX.ViewPager2.1.0.0.14 (don't use Xamarin.AndroidX.ViewPager2.1.0.0.15). I am unable to upgrade to Xamarin.AndroidX.ViewPager2.1.0.0.16 because of constraints cited above.
Relevant log output
No response
@TonyC5 Please capture the crash from logcat output following the steps below, and attach the resulting log.txt file:
$ adb shell setprop debug.mono.log default,assembly,mono_log_level=debug,mono_log_mask=all
$ adb logcat -G 16M
$ adb logcat -c
# Start the application here and after it crashes do
$ adb logcat -d > log.txt
Also, it would be good if you could provide a small project which would allow us to reproduce the issue locally.
Hi @TonyC5. We have added the "need-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
@grendello The log file you requested is attached. Thank you very much for your help. Note that for the attached log, I changed my Android target from Android 12.1 (Sv2) to Android 12.0 (S) to see if the change to monoandroid12.0 would make any difference. The app still crashed and the resulting log (with target Android 12.0) is attached. log.txt
I will work on providing a small project if the attached log does not help you to identify the problem.
NOTE: The attached log is captured with a RELEASE build of my app. I tried to deploy a DEBUG build to diagnose in my VS2022 debugger, but when the DEBUG build launched, VS2022 complains that it can't find source JNIEnv.cs (which appears to be where the exception breakpoint occurs).
@grendello Thanks to your guidance about how to get the log, I was able to find the culprit in the log. The log indicated that my AndroidManifest.xml needs the provider and meta-data blocks within the application block. I added the following to my AndroidManifest.xml and the app now runs with the updated Xamarin.AndroidX.ViewPager2.1.0.0.15. I don't understand why I needed to add this. Should this have been added automatically?
<provider android:name="androidx.startup.InitializationProvider" android:authorities="${applicationId}.androidx-startup" tools:node="merge"> <meta-data android:name="androidx.lifecycle.ProcessLifecycleInitializer" android:value="androidx.startup" /> </provider>
Is this addition correct? I searched to find suggested
Thank you again for your help.
@TonyC5 you're most welcome! Regarding the manifest, I will have to refer you to @moljac, @jpobst and @dellis1972 who know way more than I about AndroidX and the manifest :)
Glad the instructions helped!
@TonyC5
Thanks for the feedback.
Something is using androidx.startup:startup-runtime package as transitive dependency. Not sure, but it could be Xamarin.Forms. I need to check docs and/or code.
https://developer.android.com/topic/libraries/app-startup
I will move this issue to AndroidX repo soon.
Does app crash with AndroidManifest.xml snippet?
from log file
I/MonoDroid(26119): Java.Lang.RuntimeException: Unable to get provider androidx.startup.InitializationProvider: androidx.startup.StartupException: androidx.startup.StartupException: java.lang.IllegalStateException: ProcessLifecycleInitializer cannot be initialized lazily.
I/MonoDroid(26119): Please ensure that you have:
I/MonoDroid(26119): <meta-data
I/MonoDroid(26119): android:name='androidx.lifecycle.ProcessLifecycleInitializer'
I/MonoDroid(26119): android:value='androidx.startup' />
I/MonoDroid(26119): under InitializationProvider in your AndroidManifest.xml ---> Java.Lang.RuntimeException: androidx.startup.StartupException: java.lang.IllegalStateException: ProcessLifecycleInitializer cannot be initialized lazily.
I/MonoDroid(26119): Please ensure that you have:
I/MonoDroid(26119): <meta-data
I/MonoDroid(26119): android:name='androidx.lifecycle.ProcessLifecycleInitializer'
I/MonoDroid(26119): android:value='androidx.startup' />
I/MonoDroid(26119): under InitializationProvider in your AndroidManifest.xml ---> Java.Lang.RuntimeException: java.lang.IllegalStateException: ProcessLifecycleInitializer cannot be initialized lazily.
I/MonoDroid(26119): Please ensure that you have:
I/MonoDroid(26119): <meta-data
I/MonoDroid(26119): android:name='androidx.lifecycle.ProcessLifecycleInitializer'
I/MonoDroid(26119): android:value='androidx.startup' />
I/MonoDroid(26119): under InitializationProvider in your AndroidManifest.xml ---> Java.Lang.IllegalStateException: ProcessLifecycleInitializer cannot be initialized lazily.
I/MonoDroid(26119): Please ensure that you have:
I/MonoDroid(26119): <meta-data
I/MonoDroid(26119): android:name='androidx.lifecycle.ProcessLifecycleInitializer'
I/MonoDroid(26119): android:value='androidx.startup' />
I/MonoDroid(26119): under InitializationProvider in your AndroidManifest.xml
I/MonoDroid(26119): --- End of inner exception stack trace ---
I/MonoDroid(26119): --- End of inner exception stack trace ---
I/MonoDroid(26119): --- End of inner exception stack trace ---
I/MonoDroid(26119): --- End of managed Java.Lang.RuntimeException stack trace ---
I/MonoDroid(26119): java.lang.RuntimeException: Unable to get provider androidx.startup.InitializationProvider: androidx.startup.StartupException: androidx.startup.StartupException: java.lang.IllegalStateException: ProcessLifecycleInitializer cannot be initialized lazily.
I/MonoDroid(26119): Please ensure that you have:
I/MonoDroid(26119): <meta-data
I/MonoDroid(26119): android:name='androidx.lifecycle.ProcessLifecycleInitializer'
I/MonoDroid(26119): android:value='androidx.startup' />
I/MonoDroid(26119): under InitializationProvider in your AndroidManifest.xml
I/MonoDroid(26119): at android.app.ActivityThread.installProvider(ActivityThread.java:5087)
I/MonoDroid(26119): at android.app.ActivityThread.installContentProviders(ActivityThread.java:4679)
I/MonoDroid(26119): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4619)
I/MonoDroid(26119): at android.app.ActivityThread.access$1500(ActivityThread.java:155)
I/MonoDroid(26119): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1378)
I/MonoDroid(26119): at android.os.Handler.dispatchMessage(Handler.java:102)
I/MonoDroid(26119): at android.os.Looper.loop(Looper.java:135)
I/MonoDroid(26119): at android.app.ActivityThread.main(ActivityThread.java:5343)
I/MonoDroid(26119): at java.lang.reflect.Method.invoke(Native Method)
I/MonoDroid(26119): at java.lang.reflect.Method.invoke(Method.java:372)
I/MonoDroid(26119): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
I/MonoDroid(26119): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
I/MonoDroid(26119): Caused by: androidx.startup.StartupException: androidx.startup.StartupException: java.lang.IllegalStateException: ProcessLifecycleInitializer cannot be initialized lazily.
I/MonoDroid(26119): Please ensure that you have:
I/MonoDroid(26119): <meta-data
I/MonoDroid(26119): android:name='androidx.lifecycle.ProcessLifecycleInitializer'
I/MonoDroid(26119): android:value='androidx.startup' />
I/MonoDroid(26119): under InitializationProvider in your AndroidManifest.xml
I/MonoDroid(26119): at androidx.startup.AppInitializer.doInitialize(AppInitializer.java:187)
I/MonoDroid(26119): at androidx.startup.AppInitializer.discoverAndInitialize(AppInitializer.java:238)
I/MonoDroid(26119): at androidx.startup.AppInitializer.discoverAndInitialize(AppInitializer.java:206)
I/MonoDroid(26119): at androidx.startup.InitializationProvider.onCreate(InitializationProvider.java:45)
I/MonoDroid(26119): at android.content.ContentProvider.attachInfo(ContentProvider.java:1696)
I/MonoDroid(26119): at android.content.ContentProvider.attachInfo(ContentProvider.java:1671)
I/MonoDroid(26119): at android.app.ActivityThread.installProvider(ActivityThread.java:5084)
I/MonoDroid(26119): ... 11 more
I/MonoDroid(26119): Caused by: androidx.startup.StartupException: java.lang.IllegalStateException: ProcessLifecycleInitializer cannot be initialized lazily.
I/MonoDroid(26119): Please ensure that you have:
I/MonoDroid(26119): <meta-data
I/MonoDroid(26119): android:name='androidx.lifecycle.ProcessLifecycleInitializer'
I/MonoDroid(26119): android:value='androidx.startup' />
I/MonoDroid(26119): under InitializationProvider in your AndroidManifest.xml
I/MonoDroid(26119): at androidx.startup.AppInitializer.doInitialize(AppInitializer.java:187)
I/MonoDroid(26119): at androidx.startup.AppInitializer.doInitialize(AppInitializer.java:173)
I/MonoDroid(26119): ... 17 more
I/MonoDroid(26119): Caused by: java.lang.IllegalStateException: ProcessLifecycleInitializer cannot be initialized lazily.
I/MonoDroid(26119): Please ensure that you have:
I/MonoDroid(26119): <meta-data
I/MonoDroid(26119): android:name='androidx.lifecycle.ProcessLifecycleInitializer'
I/MonoDroid(26119): android:value='androidx.startup' />
I/MonoDroid(26119): under InitializationProvider in your AndroidManifest.xml
I/MonoDroid(26119): at androidx.lifecycle.ProcessLifecycleInitializer.create(ProcessLifecycleInitializer.java:38)
I/MonoDroid(26119): at androidx.lifecycle.ProcessLifecycleInitializer.create(ProcessLifecycleInitializer.java:31)
I/MonoDroid(26119): at androidx.startup.AppInitializer.doInitialize(AppInitializer.java:180)
I/MonoDroid(26119): ... 18 more
--------- beginning of crash
E/AndroidRuntime(26119): FATAL EXCEPTION: main
E/AndroidRuntime(26119): Process: com.alottajava.merchant, PID: 26119
E/AndroidRuntime(26119): java.lang.RuntimeException: Unable to get provider androidx.startup.InitializationProvider: androidx.startup.StartupException: androidx.startup.StartupException: java.lang.IllegalStateException: ProcessLifecycleInitializer cannot be initialized lazily.
E/AndroidRuntime(26119): Please ensure that you have:
E/AndroidRuntime(26119): <meta-data
E/AndroidRuntime(26119): android:name='androidx.lifecycle.ProcessLifecycleInitializer'
E/AndroidRuntime(26119): android:value='androidx.startup' />
E/AndroidRuntime(26119): under InitializationProvider in your AndroidManifest.xml
E/AndroidRuntime(26119): at android.app.ActivityThread.installProvider(ActivityThread.java:5087)
E/AndroidRuntime(26119): at android.app.ActivityThread.installContentProviders(ActivityThread.java:4679)
E/AndroidRuntime(26119): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4619)
E/AndroidRuntime(26119): at android.app.ActivityThread.access$1500(ActivityThread.java:155)
E/AndroidRuntime(26119): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1378)
E/AndroidRuntime(26119): at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime(26119): at android.os.Looper.loop(Looper.java:135)
E/AndroidRuntime(26119): at android.app.ActivityThread.main(ActivityThread.java:5343)
E/AndroidRuntime(26119): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(26119): at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime(26119): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
E/AndroidRuntime(26119): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
E/AndroidRuntime(26119): Caused by: androidx.startup.StartupException: androidx.startup.StartupException: java.lang.IllegalStateException: ProcessLifecycleInitializer cannot be initialized lazily.
E/AndroidRuntime(26119): Please ensure that you have:
E/AndroidRuntime(26119): <meta-data
E/AndroidRuntime(26119): android:name='androidx.lifecycle.ProcessLifecycleInitializer'
E/AndroidRuntime(26119): android:value='androidx.startup' />
E/AndroidRuntime(26119): under InitializationProvider in your AndroidManifest.xml
E/AndroidRuntime(26119): at androidx.startup.AppInitializer.doInitialize(AppInitializer.java:187)
E/AndroidRuntime(26119): at androidx.startup.AppInitializer.discoverAndInitialize(AppInitializer.java:238)
E/AndroidRuntime(26119): at androidx.startup.AppInitializer.discoverAndInitialize(AppInitializer.java:206)
E/AndroidRuntime(26119): at androidx.startup.InitializationProvider.onCreate(InitializationProvider.java:45)
E/AndroidRuntime(26119): at android.content.ContentProvider.attachInfo(ContentProvider.java:1696)
E/AndroidRuntime(26119): at android.content.ContentProvider.attachInfo(ContentProvider.java:1671)
E/AndroidRuntime(26119): at android.app.ActivityThread.installProvider(ActivityThread.java:5084)
E/AndroidRuntime(26119): ... 11 more
E/AndroidRuntime(26119): Caused by: androidx.startup.StartupException: java.lang.IllegalStateException: ProcessLifecycleInitializer cannot be initialized lazily.
E/AndroidRuntime(26119): Please ensure that you have:
E/AndroidRuntime(26119): <meta-data
E/AndroidRuntime(26119): android:name='androidx.lifecycle.ProcessLifecycleInitializer'
E/AndroidRuntime(26119): android:value='androidx.startup' />
E/AndroidRuntime(26119): under InitializationProvider in your AndroidManifest.xml
E/AndroidRuntime(26119): at androidx.startup.AppInitializer.doInitialize(AppInitializer.java:187)
E/AndroidRuntime(26119): at androidx.startup.AppInitializer.doInitialize(AppInitializer.java:173)
E/AndroidRuntime(26119): ... 17 more
E/AndroidRuntime(26119): Caused by: java.lang.IllegalStateException: ProcessLifecycleInitializer cannot be initialized lazily.
E/AndroidRuntime(26119): Please ensure that you have:
E/AndroidRuntime(26119): <meta-data
E/AndroidRuntime(26119): android:name='androidx.lifecycle.ProcessLifecycleInitializer'
E/AndroidRuntime(26119): android:value='androidx.startup' />
E/AndroidRuntime(26119): under InitializationProvider in your AndroidManifest.xml
E/AndroidRuntime(26119): at androidx.lifecycle.ProcessLifecycleInitializer.create(ProcessLifecycleInitializer.java:38)
E/AndroidRuntime(26119): at androidx.lifecycle.ProcessLifecycleInitializer.create(ProcessLifecycleInitializer.java:31)
E/AndroidRuntime(26119): at androidx.startup.AppInitializer.doInitialize(AppInitializer.java:180)
E/AndroidRuntime(26119): ... 18 more
@moljac Thanks for your reply. My app does not crash after I add the AndroidManifest.xml here. I guessed at this after seeing the log, so I'm not certain that my addition to AndroidManifest.xml is correct. If you have the exact snippet that I should add (or just confirm that mine is correct), that would be helpful. Thank you.
EDIT: Just to be sure I'm clearly stating the issue, I only need the additional AndroidManifest.xml snippet with package Xamarin.AndroidX.ViewPager2.1.0.0.15. I do not need this additional AndroidManifest.xml snippet with Xamarin.AndroidX.ViewPager2.1.0.0.14.
@TonyC5 Does adding the InitializationProvider in AndroidManifest.xml working fine. Did you face any impacts after adding that.
I have also faced the same issue today, not sure it is needed for my app to include this piece of code in Manifest as below
<application android:allowBackup="true" android:label="AppDebug" android:theme="@style/MyTheme" >
<provider android:name="androidx.core.content.FileProvider" android:authorities="${applicationId}.fileprovider" android:exported="false" >
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths" />
</provider>
<provider android:name="androidx.startup.InitializationProvider" android:authorities="${applicationId}.androidx-startup" tools:node="merge">
<meta-data android:name="androidx.lifecycle.ProcessLifecycleInitializer" android:value="androidx.startup" />
</provider>
</application>
closing this issue