https://kotlinlang.org logo
#splitties
Title
# splitties
m

miha-x64

12/10/2019, 9:28 PM
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

louiscad

12/11/2019, 1:34 PM
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

miha-x64

12/11/2019, 1:48 PM
Oh, looks like I could remove ContentProvider through manifest and create&initialize it directly. This will give ProGuard/R8 more freedom. Thanks :)
l

louiscad

12/11/2019, 2:03 PM
How would that help Proguard? Remove the no-op methods from
InitProvider
?
m

miha-x64

12/11/2019, 2:07 PM
this will allow obfuscation
l

louiscad

12/11/2019, 5:17 PM
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

miha-x64

12/12/2019, 12:13 PM
I like classes to be in
_
package and have 1..3-char name unless they are entry points (application components).
l

louiscad

12/12/2019, 9:44 PM
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.
11 Views