Skip to content

Android-maps-compose - StrictMode policy violation: IncorrectContextUseViolation #495

Description

@jarroyoesp

Environment details

  1. API: android-maps-compose
  2. OS type and version: Android API 31 or higher
  3. Library version and other environment information: maps-compose:4.3.0

Steps to reproduce

  1. Enable StrictMode in your app
  2. Add this rule: detectIncorrectContextUse()
  3. When you launch your app, you will get the Stack traced attached

Code example

Here you can find a sample project with the issue. Only added the StrictMode to BasicMapActivity:

https://github.com/jarroyoesp/android-maps-compose/tree/issue/strict-mode

Code snippet added in OnCreate method:

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
                val builderVM = StrictMode.VmPolicy.Builder()
            .penaltyDeath()
            .apply {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
                    detectIncorrectContextUse()
                }
            }
        StrictMode.setVmPolicy(builderVM.build())
        
         setContent {
        ....

Stack trace

StrictMode policy violation: android.os.strictmode.IncorrectContextUseViolation: The API:ViewConfiguration needs a proper configuration. Use UI contexts such as an activity or a context created via createWindowContext(Display, int, Bundle) or  createConfigurationContext(Configuration) with a proper configuration.
	at android.os.StrictMode.onIncorrectContextUsed(StrictMode.java:2261)
	at android.os.StrictMode.assertConfigurationContext(StrictMode.java:2297)
	at android.view.ViewConfiguration.get(ViewConfiguration.java:522)
	at android.view.View.<init>(View.java:5307)
	at android.view.View.<init>(View.java:5452)
	at android.view.ViewGroup.<init>(ViewGroup.java:702)
	at android.widget.RelativeLayout.<init>(RelativeLayout.java:255)
	at android.widget.RelativeLayout.<init>(RelativeLayout.java:251)
	at android.widget.RelativeLayout.<init>(RelativeLayout.java:247)
	at android.widget.RelativeLayout.<init>(RelativeLayout.java:243)
	at com.google.maps.api.android.lib6.impl.fh.<init>(:com.google.android.gms.dynamite_mapsdynamite@214218113@21.42.18 (190400-0):2)
	at com.google.maps.api.android.lib6.impl.bo.az(:com.google.android.gms.dynamite_mapsdynamite@214218113@21.42.18 (190400-0):16)
	at com.google.maps.api.android.lib6.impl.cz.d(:com.google.android.gms.dynamite_mapsdynamite@214218113@21.42.18 (190400-0):2)
	at com.google.android.gms.maps.internal.q.aX(:com.google.android.gms.dynamite_mapsdynamite@214218113@21.42.18 (190400-0):14)
	at dx.onTransact(:com.google.android.gms.dynamite_mapsdynamite@214218113@21.42.18 (190400-0):4)
	at android.os.Binder.transact(Binder.java:1064)
	at com.google.android.gms.internal.maps.zza.zzc(com.google.android.gms:play-services-maps@@18.2.0:2)
	at com.google.android.gms.maps.internal.zzl.onCreate(com.google.android.gms:play-services-maps@@18.2.0:3)
	at com.google.android.gms.maps.zzah.onCreate(com.google.android.gms:play-services-maps@@18.2.0:3)
	at com.google.android.gms.dynamic.zac.zab(com.google.android.gms:play-services-base@@18.0.1:1)
	at com.google.android.gms.dynamic.zaa.onDelegateCreated(com.google.android.gms:play-services-base@@18.0.1:3)
	at com.google.android.gms.maps.zzai.zzb(com.google.android.gms:play-services-maps@@18.2.0:5)
	at com.google.android.gms.maps.zzai.createDelegate(com.google.android.gms:play-services-maps@@18.2.0:1)
	at com.google.android.gms.dynamic.DeferredLifecycleHelper.zaf(com.google.android.gms:play-services-base@@18.0.1:6)
	at com.google.android.gms.dynamic.DeferredLifecycleHelper.onCreate(com.google.android.gms:play-services-base@@18.0.1:1)
	at com.google.android.gms.maps.MapView.onCreate(com.google.android.gms:play-services-maps@@18.2.0:4)
	at com.google.maps.android.compose.GoogleMapKt.lifecycleObserver$lambda$11(GoogleMap.kt:207)
	at com.google.maps.android.compose.GoogleMapKt.$r8$lambda$Vm6abttjyrD0BNPAw0a-nOgtk1E(Unknown Source:0)
	at com.google.maps.android.compose.GoogleMapKt$$ExternalSyntheticLambda0.onStateChanged(Unknown Source:4)
	at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.kt:314)
	at androidx.lifecycle.LifecycleRegistry.forwardPass(LifecycleRegistry.kt:251)
	at androidx.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.kt:287)
	at androidx.lifecycle.LifecycleRegistry.addObserver(LifecycleRegistry.kt:199)
	at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.android.kt:140)
	at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.android.kt:133)
	at androidx.compose.ui.platform.AndroidComposeView.onAttachedToWindow(AndroidComposeView.android.kt:1266)
	at android.view.View.dispatchAttachedToWindow(View.java:20753)
	at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3490)
	at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)
	at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)
	at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)
	at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)
	at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2613)
	at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2126)
	at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8653)
	at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1037)
	at android.view.Choreographer.doCallbacks(Choreographer.java:845)
	at android.view.Choreographer.doFrame(Choreographer.java:780)
	at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1022)
	at android.os.Handler.handleCallback(Handler.java:938)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at android.os.Looper.loopOnce(Looper.java:201)
	at android.os.Looper.loop(Looper.java:288)
	at android.app.ActivityThread.main(ActivityThread.java:7839)

                                                                                                    	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
Caused by: java.lang.IllegalAccessException: Tried to access the API:ViewConfiguration which needs to have proper configuration from a non-UI Context:android.app.Application@553e3dd

Thanks! 😃

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: p3Desirable enhancement or fix. May not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions