How can I avoid using `appctx` module? Just found ...
# splitties
m
How can I avoid using
appctx
module? Just found it thanks to Analyze APK. For some reason I can't even see it in 'merged manifest' or 'external libraries'. I understand the motivation but don't want Android to create one more component and and to have one more singleton.
l
The application
Context
is already a singleton. FYI, iOS has access to everything that Context provides in a static manner as well (it seems it has caused about zero problems so far, more than 10 years in). Since Android APIs are polluted with the
Context
parameter a lot,
appCtx
provide being quite handy. You can still disable it through merged manifest tricks, but if somthing relying on it gets into your app, it will blow up unless there's an alternative way to inject the application
Context
that is actually a singleton anyways (a subclass of
Application
). Basing your app's architecture on singeltons is most likely a bad idea, but there are a lot of places where using
object
or top level `val`s makes sense, and that's why Kotlin makes it easy, and why
appctx
leverages it.
m
Oh, looks like I could remove ContentProvider through manifest and create&initialize it directly. This will give ProGuard/R8 more freedom. Thanks :)
l
How would that help Proguard? Remove the no-op methods from
InitProvider
?
m
this will allow obfuscation
l
Obfuscation? I don't see the point of obfuscating calls to
appCtx
or it's
InitProvider
, this is open source code from an open source library. Code that uses it can still be obfuscated, and
appCtx
itself will still be obfuscated.
m
I like classes to be in
_
package and have 1..3-char name unless they are entry points (application components).
l
I don't really like to read the output of compiler or R8, so I don't really care if an open source library uses a component that can't be obfuscated as long that it doesn't make my app significantly bigger.