6

my current android application regularly reports this logcat message

W/System: A resource failed to call close. 

having searched for how to identify the root cause i have tried the following approaches, none of which have worked...

StrictMode.setVmPolicy(
                VmPolicy.Builder()
                    .detectLeakedClosableObjects()
                    .penaltyDeath()
                    .build()
            )

and this

StrictMode.setVmPolicy(
                VmPolicy.Builder()
                    .detectAll()
                    .penaltyDeath()
                    .build()
            )

and

try {
            Class.forName("dalvik.system.CloseGuard")
                .getMethod("setEnabled", Boolean::class.javaPrimitiveType)
                .invoke(null, true)
        } catch (e: ReflectiveOperationException) {
            throw java.lang.RuntimeException(e)
        }

my application targets these versions of android

 compileSdkVersion 32
    buildToolsVersion "32.0.0"

    defaultConfig {
        applicationId "com.my.app"
        minSdkVersion 26
        targetSdkVersion 32
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

where am i going wrong?

how can i discover which resource is not calling close?

Hector
  • 4,016
  • 21
  • 112
  • 211
  • 1
    Does this answer your question? [W/System: A resource failed to call release](https://stackoverflow.com/questions/56911580/w-system-a-resource-failed-to-call-release) – Stanislav Bondar Jan 18 '22 at 11:23
  • @StanislavBondar thats one of the resources i had already looked at and tried all the options listed. none of the approaches listed on your link gave any additional information – Hector Jan 18 '22 at 11:33
  • 1
    why the close vote? i have found the existing questions and answers for this issue and clearly stated these do not solve my issue. i have spent time on trying published solutions i now need additional assistance. i thought that was what so is all about? – Hector Jan 18 '22 at 11:45

1 Answers1

0

I had the same message. I looked at what resources I had declared in the main activity and took a guess it was the ListAdapter. So I cleared() it onDestroy. The message went away.

I'm sorry I don't have a better answer.