nowinandroid: [Bug]: crash app

Is there an existing issue for this?

  • I have searched the existing issues

Is there a StackOverflow question about this issue?

  • I have searched StackOverflow

What happened?

just run app ,it is crash

Relevant logcat output

Process: com.google.samples.apps.nowinandroid.demo.debug, PID: 17321
                                                                                                    java.lang.RuntimeException: StrictMode ThreadPolicy violation
                                                                                                    	at android.os.StrictMode$AndroidBlockGuardPolicy.onThreadPolicyViolation(StrictMode.java:1981)
                                                                                                    	at android.os.StrictMode$AndroidBlockGuardPolicy.lambda$handleViolationWithTimingAttempt$0(StrictMode.java:1895)
                                                                                                    	at android.os.StrictMode$AndroidBlockGuardPolicy.$r8$lambda$AF9hglpXLeeg2_1ZxHCfZb2exEY(Unknown Source:0)
                                                                                                    	at android.os.StrictMode$AndroidBlockGuardPolicy$$ExternalSyntheticLambda1.run(Unknown Source:6)
                                                                                                    	at android.os.Handler.handleCallback(Handler.java:958)
                                                                                                    	at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                                                    	at android.os.Looper.loopOnce(Looper.java:257)
                                                                                                    	at android.os.Looper.loop(Looper.java:368)
                                                                                                    	at android.app.ActivityThread.main(ActivityThread.java:8839)
                                                                                                    	at java.lang.reflect.Method.invoke(Native Method)
                                                                                                    	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:572)
                                                                                                    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1049)
                                                                                                    Caused by: android.os.strictmode.DiskReadViolation
                                                                                                    	at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1726)
                                                                                                    	at libcore.io.BlockGuardOs.access(BlockGuardOs.java:74)
                                                                                                    	at libcore.io.ForwardingOs.access(ForwardingOs.java:128)
                                                                                                    	at android.app.ActivityThread$AndroidOs.access(ActivityThread.java:8703)
                                                                                                    	at java.io.UnixFileSystem.checkAccess(UnixFileSystem.java:313)
                                                                                                    	at java.io.File.exists(File.java:813)
                                                                                                    	at android.content.res.OplusThemeZipFile.isValidThemeFile(OplusThemeZipFile.java:305)
                                                                                                    	at android.content.res.OplusThemeZipFile.getThemeZipFile(OplusThemeZipFile.java:237)
                                                                                                    	at android.content.res.OplusThemeResources.checkUpdate(OplusThemeResources.java:162)
                                                                                                    	at android.content.res.OplusThemeResourcesSystem.checkUpdate(OplusThemeResourcesSystem.java:50)
                                                                                                    	at android.content.res.ResourcesImplExt.checkUpdate(ResourcesImplExt.java:395)
                                                                                                    	at android.content.res.ResourcesImpl.updateConfiguration(ResourcesImpl.java:545)
                                                                                                    	at android.content.res.ResourcesImpl.<init>(ResourcesImpl.java:197)
                                                                                                    	at android.app.ResourcesManager.createResourcesImpl(ResourcesManager.java:713)
                                                                                                    	at android.app.ResourcesManager.findOrCreateResourcesImplForKeyLocked(ResourcesManager.java:755)
                                                                                                    	at android.app.ResourcesManager.createResourcesForActivity(ResourcesManager.java:1140)
                                                                                                    	at android.app.ResourcesManager.createBaseTokenResources(ResourcesManager.java:951)
                                                                                                    	at android.app.ContextImpl.createActivityContext(ContextImpl.java:3460)
                                                                                                    	at android.app.ActivityThread.createBaseContextForActivity(ActivityThread.java:4121)
                                                                                                    	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3894)
                                                                                                    	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4181)
                                                                                                    	at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:114)
                                                                                                    	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:144)
                                                                                                    	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:101)
                                                                                                    	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2643)
                                                                                                    	at android.os.Handler.dispatchMessage(Handler.java:106)
                                                                                                    	at android.os.Looper.loopOnce(Looper.java:257) 
                                                                                                    	at android.os.Looper.loop(Looper.java:368) 
                                                                                                    	at android.app.ActivityThread.main(ActivityThread.java:8839) 
                                                                                                    	at java.lang.reflect.Method.invoke(Native Method) 
                                                                                                    	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:572) 
                                                                                                    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1049) 

Code of Conduct

  • I agree to follow this project’s Code of Conduct

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 17 (6 by maintainers)

Most upvoted comments

@XueyiXia It is just an workaround for you, not for this project.

If you want to avoid the policy crash on your device. Simply remove penaltyDeath() from NiaApplication.kt.

private fun setStrictModePolicy() {
        if (isDebuggable()) {
            StrictMode.setThreadPolicy(
                Builder().detectAll().penaltyLog().build(),
            )
        }
    }

We probably won’t do that since it defeats the purpose of catching bad behaviors.

@XueyiXia It is just an workaround for you, not for this project.

If you want to avoid the policy crash on your device. Simply remove penaltyDeath() from NiaApplication.kt.

private fun setStrictModePolicy() {
        if (isDebuggable()) {
            StrictMode.setThreadPolicy(
                Builder().detectAll().penaltyLog().build(),
            )
        }
    }

it works

I got opportunity to test this on multiple devices today:

Device Reproducible?
Pixel 8a No
Pixel 9 No
Emulator Pixel 9 - API 35 No
Xiaomi 13 Pro YES

Inside MainActivity.kt --> onResume() add this:

permitDiskReads{ super.onResume() }

then permitDiskReads method as follows:

` private fun permitDiskReads(func: () -> Any) : Any { if (BuildConfig.DEBUG) { val oldThreadPolicy = StrictMode.getThreadPolicy() StrictMode.setThreadPolicy( StrictMode.ThreadPolicy.Builder(oldThreadPolicy) .permitDiskReads().build()) val anyValue = func() StrictMode.setThreadPolicy(oldThreadPolicy)

        return anyValue
    } else {
        return func()
    }
}`

It solves the issue in the OnePlus device. I don’t have other devices to replicate.

Interesting… It seems like your OS is trying to apply custom theming (or at least tries to see if a custom theme matches) and reading a file on disk at the same time. Do you happen to have a OnePlus device, or a custom OS with theming support? This crash will only appear in debug builds, where we want to catch these issues as soon as possible, but not on release builds.