leakcanary icon indicating copy to clipboard operation
leakcanary copied to clipboard

leak_canary_watcher_watch_dismissed_dialogs configuration incompatible with nonTransitiveRClass resources

Open bubenheimer opened this issue 2 years ago • 5 comments

leakcanary 2.10

I don't believe the unusual configuration approach overriding the leak_canary_watcher_watch_dismissed_dialogs resource is compatible with non-transitive R classes (android.nonTransitiveRClass=true). Setting that resource in app code would simply create a new resource that is private to the app.

Non-transitive R classes are the default in Android now.

bubenheimer avatar Jan 19 '23 13:01 bubenheimer

Interesting. Do you have documentation pointers on this?

Can you repro in a sample project and share it here? or e.g. by making changes to this repo in the sample app?

pyricau avatar Jan 24 '23 00:01 pyricau

The main document link I see is this, but it does not say much about how it works:

https://developer.android.com/studio/build/optimize-your-build#use-non-transitive-r-classes

In essence, it creates a per-module namespace for the resources defined in the module. Before, in the source, all your resources would look like org.example.myapp.R.someresource, now they look like org.example.myapp.mymodule.R.someresource and org.example.myapp.myothermodule.R.someresource.

A module with non-transitive R classes turned on (the default now) cannot override another module's/library's resource anymore, because for compilation purposes the module's resource effectively ends up in the module's own resource namespace as a brand new resource. It gets its own numeric resource ID assigned at the end of the build.

Easiest way to verify this for yourself would be to override one of those UI-related leakcanary resources from a module with the android.nonTransitiveRClass flag true & false. Then you'd see changes in the UI.

bubenheimer avatar Jan 31 '23 14:01 bubenheimer

I asked the god of Gradle and he said that once you set android.nonTransitiveRClass=true then you indeed cannot override resources from dependencies in any com.android.library modules, however you can still do that in your com.android.application module. Not ideal but at least that's a workaround.

pyricau avatar Feb 07 '23 19:02 pyricau

Thank you for the investigation, that is workable for me until something better comes around.

bubenheimer avatar Feb 08 '23 12:02 bubenheimer

Goal is to fix this by removing all XML configuration booleans.

pyricau avatar May 18 '23 04:05 pyricau