After updating to 2.71828 started getting crashes:
Caused by: java.lang.IllegalStateException:
at com.squareup.picasso.Picasso.get (Picasso.java:681)
With what stacktrace?
That's from the Play Console, I'm yet to reproduce it myself:
java.lang.RuntimeException:
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2984)
at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3045)
at android.app.ActivityThread.-wrap14 (ActivityThread.java)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1642)
at android.os.Handler.dispatchMessage (Handler.java:102)
at android.os.Looper.loop (Looper.java:154)
at android.app.ActivityThread.main (ActivityThread.java:6776)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1496)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1386)
Caused by: java.lang.IllegalStateException:
at com.squareup.picasso.Picasso.get (Picasso.java:681)
at my.app.service.PlaybackHandlerService.<init> (PlaybackHandlerService.kt:55)
at my.app.main.ServiceRegistry$playbackHandlerService$2.invoke (ServiceRegistry.kt:38)
at my.app.main.ServiceRegistry$playbackHandlerService$2.invoke (ServiceRegistry.kt:29)
at kotlin.SynchronizedLazyImpl.getValue (Lazy.kt:131)
at my.app.main.ServiceRegistry.getPlaybackHandlerService (ServiceRegistry.kt)
at my.app.main.ServiceRegistry.access$getPlaybackHandlerService$p (ServiceRegistry.kt:29)
at my.app.main.ServiceRegistry$allServices$2.invoke (ServiceRegistry.kt:77)
at my.app.main.ServiceRegistry$allServices$2.invoke (ServiceRegistry.kt:29)
at kotlin.SynchronizedLazyImpl.getValue (Lazy.kt:131)
at my.app.main.ServiceRegistry.getAllServices (ServiceRegistry.kt)
at my.app.main.ServiceRegistry.<init> (ServiceRegistry.kt:99)
at my.app.main.ServiceRegistry.<init> (ServiceRegistry.kt:29)
at my.app.main.ServiceRegistry$Companion.instance (ServiceRegistry.kt:116)
at my.app.MainActivity.onCreate (MainActivity.kt:29)
at android.app.Activity.performCreate (Activity.java:6955)
at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1126)
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2927)
Hmm that's super weird because at that point the provider should have been able to attach the context. Is there anything interesting about the devices on which the crash occurs?
Samsung phones including S6 & S7, Huawei, ASUS, all running Android 7.0.
I can't reproduce this on 7.0 myself.
An easy way to ensure this never happens is to create your own Picasso instance in Application.onCreate and then set it as the singleton instance with Picasso.setSingletonInstance in that method.
@yanchenko by chance, do any of the components in your application run in a separate process? I ask because ContentProviders (in this case, PicassoProvider) only run in the app's main process.
See "Some Drawbacks..." here: https://firebase.googleblog.com/2016/12/how-does-firebase-initialize-on-android.html
There's a bug in N where the backup feature leaves the process in an unusable state. Android then re-uses the unusable process. Basically what happens is that neither your Application subclass or ContentProviders are created in that process, so none of the initialization happens.
@jrodbx no. Thanks for the link!
@SimonVT seems to be the case, because a lateinit var that should have been initialized from Application was throwing UninitializedPropertyAccessException.
Is android:allowBackup="false" the fix?
I'm not sure, it doesn't happen enough for me to disable backups completely.
If you go that route you should only disable it on
Having the same issue on
Fixed in Application.java class using:
Picasso.setSingletonInstance(new Picasso.Builder(this).build());
No action to take. Closing.
I faced the same issue after adding dependency for lifecycle-extensions.
I have two apps that run under the same process.
The first app is the launcher app which is used for navigation.
The second app enhance the first with some extra functionalities.
Both of them use picasso.
After adding dependency for lifecycle-extensions, when i try to use a component of the second app that uses picasso, it crashes.
Caused by: java.lang.IllegalStateException: context == null
at com.squareup.picasso.Picasso.get(Picasso.java:681)
And then is impossible to launch the first app again.
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.Application.registerActivityLifecycleCallbacks(android.app.Application$ActivityLifecycleCallbacks)' on a null object reference
at androidx.lifecycle.LifecycleDispatcher.init(LifecycleDispatcher.java:44)
I have to uninstall the second app in order be able to launch.
I do not think is problem of picasso.
Maybe something has changed with lifecycle-extensions either
there was a hidden bug of my architecture which was exposed by them.
After investigating more the issue I found that the problem occurs when the apps are running in the same process and have declared the same Content Provider.
In the attachBaseContext of navigation's application class, all the Content Providers are trying to initiate themselves. The strange is that if we check the context of common Content Provider, then we are going to see that as packageInfo has a LoadedApk which refers to the other app. As a result context.getApplicationContext() returns null. I suppose that this happens because the Application class of the second app is not loaded in the classloader.
I do not know if this is a bug in android or it is something that happens by design (I know that it is not according to the guideline to have different apps in the same process :p)
Also I found a workaround, if we force the common Content Providers to run in a different process they seem to work well. We just have to declare them in AndroidManifest of each app and add a value for the process attribute. For example:
<provider
android:process="com.quadible.lifecycle"
android:name="android.arch.lifecycle.ProcessLifecycleOwnerInitializer"
android:authorities="${applicationId}.lifecycle-process"
android:exported="true"
tools:replace="android:authorities,android:exported">
</provider>
after create PicassoContentProvider.java, try to use:
<provider
android:name=".provider.PicassoContentProvider"
android:authorities="${applicationId}.provider.PicassoContentProvider"
android:exported="false"/>
in Manifest.xml.
Most helpful comment
Having the same issue on
Motorola G5S plus
Android 7.1.1
Fixed in
Application.javaclass using:Picasso.setSingletonInstance(new Picasso.Builder(this).build());