<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Jason Pearson on Medium]]></title>
        <description><![CDATA[Stories by Jason Pearson on Medium]]></description>
        <link>https://medium.com/@kaeawc?source=rss-176cd46cdccd------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*LVpaHJ12i4y4pQO6xx64bg.png</url>
            <title>Stories by Jason Pearson on Medium</title>
            <link>https://medium.com/@kaeawc?source=rss-176cd46cdccd------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 13:25:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kaeawc/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Kotlin JVM args: Inheritance & Defaults]]></title>
            <link>https://medium.com/@kaeawc/kotlin-jvm-args-inheritance-defaults-e74a1e7a2b63?source=rss-176cd46cdccd------2</link>
            <guid isPermaLink="false">https://medium.com/p/e74a1e7a2b63</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[platform-engineering]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[jvm]]></category>
            <dc:creator><![CDATA[Jason Pearson]]></dc:creator>
            <pubDate>Tue, 24 Sep 2024 11:17:09 GMT</pubDate>
            <atom:updated>2024-09-24T11:17:09.020Z</atom:updated>
            <content:encoded><![CDATA[<p>This is a post in my JVM Args for Builds series where I break down how these settings affect JVM-based build systems. A number of these settings are complicated and all have compounding effects on each other as the JVM is a complex machine, but used the right way can be the difference between having a high-value feedback build system versus a high-cost one.</p><p>One of Kotlin’s main targets is the JVM and therefore how it sets up its daemon for compilation can be tweaked via its JVM args. Over the years we’ve gotten better hooks and documentation that make it easier to set them correctly, especially with the introduction of the kotlin.daemon.jvmargs property. Today&#39;s article is going to cover the inheritance and defaults of JVM args the Kotlin daemon runs with.</p><h3>TLDR;</h3><p>For the vast majority of JVM build systems that are small-medium projects this doesn’t impact you. You might be running settings you didn’t expect, but they don’t matter significantly.</p><p>For medium to large projects that have tried to apply JVM arg best practices you might have assumed the Kotlin daemon is copying all JVM args from Gradle JVM args because the Kotlin documentation was a bit vague. You should check out your settings and verify via <a href="https://visualvm.github.io/">VisualVM</a>. Since I started writing this I <a href="https://github.com/JetBrains/kotlin-web-site/pull/4454">fixed Kotlin’s documentation on the topic</a>, but that doesn’t fix all the build systems out there. Its up to you to verify and adjust accordingly.</p><h3>Unexpected Behavior</h3><p>I was checking over some JVM profiling I had done for a build. One of the suggestions I got along the way was to remove all the Kotlin JVM args because they were all the same, and that made sense so I did it. But then I went to check out the results in profiling and saw slightly different numbers. That’s odd. So I looked up how I could verify the JVM args in a running process and came across the tool <a href="https://visualvm.github.io/">VisualVM</a> which does that and more.</p><p>After downloading it VisualVM wasn’t picking up my JAVA_HOME so I opened it via Terminal with the manual flag:</p><pre>/Applications/VisualVM.app/Contents/MacOS/visualvm --jdkhome $JAVA_HOME</pre><p>I’d been setting the following JVM args:</p><p>org.gradle.jvmargs=-Dfile.encoding=UTF-8 -XX:+UseG1GC -XX:SoftRefLRUPolicyMSPerMB=1 -XX:+HeapDumpOnOutOfMemoryError -Xmx3g -Xms3g -XX:MetaspaceSize=512m -XX:MaxMetaspaceSize=1g</p><p>gradle.properties file in NowInAndroid</p><p>The Gradle Daemon looks okay…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UUM4RZJXY8G2KxED.png" /></figure><p>But the Kotlin Daemon has a bunch of stuff in it I didn’t specify and missing most of the Gradle JVM args!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*l9h4xZDcvkb5qo-i.png" /></figure><p>Okay, so there must be some filtering going on somewhere in the Kotlin codebase that contains both the Kotlin Gradle Plugin and Kotlin Daemon for JVM. For the benefit of the curious I documented that journey, otherwise you can <a href="#what-did-we-find">skip the entire next section to see what I found</a>.</p><h3>Down the rabbit hole</h3><p>The Gradle property kotlin.daemon.jvmargs is read by KGP in PropertiesProvider.kt</p><pre>package org.jetbrains.kotlin.gradle.plugin</pre><pre>internal class PropertiesProvider private constructor(private val project: Project) {</pre><pre>    val kotlinDaemonJvmArgs: String?<br>        get() = property(&quot;kotlin.daemon.jvmargs&quot;).orNull</pre><p>kotlinDaemonJvmArgs gets used in AbstractKotlinCompileConfig.kt</p><pre>package org.jetbrains.kotlin.gradle.tasks.configuration</pre><pre>/**<br> * Configuration for the base compile task, [org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile].<br> *<br> * This contains all data necessary to configure the tasks, and should avoid exposing global state (project, extensions, other tasks)<br> * to the task instance as much as possible.<br> */<br>internal abstract class AbstractKotlinCompileConfig&lt;TASK : AbstractKotlinCompile&lt;*&gt;&gt;(<br>    project: Project,<br>    val ext: KotlinTopLevelExtension<br>) : TaskConfigAction&lt;TASK&gt;(project) {</pre><pre>    init {<br>        val compilerSystemPropertiesService = CompilerSystemPropertiesService.registerIfAbsent(project)<br>        val buildFinishedListenerService = BuildFinishedListenerService.registerIfAbsent(project)<br>        val buildIdService = BuildIdService.registerIfAbsent(project)<br>        configureTask { task -&gt;<br>            val propertiesProvider = project.kotlinPropertiesProvider</pre><pre>            propertiesProvider.kotlinDaemonJvmArgs?.let { kotlinDaemonJvmArgs -&gt;<br>                task.kotlinDaemonJvmArguments.set(providers.provider {<br>                    kotlinDaemonJvmArgs.split(&quot;\\s+&quot;.toRegex())<br>                })<br>            }</pre><p>kotlinDaemonJvmArguments gets used in CompileUsingKotlinDaemonWithNormalization.kt</p><pre>package org.jetbrains.kotlin.gradle.tasks</pre><pre>internal interface CompileUsingKotlinDaemonWithNormalization : CompileUsingKotlinDaemon {</pre><pre>    @get:Internal<br>    val normalizedKotlinDaemonJvmArguments: Provider&lt;List&lt;String&gt;&gt;<br>        get() = kotlinDaemonJvmArguments.map {<br>            it.map { arg -&gt; arg.trim().removePrefix(&quot;-&quot;) }<br>        }<br>}</pre><p>normalizedKotlinDaemonJvmArguments gets used in AbstractKotlinCompile.kt</p><pre>package org.jetbrains.kotlin.gradle.tasks</pre><pre>@DisableCachingByDefault(because = &quot;Abstract super-class, not to be instantiated directly&quot;)<br>abstract class AbstractKotlinCompile&lt;T : CommonCompilerArguments&gt; @Inject constructor(<br>    objectFactory: ObjectFactory,<br>    workerExecutor: WorkerExecutor,<br>) : AbstractKotlinCompileTool&lt;T&gt;(objectFactory),<br>    CompileUsingKotlinDaemonWithNormalization,<br>    UsesBuildMetricsService,<br>    UsesIncrementalModuleInfoBuildService,<br>    UsesCompilerSystemPropertiesService,<br>    UsesVariantImplementationFactories,<br>    UsesBuildFinishedListenerService,<br>    UsesClassLoadersCachingBuildService,<br>    UsesKotlinToolingDiagnostics,<br>    UsesBuildIdProviderService,<br>    UsesBuildFusService,<br>    BaseKotlinCompile {</pre><pre>    @get:Internal<br>    internal val compilerRunner: Provider&lt;GradleCompilerRunner&gt; =<br>        objectFactory.propertyWithConvention(<br>            gradleCompileTaskProvider.flatMap { taskProvider -&gt;<br>                compilerExecutionStrategy<br>                    .zip(metrics) { executionStrategy, metrics -&gt;<br>                        metrics to executionStrategy<br>                    }<br>                    .flatMap { params -&gt;<br>                        defaultKotlinJavaToolchain<br>                            .map {<br>                                val toolsJar = it.currentJvmJdkToolsJar.orNull<br>                                createGradleCompilerRunner(<br>                                    taskProvider,<br>                                    toolsJar,<br>                                    CompilerExecutionSettings(<br>                                        normalizedKotlinDaemonJvmArguments.orNull,<br>                                        params.second,<br>                                        useDaemonFallbackStrategy.get()<br>                                    ),<br>                                    params.first,<br>                                    workerExecutor,<br>                                    runViaBuildToolsApi.get(),<br>                                    classLoadersCachingService,<br>                                    buildFinishedListenerService,<br>                                    buildIdService,<br>                                    buildFusService.orNull?.getFusMetricsConsumer()<br>                                )<br>                            }<br>                    }<br>            }<br>        )</pre><p>normalizedKotlinDaemonJvmArguments gets passed into CompilerExecutionSettings.kt</p><pre>package org.jetbrains.kotlin.compilerRunner</pre><pre>import org.jetbrains.kotlin.gradle.tasks.KotlinCompilerExecutionStrategy<br>import java.io.Serializable</pre><pre>internal data class CompilerExecutionSettings(<br>    val daemonJvmArgs: List&lt;String&gt;?,<br>    val strategy: KotlinCompilerExecutionStrategy,<br>    val useDaemonFallbackStrategy: Boolean,<br>) : Serializable {<br>    companion object {<br>        const val serialVersionUID: Long = 0<br>    }<br>}</pre><p>This is a data class, so an instance of CompilerExecutionSettings must be created. Its field daemonJvmArgs is then used by GradleKotlinCompilerWork.kt</p><pre>package org.jetbrains.kotlin.compilerRunner</pre><pre>internal class GradleKotlinCompilerWork @Inject constructor(<br>    private val config: GradleKotlinCompilerWorkArguments<br>) : Runnable {</pre><pre>    private fun compileWithDaemon(messageCollector: MessageCollector): ExitCode {<br>        val isDebugEnabled = log.isDebugEnabled || System.getProperty(&quot;kotlin.daemon.debug.log&quot;)?.toBoolean() ?: true<br>        val daemonMessageCollector =<br>            if (isDebugEnabled) messageCollector else MessageCollector.NONE<br>        val connection =<br>            metrics.measure(GradleBuildTime.CONNECT_TO_DAEMON) {<br>                GradleCompilerRunner.getDaemonConnectionImpl(<br>                    config.projectFiles.clientIsAliveFlagFile,<br>                    config.projectFiles.sessionFlagFile,<br>                    config.compilerFullClasspath,<br>                    daemonMessageCollector,<br>                    isDebugEnabled = isDebugEnabled,<br>                    daemonJvmArgs = config.compilerExecutionSettings.daemonJvmArgs<br>                )</pre><p>Then we find getDaemonConnectionImpl in GradleKotlinCompilerRunner.kt</p><pre>package org.jetbrains.kotlin.compilerRunner</pre><pre>/*<br>Using real taskProvider cause &quot;field &#39;taskProvider&#39; from type &#39;org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner&#39;:<br>value &#39;fixed(class org.jetbrains.kotlin.gradle.tasks.KotlinCompile_Decorated, task &#39;:compileKotlin&#39;)&#39;<br>is not assignable to &#39;org.gradle.api.tasks.TaskProvider&#39;&quot; exception<br> */<br>internal open class GradleCompilerRunner(<br>    protected val taskProvider: GradleCompileTaskProvider,<br>    protected val jdkToolsJar: File?,<br>    protected val compilerExecutionSettings: CompilerExecutionSettings,<br>    protected val buildMetrics: BuildMetricsReporter&lt;GradleBuildTime, GradleBuildPerformanceMetric&gt;,<br>    protected val fusMetricsConsumer: StatisticsValuesConsumer?,<br>) {<br></pre><pre>    companion object {<br>        @Synchronized<br>        internal fun getDaemonConnectionImpl(<br>            clientIsAliveFlagFile: File,<br>            sessionIsAliveFlagFile: File,<br>            compilerFullClasspath: List&lt;File&gt;,<br>            messageCollector: MessageCollector,<br>            daemonJvmArgs: List&lt;String&gt;?,<br>            isDebugEnabled: Boolean,<br>        ): CompileServiceSession? {<br>            val compilerId = CompilerId.makeCompilerId(compilerFullClasspath)<br>            val daemonJvmOptions = configureDaemonJVMOptions(<br>                inheritMemoryLimits = true,<br>                inheritOtherJvmOptions = false,<br>                inheritAdditionalProperties = true<br>            ).also { opts -&gt;<br>                if (!daemonJvmArgs.isNullOrEmpty()) {<br>                    opts.jvmParams.addAll(<br>                        daemonJvmArgs.filterExtractProps(opts.mappers, &quot;&quot;, opts.restMapper)<br>                    )<br>                }<br>            }</pre><p>Okay now we’re getting to the juicy bit where we are going to configure Kotlin JVM options to inherit Gradle or JVM memory limits and options.</p><pre>configureDaemonJVMOptions(<br>    inheritMemoryLimits = true,<br>    inheritOtherJvmOptions = false,<br>    inheritAdditionalProperties = true<br>)</pre><p>The above is an top level function in DaemonParams.kt. There&#39;s also the DaemonJVMOptions data class which is used to inherit JVM options, but only maxMemory, maxMetaspaceSize, and reservedCodeCacheSize. Now it makes perfect sense why I was seeing the behavior I was - but another surprise is the default value of 320m for -XX:ReservedCodeCacheSize. This seems fine to me as I&#39;ve been setting this value to 256m - 512m in my builds anyway, but I&#39;ll write an analysis on CodeCache JVM args another day. The rest of this code also explains a few of the other JVM args being added like -ea, but not all of them.</p><pre>package org.jetbrains.kotlin.daemon.common</pre><pre>data class DaemonJVMOptions(<br>        var maxMemory: String = &quot;&quot;,<br>        var maxMetaspaceSize: String = &quot;&quot;,<br>        var reservedCodeCacheSize: String = &quot;320m&quot;,<br>        var jvmParams: MutableCollection&lt;String&gt; = arrayListOf()<br>) : OptionsGroup {<br>    override val mappers: List&lt;PropMapper&lt;*, *, *&gt;&gt;<br>        get() = listOf(StringPropMapper(this, DaemonJVMOptions::maxMemory, listOf(&quot;Xmx&quot;), mergeDelimiter = &quot;&quot;),<br>                       StringPropMapper(this, DaemonJVMOptions::maxMetaspaceSize, listOf(&quot;XX:MaxMetaspaceSize&quot;), mergeDelimiter = &quot;=&quot;),<br>                       StringPropMapper(this, DaemonJVMOptions::reservedCodeCacheSize, listOf(&quot;XX:ReservedCodeCacheSize&quot;), mergeDelimiter = &quot;=&quot;),<br>                       restMapper)</pre><pre>    val restMapper: RestPropMapper&lt;*, *&gt;<br>        get() = RestPropMapper(this, DaemonJVMOptions::jvmParams)<br>}</pre><pre>// TODO: expose sources for testability and test properly<br>fun configureDaemonJVMOptions(opts: DaemonJVMOptions,<br>                              additionalParams: Iterable&lt;String&gt;,<br>                              inheritMemoryLimits: Boolean,<br>                              inheritOtherJvmOptions: Boolean,<br>                              inheritAdditionalProperties: Boolean<br>): DaemonJVMOptions {<br>    // note: sequence matters, e.g. explicit override in COMPILE_DAEMON_JVM_OPTIONS_PROPERTY should be done after inputArguments processing<br>    if (inheritMemoryLimits || inheritOtherJvmOptions) {<br>        val jvmArguments = ManagementFactory.getRuntimeMXBean().inputArguments<br>        val targetOptions = if (inheritMemoryLimits) opts else DaemonJVMOptions()<br>        val otherArgs = jvmArguments.filterExtractProps(targetOptions.mappers, prefix = &quot;-&quot;)</pre><pre>        if (inheritMemoryLimits) {<br>            if (opts.maxMemory.isBlank()) {<br>                val maxMemBytes = Runtime.getRuntime().maxMemory()<br>                // rounding up<br>                val maxMemMegabytes = maxMemBytes / (1024 * 1024) + if (maxMemBytes % (1024 * 1024) == 0L) 0 else 1<br>                opts.maxMemory = &quot;${maxMemMegabytes}m&quot;<br>            }<br>        }</pre><pre>        if (inheritOtherJvmOptions) {<br>            opts.jvmParams.addAll(<br>                otherArgs.filterNot {<br>                    it.startsWith(&quot;agentlib&quot;) ||<br>                            it.startsWith(&quot;D&quot; + CompilerSystemProperties.COMPILE_DAEMON_LOG_PATH_PROPERTY.property) ||<br>                            it.startsWith(&quot;D&quot; + CompilerSystemProperties.KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY.property) ||<br>                            it.startsWith(&quot;D&quot; + CompilerSystemProperties.COMPILE_DAEMON_JVM_OPTIONS_PROPERTY.property) ||<br>                            it.startsWith(&quot;D&quot; + CompilerSystemProperties.COMPILE_DAEMON_OPTIONS_PROPERTY.property)<br>                })<br>        }<br>    }<br>    CompilerSystemProperties.COMPILE_DAEMON_JVM_OPTIONS_PROPERTY.value?.let {<br>        opts.jvmParams.addAll(<br>                it.trimQuotes()<br>                  .split(&quot;(?&lt;!\\\\),&quot;.toRegex())  // using independent non-capturing group with negative lookahead zero length assertion to split only on non-escaped commas<br>                  .map { it.replace(&quot;\\\\(.)&quot;.toRegex(), &quot;$1&quot;) } // de-escaping characters escaped by backslash, straightforward, without exceptions<br>                  .filterExtractProps(opts.mappers, &quot;-&quot;, opts.restMapper))<br>    }</pre><pre>    // assuming that from the conflicting options the last one is taken<br>    // TODO: compare and override<br>    opts.jvmParams.addAll(additionalParams)</pre><pre>    if (inheritAdditionalProperties) {<br>        CompilerSystemProperties.COMPILE_DAEMON_LOG_PATH_PROPERTY.value?.let { opts.jvmParams.add(&quot;D${CompilerSystemProperties.COMPILE_DAEMON_LOG_PATH_PROPERTY.property}=\&quot;$it\&quot;&quot;) }<br>        CompilerSystemProperties.KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY.value?.let { opts.jvmParams.add(&quot;D${CompilerSystemProperties.KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY.property}&quot;) }<br>    }</pre><pre>    if (opts.jvmParams.none { it.matches(jvmAssertArgsRegex) }) {<br>        opts.jvmParams.add(&quot;ea&quot;)<br>    }<br>    return opts<br>}</pre><p>I found the rest of the JVM args were being set in KotlinCompilerClient.kt which also calls configureDaemonJVMOptions when the Kotlin Daemon is started. I&#39;m honestly not 100% sure how this gets invoked and didn&#39;t want to spend more time connecting the dots since I found what I was looking for.</p><pre>package org.jetbrains.kotlin.daemon.client</pre><pre>object KotlinCompilerClient {<br>    @JvmStatic<br>    fun main(vararg args: String) {<br>        val compilerId = CompilerId()<br>        val daemonOptions = configureDaemonOptions()<br>        val daemonLaunchingOptions =<br>            configureDaemonJVMOptions(inheritMemoryLimits = true, inheritOtherJvmOptions = false, inheritAdditionalProperties = true)<br></pre><pre>    internal data class GcAutoConfiguration(<br>        var shouldAutoConfigureGc: Boolean = true,<br>        val preferredGc: String = &quot;Parallel&quot;<br>    )</pre><pre>    private fun startDaemon(<br>        compilerId: CompilerId,<br>        daemonJVMOptions: DaemonJVMOptions,<br>        daemonOptions: DaemonOptions,<br>        reportingTargets: DaemonReportingTargets,<br>        startupAttempt: Int,<br>        gcAutoConfiguration: GcAutoConfiguration,<br>    ): Boolean {<br>        val javaExecutable = File(File(CompilerSystemProperties.JAVA_HOME.safeValue, &quot;bin&quot;), &quot;java&quot;)<br>        val serverHostname = CompilerSystemProperties.JAVA_RMI_SERVER_HOSTNAME.value<br>            ?: error(&quot;${CompilerSystemProperties.JAVA_RMI_SERVER_HOSTNAME.property} is not set!&quot;)<br>        val platformSpecificOptions = listOf(<br>            // hide daemon window<br>            &quot;-Djava.awt.headless=true&quot;,<br>            &quot;-D${CompilerSystemProperties.JAVA_RMI_SERVER_HOSTNAME.property}=$serverHostname&quot;<br>        )<br>        val javaVersion = CompilerSystemProperties.JAVA_VERSION.value?.toIntOrNull()<br>        val javaIllegalAccessWorkaround =<br>            if (javaVersion != null &amp;&amp; javaVersion &gt;= 16)<br>                listOf(&quot;--add-exports&quot;, &quot;java.base/sun.nio.ch=ALL-UNNAMED&quot;)<br>            else emptyList()<br>        val environmentVariablesForTests = getEnvironmentVariablesForTests(reportingTargets)<br>        val jvmArguments = daemonJVMOptions.mappers.flatMap { it.toArgs(&quot;-&quot;) }<br>        if (<br>            (jvmArguments + getImplicitJvmArguments(environmentVariablesForTests))<br>                .any { it == &quot;-XX:-Use${gcAutoConfiguration.preferredGc}GC&quot; || (it.startsWith(&quot;-XX:+Use&quot;) &amp;&amp; it.endsWith(&quot;GC&quot;)) }<br>        ) {<br>            // enable the preferred gc only if it&#39;s not explicitly disabled and no other GC is selected<br>            gcAutoConfiguration.shouldAutoConfigureGc = false<br>        }<br>        val additionalOptimizationOptions = listOfNotNull(<br>            &quot;-XX:+UseCodeCacheFlushing&quot;,<br>            if (gcAutoConfiguration.shouldAutoConfigureGc) &quot;-XX:+Use${gcAutoConfiguration.preferredGc}GC&quot; else null,<br>        )<br>        val args = listOf(<br>            javaExecutable.absolutePath, &quot;-cp&quot;, compilerId.compilerClasspath.joinToString(File.pathSeparator)<br>        ) +<br>                platformSpecificOptions +<br>                jvmArguments +<br>                additionalOptimizationOptions +<br>                javaIllegalAccessWorkaround +<br>                COMPILER_DAEMON_CLASS_FQN +<br>                daemonOptions.mappers.flatMap { it.toArgs(COMPILE_DAEMON_CMDLINE_OPTIONS_PREFIX) } +<br>                compilerId.mappers.flatMap { it.toArgs(COMPILE_DAEMON_CMDLINE_OPTIONS_PREFIX) }<br>        reportingTargets.report(DaemonReportCategory.INFO, &quot;starting the daemon as: &quot; + args.joinToString(&quot; &quot;))<br>        val processBuilder = ProcessBuilder(args)<br>        processBuilder.redirectErrorStream(true)<br>        processBuilder.environment().putAll(environmentVariablesForTests)<br>        val workingDir = File(daemonOptions.runFilesPath).apply { mkdirs() }<br>        processBuilder.directory(workingDir)<br>        // assuming daemon process is deaf and (mostly) silent, so do not handle streams<br>        val daemon = processBuilder.start()</pre><h3>What did we find?</h3><p>The Kotlin Daemon only inherits 3 specific JVM args from its parent VM (whether that is Gradle or something else) and ignores the rest. It also sets a bunch of defaults that are all good settings.</p><p>Inherited JVM args:</p><ul><li>-Xmx</li><li>-XX:MaxMetaspaceSize</li><li>-XX:ReservedCodeCacheSize (Defaults to 320m if not inherited and unspecified)</li></ul><p>Defaults:</p><ul><li>-XX:UseParallelGC</li><li>-ea</li><li>-XX:+UseCodeCacheFlushing</li><li>-XX:+HeapDumpOnOutOfMemoryError</li><li>-Djava.awt.headless=true</li><li>-D{hostname.property}={localhostip}</li><li>— add-exports=java.base/sun.nio.ch=ALL-UNNAMED (Only for JDK 16+)</li></ul><p>Since I was at DroidconNYC this past week I spot checked with various Android engineers, and only the Gradle engineers told me the correct behavior. I <a href="https://github.com/JetBrains/kotlin-web-site/pull/4454">updated the Kotlin Gradle JVM documentation</a> to fully explain the behavior happening under the hood. Therefore if you’re reading this its a good idea to check your settings, run <a href="https://visualvm.github.io/">VisualVM</a>, and verify that your intended settings are being applied appropriately.</p><h3>References:</h3><ol><li>KotlinLang Docs: Kotlin JVM args property <a href="https://kotlinlang.org/docs/gradle-compilation-and-caches.html#kotlin-daemon-jvmargs-property">https://kotlinlang.org/docs/gradle-compilation-and-caches.html#kotlin-daemon-jvmargs-property</a></li><li>KotlinLang Docs: Gradle daemon arguments inheritance <a href="https://kotlinlang.org/docs/gradle-compilation-and-caches.html#gradle-daemon-arguments-inheritance">https://kotlinlang.org/docs/gradle-compilation-and-caches.html#gradle-daemon-arguments-inheritance</a></li><li>KotlinLang Slack #gradle <a href="https://kotlinlang.slack.com/archives/C19FD9681/p1585046690028700">https://kotlinlang.slack.com/archives/C19FD9681/p1585046690028700</a></li><li>Kotlin source code <a href="https://www.github.com/JetBrains/kotlin/blob/master/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/PropertiesProvider.kt">https://www.github.com/JetBrains/kotlin/</a></li><li>Inherit max metaspace size of client VM for Kotlin compile daemon (Jul 25, 2019) <a href="https://github.com/JetBrains/kotlin/commit/f3112f752da28f233859fd95b3a86980951a4b8b">https://github.com/JetBrains/kotlin/commit/f3112f752da28f233859fd95b3a86980951a4b8b</a></li><li>Drop MaxPermSize support from compiler daemon (Jul 29, 2019) <a href="https://github.com/JetBrains/kotlin/commit/560f1483e8fa71b258e6cc205f200625f92736f5">https://github.com/JetBrains/kotlin/commit/560f1483e8fa71b258e6cc205f200625f92736f5</a><br>compiler/daemon/daemon-client/src/main/kotlin/KotlinCompilerDaemon.kt <a href="https://github.com/JetBrains/kotlin/blob/master/compiler/daemon/src/org/jetbrains/kotlin/daemon/KotlinCompileDaemon.kt">https://github.com/JetBrains/kotlin/blob/master/compiler/daemon/src/org/jetbrains/kotlin/daemon/KotlinCompileDaemon.kt</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e74a1e7a2b63" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Metaspace in JVM Builds]]></title>
            <link>https://medium.com/@kaeawc/metaspace-in-jvm-builds-0be283f4aa26?source=rss-176cd46cdccd------2</link>
            <guid isPermaLink="false">https://medium.com/p/0be283f4aa26</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[jvm]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[platform-engineering]]></category>
            <dc:creator><![CDATA[Jason Pearson]]></dc:creator>
            <pubDate>Tue, 24 Sep 2024 11:05:51 GMT</pubDate>
            <atom:updated>2024-09-24T11:05:51.015Z</atom:updated>
            <content:encoded><![CDATA[<p>This is a post in my JVM Args for Builds series where I break down how these settings effect JVM-based build systems. A number of these settings are complicated and all have compounding effects on each other as the JVM is a complex machine, but used the right way can be the difference between having a high-value feedback build system versus a high-cost one.</p><p>Metaspace can contribute significantly to the non-heap memory footprint. If you want to learn all the details of how it works I highly recommend <a href="https://stuefe.de/posts/metaspace/what-is-metaspace/?ref=jasonpearson.dev">Thomas Stüfe</a>‘s blog post series on the topic — I will only be covering the relevant details as they relate to JVM-based build systems, not JVM-based applications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1021/1*BQ5A-ccJfeYP842nyJs55A.png" /></figure><h3>TLDR;</h3><p>If you’re using Gradle:</p><ul><li>with JDK 17+, override Gradle’s JVM arg defaults and do not set -XX:MaxMetaspaceSize.</li><li>with JDK 16 or older, make sure to have XX:MaxMetaspaceSize set to prevent ClassLoader leaks from running wild. Measure your usage with jcmd &lt;PID&gt; VM.metaspace and read towards the end of this post to see an example.</li><li>-XX:MetaspaceSize should not be set for most projects - this governs when to trigger a garbage collection the first time it is exceeded. The defaults work well on this.</li></ul><p>If you’re in any other JVM build system, read the documentation but unless it has a default setting for -XX:MaxMetaspaceSize you likely don&#39;t need to do anything.</p><h3>The Story behind Metaspace in Gradle</h3><p>In my experience with Android projects and Gradle a number of memory settings have been shared in the community. I noticed a shift from MaxPermgenSize to MaxMetaspaceSize as the Android community moved from JDK 6 to JDK 8+, but I didn&#39;t understand at the time that there was an effort to replace PermGen with a new system and that the new system behaved entirely differently. Since that time Gradle introduced usage of the MaxMetaspaceSize in its default JVM args in 2018 to promote failing fast on memory leaks. The Android community was trying to adapt to ever larger codebases and since there aren&#39;t a lot of people reading JVM release notes, the popular consensus became that we needed to use the setting Gradle provided.</p><p>Unfortunately what got missed was that the Metaspace system was specifically designed to not have a limit imposed — that was actually the fundamental problem with PermGen where its size could not grow on-demand even if system resources were available. There was also no discussion about how MaxMetaspaceSize limits both non-class metadata and CompressedClassSpaceSize. Simultaneously the Metaspace system had become notorious for not returning unused memory back to the system and this issue wasn&#39;t addressed until Java 16, so it made a lot of sense at the time to limit Metaspace until various ClassLoader leaks were addressed, but so much time has passed that few in the Gradle community are considering removing the limit.</p><p>Another issue related to this is the awareness of how to apply JVM args correctly in Gradle builds. I’ve used other systems in the past (Maven, Ant) that didn’t support as much functionality but made such configuration settings simpler to apply. In recent years this got a lot easier and the knowledge is becoming more commonplace, but most engineers who work with Gradle as a build system remain unaware.</p><h3>Why is having a Metaspace limit bad?</h3><p>CompressedClassSpaceSize defaults to 1GB if CompressedClassPointers is enabled (which is it by default for JVM heaps under 32GB). If MaxMetaspaceSize is less than 1GB the JVM will use heuristics to determine how much to allocate. Compressed class pointers also reduce memory usage by allowing the JVM to represent class metadata with less memory.</p><p>So setting MaxMetaspaceSize has a few consequences:</p><ul><li>If we’re at the limit and the JVM has more class pointers to assign into memory it will OOM. Also the OOM will not reference Metadata but instead CompressedClassSpace.</li><li>If we’re at the limit and the JVM has more non-class metadata to write it will OOM on Metadata.</li></ul><p>If you’ve never run into this because your project isn’t too large, you don’t need to worry about this and continue happily with the defaults. But if you’ve got a few thousand classes and have started to see Caused by: java.lang.OutOfMemoryError: Metaspace you should keep reading.</p><h3>Metaspace Growth &amp; Implications</h3><p>First, let’s put into perspective why and when this will matter for a given codebase. Since we know we have two competing spaces in memory, let’s break down what each class roughly puts into them. If you’re seriously interested in more detail than this breakdown you can read JVM source code.</p><p>Class Space</p><ul><li>The Klass structure represents the fundamental metadata for the class in the JVM. It contains information about the class name, superclass, interfaces, fields, methods, and more.</li><li>vtable (virtual method table) holds pointers to the implementations of the class’s virtual methods and any inherited from its super class.</li><li>itable (interface method table) stores pointers to methods that implement interfaces.</li><li>The nonstatic ordinary object pointer map holds metadata about the instance fields of the class that are object references (non-primitive types).</li><li>Misc — additional internal JVM data structures, and padding for alignment.</li></ul><p>Non-Class Metadata</p><ul><li>The constant pool, which is variable sized.</li><li>Method metadata: bytecode, variable and exception tables, and more</li><li>Annotations</li></ul><p>I came across Thomas Stüfe’s blog posts and he has an excellent real world profiling example with <em>jcmd VM.metaspace</em> to get these results:</p><blockquote>For standard classes (assuming classes loaded by bootstrap and app loaders are considered standard), we come to an average of <strong>~5–7k</strong> of non-class space and <strong>600–900 bytes</strong> class space per class.</blockquote><blockquote>Anonymous (lambda) classes are much smaller, no surprise, but interestingly ratio between class and non-class space usage is also warped: we need much more class space in relation to non-class space. That is not surprising since Lambda classes are minuscule, but the overhead for the Klass structure cannot shrink below sizeof(Klass) structure itself. So, we come to about <strong>1k</strong> non-class space, <strong>.5k</strong> class space.</blockquote><p>Let’s take Thomas’s numbers (~5–7k non-class space, 600–900 bytes class space) and had the JVM defaults we would only be limited by CompressedClassSpaceSize and be able to run 1-1.5 million classes, which is definitely more code than I ever hope to write. However with a Gradle&#39;s current defaults setting MaxMetaspaceSize limit to 768MB and Thomas&#39;s estimate that 80% of that is given to CompressedClassSpaceSize, we are left with ~150MB for non-class metadata. That would mean a limit of 20k-30k classes - not an easy limit to hit but I&#39;m sure the larger and more complex Android apps are.</p><h3>Does this issue impact my codebase?</h3><p>We’ve learned that we can profile metaspace usage via <em>jcmd VM.metaspace</em>, but what does that look like practically?</p><p>For starters you can grab the PID from a running Gradle Daemon:</p><pre>GRADLE_PID=$(pgrep -f &#39;.*GradleDaemon.*&#39; | xargs -I{} ps -o pid= -o lstart= -p {} | sort -k2,3 | tail -n 1 | awk &#39;{print $1}&#39;) jcmd $GRADLE_PID VM.metaspace</pre><p>This is script will grab the latest Gradle Daemon PID, which for purposes of this analysis is fine. Don’t put this in production automations.</p><p>I’ve written a bash script that shows how to grab the PID from a running Gradle process. You should be able to apply this to other JVM-based build tools.</p><p>Running this against my <a href="https://github.com/kaeawc/android-build">android-build</a> repository during a clean build doesn’t indicate much metaspace usage, but since it’s literally an Android Studio starter wizard project that is expected.</p><p>However running against the <a href="https://github.com/android/nowinandroid?ref=jasonpearson.dev">NowInAndroid</a> codebase shows some interesting things right off the bat. At the time of writing it still has MaxMetaspace set to 1GB.</p><p>There’s a couple things to unpack from the resultant logs:</p><ul><li>CompressedClassSpace would normally default to 1 GB, but MaxMetaspaceSize limits the entire space and therefore CompressedClassSpace becomes 832 MB.</li><li>At the end of this build if we take a look at VirtualSpace and whats been committed we see 301.50 MB for non-class space (metaspace) and 43.06 MB for class space. CompressedClassSpace cannot change or grow, its at 832 MB. Everything has plenty of room, no OOM crash.</li></ul><p>What happens if I run the same build with drastically less MaxMetaspaceSize? Expectedly I saw an OOM crash and through a few iterations I found the minimum passing MaxMetaspaceSize of 160MB</p><p>What are the important differences?</p><p><strong>num_arena_births:</strong> This represents the number of times the JVM has created new “arenas” in the metaspace. Arenas are contiguous memory regions used by the JVM to manage Metaspace allocations. When the JVM needs more memory for class or non-class data, it creates a new arena (essentially reserving more memory from the OS).</p><p><strong>num_arena_deaths:</strong> This tracks how many arenas have been destroyed (or “died”) because they were no longer needed. This happens when the JVM releases memory back to the OS or frees up arenas that are no longer in use. Arena deaths typically occur after garbage collection if class loaders are unloaded and their associated metadata is no longer needed.</p><p><strong>num_chunks_returned_to_freelist:</strong> This number tells you how many chunks of memory have been returned to the freelist after being used and deallocated. Essentially, when the JVM no longer needs certain memory chunks, they are returned to the freelist, so they can be reused later.</p><p><strong>num_chunks_taken_from_freelist:</strong> This represents the number of chunks that have been reallocated from the freelist when the JVM needed to allocate new memory. Instead of asking the OS for new memory, the JVM reuses memory chunks from the freelist, reducing fragmentation and overhead.</p><p>1GB MaxMetaspace<strong>:</strong></p><ul><li>5480 loaders, 86611 classes (1455 shared)</li><li>num_arena_births: 9494</li><li>num_arena_deaths: 378</li><li>num_chunks_returned_to_freelist: 1088.</li><li>num_chunks_taken_from_freelist: 27040.</li></ul><p>160 MaxMetaspace:</p><ul><li>3587 loaders, 33850 classes (1438 shared)</li><li>num_arena_births: 7366.</li><li>num_arena_deaths: 192.</li><li>num_chunks_returned_to_freelist: 288.</li><li>num_chunks_taken_from_freelist: 16084.</li></ul><p>128 MaxMetaspace:</p><ul><li>2558 loaders, 27915 classes (1423 shared)</li><li>num_arena_births: 5116</li><li>num_arena_deaths: 0</li><li>num_chunks_returned_to_freelist: 12.</li><li>num_chunks_taken_from_freelist: 11256.</li></ul><p>After reducing the MaxMetaspaceSize the JVM loaded fewer classes, indicating that memory pressure led to class unloading or prevented further loading. Arena births reached 7366 in passing builds but could not reach that count before the OOM crash in builds using less than 160MB. We can see the failing one doesn’t return many chunks back to the freelist and that makes sense with high memory pressure on essential chunks.</p><p>We are able to confirm Thomas’s claim that 80% of MaxMetaspaceSize is reserved for CompressedClassSpace, but then the non-class metaspace is allowed to grow within the total maximum size to compete with it. When space runs out we observe the OOM, and since this is a small project without a lot going on its more easily reproducible on clean builds with no cache.</p><p>Let’s also check against Thomas’s rough estimates for class and non-class space on a per class basis. If we look at the number of classes referenced by the minimum passing build (33,850). Does the math match up?</p><p>600–900 byte class space size at 33,850 classes is 19MB — 29MB</p><p>5kb-7kb non-class space at 33,850 classes is 165MB — 231MB</p><p>Yup. So now we have an idea of the range of memory we need to provide to ensure this project passes. And now you know how to calculate this (roughly) for your project too.</p><h3>Build System Recommendations</h3><p>Metaspace varies a lot from project to project and setting an arbitrary limit can create GC pauses and unexpected OOMs that would confuse developers who think JVM heap, Metaspace, and Codecache are all shared.</p><p>If you’re an Android developer using AGP 8.5.0 or higher you are required to be using JDK 17, so my recommendation is try not setting -XX:MaxMetaspaceSize in build system JVM args. Specifically for Gradle that means you should override its defaults and not set anything for -XX:MaxMetaspaceSize. The only performance improvement by adding a setting is found through -XX:MetaspaceSize which will allow your build to skip growing Metaspace. You should figure out what to set that to based on profiling your build with jcmd VM.metaspace [[10]] and observing the peak usage.</p><p><strong>Update:</strong> <a href="https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html?ref=jasonpearson.dev#BABFAFAE">JVM docs definition for `-XX:MetaspaceSize`</a></p><blockquote>Sets the size of the allocated class metadata space that will trigger a garbage collection the first time it is exceeded. This threshold for a garbage collection is increased or decreased depending on the amount of metadata used. The default size depends on the platform.</blockquote><p>Therefore we really shouldn’t be setting this and allow the JVM to perform GC at regular healthy intervals in metaspace to remove unused references.</p><p>If you’re not using JDK 17+ or a recent version of Gradle you may still be suffering from ClassLoader leak bugs and it still makes sense to have -XX:MaxMetaspaceSize set, but add a TODO to upgrade your JDK and remove this setting eventually when you&#39;ve been able to confirm the issue is resolved. Your build system and fellow teammates will thank you for a better and more reliable developer experience.</p><p>If you’re not an Android developer you probably still use some framework. Spring is super common in JVM backend systems and it also usually is built with a sizable list of dependencies. The above recommendations likely apply to you, especially if you’re using Gradle to run your builds.</p><p>You could also go further and monitor jcmd VM.metaspace output for the committed class and non-class space in a build. I&#39;ll cover how to set that up properly in another blog post.</p><h3>Thank You</h3><p>Zac Sweers, Nicklas Ansman, and Inaki Villar for the reviews and kind encouragement!</p><h3>References</h3><ol><li>Red Hat JVM Engineer, OpenJDK contributor <a href="https://stuefe.de/about/">https://stuefe.de/about/</a></li><li>“What is Metaspace?” by Thomas Stüfe <a href="https://stuefe.de/posts/metaspace/what-is-metaspace/">https://stuefe.de/posts/metaspace/what-is-metaspace/</a></li><li>“JEP-122: Remove the Permanent Generation” <a href="https://openjdk.org/jeps/122">https://openjdk.org/jeps/122</a></li><li>“Lower default memory limits for Gradle processes” <a href="https://github.com/gradle/gradle/pull/7343">https://github.com/gradle/gradle/pull/7343</a></li><li>StackOverflow — Gradle Engineer recommends Gradle defaults <a href="https://stackoverflow.com/questions/54045132/after-upgrading-to-gradle-5-and-android-plugin-3-3-my-build-fails-with-metaspa">https://stackoverflow.com/questions/54045132/after-upgrading-to-gradle-5-and-android-plugin-3-3-my-build-fails-with-metaspa</a></li><li>“Garbage Collection in Java” by Java Latte <a href="https://java-latte.blogspot.com/2013/08/garbage-collection-in-java.html">https://java-latte.blogspot.com/2013/08/garbage-collection-in-java.html</a></li><li>“JEP 387: Elastic Metaspace” — Proposal for Returning Memory <a href="https://openjdk.org/jeps/387">https://openjdk.org/jeps/387</a></li><li>“What is Compressed Class Space?” by Thomas Stüfe <a href="https://stuefe.de/posts/metaspace/what-is-compressed-class-space/">https://stuefe.de/posts/metaspace/what-is-compressed-class-space/</a></li><li>JDK11 Source Code: Memory Allocation Structs in Metaspace <a href="https://hg.openjdk.org/jdk/jdk11/file/1ddf9a99e4ad/src/hotspot/share/memory/allocation.hpp#l239">https://hg.openjdk.org/jdk/jdk11/file/1ddf9a99e4ad/src/hotspot/share/memory/allocation.hpp#l239</a></li><li>“Analyzing Metaspace with jcmd” by Thomas Stüfe <a href="https://stuefe.de/posts/metaspace/analyze-metaspace-with-jcmd">https://stuefe.de/posts/metaspace/analyze-metaspace-with-jcmd</a></li><li>“Sizing Metaspace: Metaspace default size” by Thomas Stüfe <a href="https://stuefe.de/posts/metaspace/sizing-metaspace/#metaspace-default-size">https://stuefe.de/posts/metaspace/sizing-metaspace/#metaspace-default-size</a></li><li>Java Platform, Standard Edition Tools Reference <a href="https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html#BABFAFAE">https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html#BABFAFAE</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0be283f4aa26" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Designing Interviews — Scaling Startup looking for Experience]]></title>
            <link>https://medium.com/@kaeawc/designing-interviews-scaling-startup-looking-for-experience-7afd5da4acdd?source=rss-176cd46cdccd------2</link>
            <guid isPermaLink="false">https://medium.com/p/7afd5da4acdd</guid>
            <category><![CDATA[soft-skills]]></category>
            <category><![CDATA[interviews-and-insights]]></category>
            <dc:creator><![CDATA[Jason Pearson]]></dc:creator>
            <pubDate>Tue, 24 Sep 2024 04:15:53 GMT</pubDate>
            <atom:updated>2024-09-24T04:15:53.704Z</atom:updated>
            <content:encoded><![CDATA[<h3>Designing Interviews — Scaling Startup looking for Experience</h3><p>Designing Interviews is a series that looks at different stages of tech companies from initial founding all the way up to unicorn size.</p><p>This article focuses on the context of a scaling tech startup. Generally the ambition for such a company is to grow while maintaining the iteration speed and culture that has allowed it to find its product market fit. This is a difficult process because the faster you grow the more time existing employees have to spend onboarding, teaching, and learning from new hires — but there is also an existential need to gain experience to solve business, product, and technical hurdles.</p><p>Designing and running an effective interview pipeline is hard. The goal is to create a balanced, thoughtful process that attracts the right talent, keeps candidates engaged, and sets them up for success once hired. That takes considerable continuous effort, but as long as you keep your situation and values in mind it can work. If this situation speaks to you and you’re looking for help, feel free to <a href="https://www.jasonpearson.dev/consulting/">reach out</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*G70kF_OQ3sJpmpvS" /><figcaption>Photo by <a href="https://unsplash.com/@neom?utm_source=medium&amp;utm_medium=referral">NEOM</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Imagining a Startup</h3><p>When designing an interview pipeline, the first step is to assess where your business stands today. For the purposes of this post let’s imagine a startup called Xazzy that wants to save the world with more Jazz music — the founder fell in love with Jazz at an early age and it has always improved her mood. Getting more people listening to it, writing and playing jazz, sharing it just brings joy to everyone. Xazzy found product market fit by selling their system for use in elevators, waiting rooms, lobbies, etc.</p><p>They’re gearing up to scale but haven’t gone through a rapid growth phase before. They’ve built their engineering team through job postings and investor networks but lack experience hiring for senior roles, particularly in areas outside their expertise, like large-scale production environments. Due to that lack of experience there are some challenges like outages around releases that are affecting customer satisfaction and could brand reputation at risk if they continue.</p><p>Let’s round out this scenario:</p><ul><li>Mission: Save the world with more Jazz music</li><li>Values: Joy, Reliability, Compassion, Ownership</li><li>Team composition: A solid team of mid-senior engineers but very few with production experience at serious scale.</li><li>Challenges: Release-related outages and increasing demand for scalability, which necessitates more frequent releases.</li></ul><p>Sounds like Xazzy needs to improve stability and engineering maturity. They also need to speed up product iteration while protecting a positive reputation.</p><h3>Realizing we need more experience</h3><p>Looking at the goals, from a technical standpoint stabilizing their backend infrastructure and raising the engineering bar seems worthwhile. Let’s assume we confirm that with engineering and get alignment that a senior or staff-level backend engineer with experience in Go and scaling large systems would be the most immediate and impactful hire. Now, the question is: how do we interview someone who is beyond our own individual experience?</p><p>Its likely that among the shared experience of the existing team you have some talented and valuable people or Xazzy wouldn’t have gotten this far. So part of the process needs to lean on their strengths while learning through doing. Thoughtful feedback is the best way to ensure your team is learning as much as possible, so paving the road and incentivizing it can be worthwhile. Pairing up to do interviews can help build confidence, mitigate individual biases, and ensure there is always a notetaker.</p><p>This situation speaks to the need to not just have a well thought out plan for the interview pipeline but also to invest in <a href="https://interviewing.io/blog/the-other-half-or-why-interviewers-aren-t-always-great-and-how-to-make-them-better?ref=jasonpearson.dev">training your team to be good interviewers</a>. Incentivizing and rewarding the ones who are eager to grow their interviewing skills will get you better calibrated interviewers. 2 The very <a href="https://interviewing.io/blog/we-have-the-best-technical-interviewers-heres-how-we-do-it?ref=jasonpearson.dev">best interviewers will stand out in their ability to help the candidate showcase their skills</a>.</p><h3>Job Description</h3><p>Writing a good job description and title for the intended role helps attract good candidates. <a href="https://interviewing.io/blog/how-to-write-good-job-descriptions?ref=jasonpearson.dev">It doesn’t do much to weed out spam and therefore I wouldn’t be concerned with putting effort into it with that goal in mind</a>. Here’s my list of things to check:</p><ul><li>Would my prospective candidate be searching for the job title I’m leading with?</li><li>How can I quickly interest them that this is a good place to work and they’ll have the outcomes they want? <a href="https://interviewing.io/blog/3-exercises-to-create-the-kind-of-employer-brand-that-actually-makes-engineers-want-to-work-for-you?ref=jasonpearson.dev">Investing in the copy about the company’s brand here actually matters</a>.</li><li>What is the candidate going to work on? People want to know what is expected of them.</li><li>Requirements — make sure they’re actually requirements and they’re realistic. 20 years of Go experience simply doesn’t exist yet, and years of experience is a very rough filter. Add qualifiers like production experience to indicate what you’re really after. <a href="https://interviewing.io/blog/best-technical-interviews-common?ref=jasonpearson.dev">The best requirements are exciting to the best people for the job</a>.</li><li>Benefits — don’t make it a mystery whether you do or don’t have benefits. Hiding the lack of benefits will always lead to resentment, and omitting them when you do offer them misses a chance to build excitement. 10% 401k matching? Amazing. 20 weeks of paternity leave — wow that place cares about it’s people. Xazzy doesn’t have that but it offers free Jazz lessons in the office with local bands.</li></ul><h3>Designing the Interview Loop</h3><p>Xazzy has started to get a few resumes sent in and we’ve got to assess candidates promptly in order to grab the right talent. What kinds of interviews should they do?</p><p>My evergreen post <a href="https://www.jasonpearson.dev/software-engineer-interview-examples/">“Software Engineer Interview Examples”</a> covers a wide variety of interviews we can use in this loop.</p><p>While it might be tempting to cover all the bases with multiple rounds of interviews, keep in mind that every additional step risks alienating talented candidates. Skilled candidates often prefer shorter and more focused interview loops. They also appreciate transparency and being able to ask questions to understand the company better, so its in the company’s best interest to allot time for that. Its also great to send out or even publish information publicly on how you interview — Block has had a <a href="https://developer.squareup.com/blog/pair-programming-interviews/?ref=jasonpearson.dev">few</a> <a href="https://developer.squareup.com/blog/pair-programming-interviews-part-ii/?ref=jasonpearson.dev">engineers</a> <a href="https://developer.squareup.com/blog/ace-the-square-pairing-interview/?ref=jasonpearson.dev">write</a> about their experiences and published <a href="https://developer.squareup.com/blog/squares-updated-growth-framework-for-engineers-and-engineering-managers/?ref=jasonpearson.dev">information about levels</a>. A number of companies’ interview processes are written about at <a href="https://interviewing.io/topics?ref=jasonpearson.dev#companies">interviewing.io</a> including Google, Meta, Netflix, Apple… but part of Xazzy’s appeal is its not a huge tech company, so it should stick with a short loop that evaluates what it values most.</p><p>After workshopping with the team Xazzy decides it really needs an engineer with good system design, a match for its fun jazz culture, a solid coder, someone who has a proven track record of solid execution. They also want to balance how long the interview loop is, so they decide to start with:</p><ul><li>15–20 min casual conversation</li><li>Take home assignment that use’s Xazzy’s REST API to mix and play jazz styles and stream some audio.</li><li>60 min system design (10 minutes for questions)</li><li>45 min culture interview (10 minutes for questions)</li></ul><p>After running with this on a few candidates they <a href="https://interviewing.io/blog/why-engineers-dont-like-take-homes-and-how-companies-can-fix-them">find a lot of candidates dropping off on the take home assignment</a>. There are so many <a href="https://hbr.org/2019/05/your-approach-to-hiring-is-all-wrong?ref=jasonpearson.dev">good</a> <a href="https://hbr.org/2022/06/10-red-flags-to-watch-out-for-in-a-job-interview?ref=jasonpearson.dev">articles</a> that consistently point to measuring the process and re-evaluating against the results. So Xazzy changes it up:</p><ul><li>15–20 min casual conversation</li><li>45 min live coding pair programming against Xazzy’s REST API</li><li>45 min system design (10 minutes for questions)</li><li>45 min culture interview (10 minutes for questions)</li></ul><h3>Closing</h3><p>Once you’ve found a strong experienced candidate that matches what you want, move swiftly to close. It’s essential to keep communication clear and move the process forward smoothly. Long, drawn-out negotiations or delays can cause candidates to lose interest or accept other offers.</p><p>Xazzy found a great backend engineer that passed its interview loop and is excited to join. It’s their first time working for a startup and they’re coming from a more established company. The founder takes some time to get on a call with them and tell them about their vision and why this engineer is going to have great impact. She talks about the challenges she sees on the horizon as well as ambitions.</p><p>Every company’s situation is different, but the more transparency you offer prospective candidates, the more likely they are to trust you.</p><h3>Onboarding</h3><p>Finally, onboarding is critical. Provide the new hire with the necessary tools — both technical and cultural — to succeed. This includes setting them up with their equipment, documentation, and meeting schedules. Have a plan for their first day, week, and month and make sure they’re aware of it. The faster they feel comfortable and prepared, the faster they can start contributing to the business. Common pitfalls are:</p><ul><li>Delays in ordering a work machine, or having it specced incorrectly. Hash this out the day they accept the offer.</li><li>Background check verification. Some companies require this; make sure the candidate is aware before they sign an offer.</li><li>Missing onboarding documentation — where are the data and tools they need to do their job? The more they are provided with the better.</li><li>No introduction — make a public announcement about the new hire where other team members can see it. Setup meetings with their peers. This is crucial for remote employees where social expectations can be unclear.</li></ul><p>By structuring the interview pipeline with these stages, you’ll be able to hire the right senior talent, stabilize your infrastructure, and continue scaling your company with a strong and collaborative team.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7afd5da4acdd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Giving Conference Talks]]></title>
            <link>https://medium.com/@kaeawc/giving-conference-talks-d8faef914dc8?source=rss-176cd46cdccd------2</link>
            <guid isPermaLink="false">https://medium.com/p/d8faef914dc8</guid>
            <category><![CDATA[speaking]]></category>
            <category><![CDATA[conference]]></category>
            <category><![CDATA[presentations]]></category>
            <category><![CDATA[tech-talk]]></category>
            <category><![CDATA[soft-skills]]></category>
            <dc:creator><![CDATA[Jason Pearson]]></dc:creator>
            <pubDate>Tue, 24 Sep 2024 04:07:02 GMT</pubDate>
            <atom:updated>2024-09-24T04:07:40.471Z</atom:updated>
            <content:encoded><![CDATA[<p>Over the past few years, peers have increasingly asked me for advice on giving talks at conferences. I’m writing down my thoughts in hopes that others can benefit from my experience, much like I’ve learned from others before me.</p><p>When I began presenting, I relied heavily on a template I’ve refined over the years. As I’ve given more talks, I’ve noticed recurring themes in what I wanted my audience to take away. The way I design my slides is directly tied to ensuring these themes are clear and impactful. My approach has been inspired by many sources, but most notably Jake Wharton’s <a href="https://jakewharton.com/the-conference-speaker-investment/?ref=jasonpearson.dev"><em>The Conference Speaker Investment</em></a>. Some of the principles I’ll outline here are adapted from his guidance because it’s still very practical and effective.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i2WNzmwzIEyrKlS_5XvznQ.png" /><figcaption>My first Droidcon talk in 2019</figcaption></figure><h3>Finding Inspiration</h3><p>Beyond Jake there are a <a href="https://www.youtube.com/watch?v=SIr7mcnVy98&amp;ref=jasonpearson.dev">ton</a> of <a href="https://www.youtube.com/watch?v=JPaUjXzhuMA&amp;ref=jasonpearson.dev">speakers</a> <a href="https://www.youtube.com/watch?v=r8cYDlBOPaA&amp;ref=jasonpearson.dev">who</a> have <a href="https://www.youtube.com/watch?v=YZstpc2939s&amp;ref=jasonpearson.dev">inspired</a> <a href="https://www.droidcon.com/2022/06/28/solid-modularization-untangling-the-dependency-graph/?ref=jasonpearson.dev">me</a> over the years. Their charisma, storytelling, and stunning visual aids all shaped how I present. Pay attention to what you observe other speakers do well — and what they don’t. Learning from both will refine your approach. And if you get the chance, talk with your role models. Odds are they would be more than happy to open up about their experiences and challenges.</p><h3>Understanding the Audience’s Mindset</h3><p>Imagine attending a technical conference for the first time. You’ve registered, grabbed a coffee, and decided to check out some talks. You’re browsing the schedule, spotting a few titles that look interesting, and you walk into one of the sessions. You may not know the speaker or be fully familiar with the topic, but you’re curious.</p><p>This is the typical audience mindset when they enter your session. Your job as a speaker is to engage and relate to this curiosity. Whether they are beginners or have a passing familiarity with the subject, you want to ensure they find your talk accessible and relevant from the very start.</p><h3>The Hook</h3><p>Therefore your first few minutes should be dedicated to putting a hook in your audience. They will quickly decide whether they are invested in your talk or if they’ll mentally check out. Don’t waste time on too much background or trivial details — get to the point where your audience understands, “This is relevant to me!” quickly.</p><p>Some helpful questions to answer for the audience:</p><ul><li>“How does this apply to me?”</li><li>“Will I be able to try out what they’re talking about today?”</li><li>“Is this person credible? Do they know what they’re talking about?”</li></ul><h3>Finding Inspiration</h3><p>I’ve been inspired by numerous speakers over the years, not just for their technical depth, but for how they present ideas with charisma, storytelling, and stunning visual aids. Watching these great talks has shaped how I present. Pay attention to what other speakers do well — and what they don’t. Learning from both will refine your approach.</p><h3>Readability Matters</h3><p>Design your slides with the back-half rows in mind. Use the largest font possible to ensure everyone can see. Avoid text-heavy slides; instead, ask yourself if an illustration or video would communicate your point more clearly. And be mindful of the layout. Sometimes, using every bit of screen space can lead to important content being blocked by the audience’s heads. Designing with these constraints often improves clarity and keeps your audience more engaged. I set a guideline in Keynote roughly 1/3 from the bottom and attempt to keep important content above that.</p><h3>Progress Markers</h3><p>For longer, in-depth talks, it helps to provide progress markers. These serve as checkpoints for your audience, helping them understand where they are in the presentation and what’s coming next. Ideally, this aligns with the agenda you set out at the start. Progress transitions are especially useful when shifting between different concepts, ensuring the audience stays with you.</p><p>If your talk involves solving multiple sub-problems, wrap up each section with a summary before moving on.</p><h3>Ruthlessly Cut</h3><p>If your talk has more than 100 slides or runs close to the full time limit during practice, consider cutting content. Not every slide is critical. Remember, the audience won’t leave with the same depth of understanding as you — they’ll take away key insights, ideas, and inspiration. Focus on those, and cut what’s unnecessary.</p><p>Be cautious with animations. Too much movement can distract the audience away from you and your content. Try to only use animation to clarify connections between ideas and keep it subtle.</p><p>If you find yourself wanting to tangent in your explanation, consider whether it is a necessary technical hurdle, or is it something that could be skipped in favor of a more streamlined story?</p><h3>Speaking</h3><p>Once you get on stage, make sure your audience knows who you are. Even if your talk’s content is amazing, one of your goals should be that the audience remembers you.</p><p>Rehearse enough that your delivery feels natural and you’re confident in your timing. This will help you stay on track and avoid running over, while making your talk more fluid and engaging. It is a lot easier to understand a speaker who talks at a comfortable pace than one who is rushed.</p><h3>Takeaways</h3><p>Here’s a summary of the most impactful recommendations:</p><ul><li>Understand your audience’s mindset: They’re curious but not deeply familiar with your topic. Make your content accessible and relevant quickly.</li><li>Create a strong hook: Capture attention in the first two minutes by showing why your talk matters.</li><li>Focus on readability: Use large fonts and avoid text-heavy slides. Opt for illustrations and videos when possible.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d8faef914dc8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android App Bundle Crashing on ResourceNotFound]]></title>
            <link>https://medium.com/@kaeawc/android-app-bundle-crashing-on-resourcenotfound-17f3a63d18e3?source=rss-176cd46cdccd------2</link>
            <guid isPermaLink="false">https://medium.com/p/17f3a63d18e3</guid>
            <category><![CDATA[bugs]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[crash]]></category>
            <dc:creator><![CDATA[Jason Pearson]]></dc:creator>
            <pubDate>Tue, 24 Sep 2024 04:05:37 GMT</pubDate>
            <atom:updated>2024-09-24T04:05:37.677Z</atom:updated>
            <content:encoded><![CDATA[<p>Android App Bundle has been a required format for Play Store app uploads for years now, but there is still an important gotcha that requires special handling. When a user restores a backup or sideloads an APK that was derived from the AAB format, that APK might not have the resources intended for their new device.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EPBki939vx6PQKEkByKJng.png" /></figure><p>Let’s walk through an example. The user downloads the app on their phone, and some time passes. They decide to upgrade their phone to one with better specs. The APK downloaded to their old phone only has xhdpi resources and their new phone has a higher DPI density which makes it expect xxhdpi resources. When they restore a backup of the APK to their new phone it crashes on attempting to load any density based resource.</p><p>Another example is for apps that have put in the work to translate their experience into other languages. If you ship an AAB that allows splits on translations and the user changes their app specific or system language, the app will crash on attempting to load such resources.</p><p>Generally user experiencing this would never use the app again since the crash happens on app start and is reproducible even after wiping local application data. They wouldn’t necessarily think to uninstall and reinstall to fix the issue, which is actually the only resolution from this state. Therefore we wrote a simple runtime check to be used before starting our single Activity.</p><pre>fun canLoadResources(@DrawableRes resourceId: Int): Boolean {<br>    val result = try {<br>        ContextCompat.getDrawable(baseContext, resourceId)<br>    } catch (ex: Exception) {<br>        null<br>    }</pre><pre>    return result != null<br>}</pre><p>Therefore we wrote a couple lines of code that would just redirect them to a different Activity.</p><p>We also want to immediately redirect the user to a different Activity that never makes use of any resources that could be split for a particular APK. Regardless of launchMode, using the following combination of Intent flags should ensure we leave no chance of any remaining separate Activity.</p><pre>fun redirectToInvalidApkScreen() {<br>    startActivity(<br>        Intent(baseContext,<br>        InvalidApkActivity::class.java).apply {<br>            flags = Intent.FLAG_ACTIVITY_NEW_TASK or<br>                    Intent.FLAG_ACTIVITY_CLEAR_TASK<br>        }<br>    )<br>}</pre><p>Where should we add this check and redirect? In our experience the user typically encounters this type of crash in the launcher activity’s onCreate method:</p><pre>class MainActivity : AppCompatActivity() {</pre><pre>    override fun onCreate(savedInstanceState: Bundle?) {<br>        setTheme(co.hinge.common.design.resources.R.style.HingeTheme)<br>        super.onCreate(savedInstanceState)</pre><pre>+        if (!canLoadResources(R.drawable.example_drawable)) {<br>+            redirectToInvalidApkScreen()<br>+            return<br>+        }</pre><pre>        setContentView(ui.root)<br>    }</pre><pre>}</pre><p>Assuming you’ve written InvalidApkActivity in a way that doesn&#39;t use resources you never have to think about this issue again.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17f3a63d18e3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fixing a crash in ViewGroup offsetRectBetweenParentAndChild]]></title>
            <link>https://medium.com/@kaeawc/fixing-a-crash-in-viewgroup-offsetrectbetweenparentandchild-f988a9429f15?source=rss-176cd46cdccd------2</link>
            <guid isPermaLink="false">https://medium.com/p/f988a9429f15</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[bugs]]></category>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[crash]]></category>
            <dc:creator><![CDATA[Jason Pearson]]></dc:creator>
            <pubDate>Tue, 24 Sep 2024 04:03:49 GMT</pubDate>
            <atom:updated>2024-09-24T04:03:49.791Z</atom:updated>
            <content:encoded><![CDATA[<p>I was a tracking an originally low volume bug for about 6 months that gradually worked its way into our top crashes. The stacktrace had the clue all along but I kept missing what it was pointing out.</p><pre>android.view.ViewGroup.offsetRectBetweenParentAndChild (ViewGroup.java:6296)<br>android.view.ViewGroup.offsetDescendantRectToMyCoords (ViewGroup.java:6225)<br>com.android.internal.view.RecyclerViewCaptureHelper.onScrollRequested (RecyclerViewCaptureHelper.java:114)<br>com.android.internal.view.RecyclerViewCaptureHelper.onScrollRequested (RecyclerViewCaptureHelper.java:42)<br>com.android.internal.view.ScrollCaptureViewSupport.onScrollCaptureImageRequest (ScrollCaptureViewSupport.java:253)<br>android.view.ScrollCaptureConnection.lambda$requestImage$1$android-view-ScrollCaptureConnection (ScrollCaptureConnection.java:149)<br>android.view.ScrollCaptureConnection$$ExternalSyntheticLambda4.run (Unknown Source:6)<br>android.os.Handler.handleCallback (Handler.java:942)</pre><p>The first place I started looking was around ViewGroup.offsetRectBetweenParentAndChild, which used to have issues many years ago in early Android days. Along the way I found a reference to [a race condition between physical trackball and IME keyboard], a <a href="http://www.cnblogs.com/monodin/p/3675040.html?ref=jasonpearson.dev">blog post by a Chinese developer who uncovered a bug in ViewGroup&#39;s source code</a>. This behavior was fixed in Android 16 (and still has comments in AndroidX RecyclerView source today). Because these issues were so old but seemingly had established fixes I was confused as to how the behavior referenced could be happening today, and specifically <em>only on Android 13</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/294/0*rbPwSeaILo5NTHYk.png" /></figure><p>I finally was about to throw in the towel and put on a blanket fix using <a href="https://developer.android.com/reference/android/view/ViewGroup?ref=jasonpearson.dev#FOCUS_BEFORE_DESCENDANTS">android:descendantFocusability=”beforeDescendants”</a>, but then I looked at the stack trace one more time. I read each line and classname and looked up each one until I got to ScrollCaptureViewSupport, whose source I&#39;ve never read before, but I immediately connected it with why we would only see this crash on Android 13 - because it is a feature introduced in Android 13 to capture scrolling screenshots.</p><p>I made a simple reproduction app and had success reproducing the crash with these steps:</p><ol><li>The list must have a focusable element that the user interacts with for it to gain focus.</li><li>That view gains focus</li><li>The user scrolls away from the focused view</li><li>The user opens the soft keyboard (in Chat this means tapping on message composition EditText</li><li>The user takes a screenshot</li><li>The user chooses “Capture More”</li></ol><p>Now that I had clear STR, I attempted a fix that was mentioned in a <a href="https://stackoverflow.com/questions/7100555/preventing-catching-illegalargumentexception-parameter-must-be-a-descendant-of?ref=jasonpearson.dev">a very old question post</a>. Funny enough the answer is from October 2022, and it makes sense — get the window’s currently focused item and clear it before attempting to show the keyboard after Android 13 was released.</p><p>Therefore I’m reworking our keyboard extensions to ensure we do clear focus whenever requesting to show the keyboard. We cleaned up some deprecated code along the way and removed android:focusable=&quot;true&quot; where it wasn&#39;t needed.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f988a9429f15" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android App Bundle & Google App Signing]]></title>
            <link>https://medium.com/@kaeawc/android-app-bundle-google-app-signing-77fec44ed678?source=rss-176cd46cdccd------2</link>
            <guid isPermaLink="false">https://medium.com/p/77fec44ed678</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[google]]></category>
            <dc:creator><![CDATA[Jason Pearson]]></dc:creator>
            <pubDate>Tue, 24 Sep 2024 04:02:01 GMT</pubDate>
            <atom:updated>2024-09-24T04:02:01.359Z</atom:updated>
            <content:encoded><![CDATA[<p>Google announced over in 2020 that all new apps will be required to upload the AAB format and <a href="https://android-developers.googleblog.com/2021/06/the-future-of-android-app-bundles-is.html?ref=jasonpearson.dev">gave it a hard deadline of August 2021</a>. There were a lot of opinions at the time about the ramifications and I wanted to take the opportunity to analyze what AAB and Google App Signing each do and how they impact each other, end users, and developers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KxVc5zzl1ouWCDcEZXCW4w.png" /></figure><h3>AAB Format</h3><p>To start — <a href="https://developer.android.com/platform/technology/app-bundle?ref=jasonpearson.dev">AAB</a> is a format that lets Google Play and potentially other Android distribution platforms know how to split up your universal APK into the specific slice any given user needs. This results in smaller APKs, optimizations like shared native libraries, and the ability to dynamically deliver parts of an app. It does this using the open sourced <a href="https://github.com/google/bundletool?ref=jasonpearson.dev">bundletool</a>. You can use it to bundle and then extract the split APKs or you can run the assembleBundle Gradle task and upload the resulting AAB file to however many stores you want to publish to. So how does the format lock anyone in?</p><p>The controversial part of the AAB format is all about <a href="https://developer.android.com/studio/publish/upload-bundle?ref=jasonpearson.dev">the signing requirement</a>.</p><blockquote>If you build and upload an Android App Bundle, you must enroll in app signing by Google Play.</blockquote><h3>Store App Signing</h3><p>This allows Google to have a copy of your private keystore so that it can reassemble and sign your app to distribute. This is required in order to operate on the AAB format.</p><p>Should you let Google generate the original signing key and not have a copy for yourself? That seems like a silly option and its strange that it is the default — though it does make sense as it is easier for brand new Android developers who aren’t familiar with the keystore creation process. But the downside of that option is it prevents publishing an app with the same signature across multiple stores — I know very few places that do this. My viewpoint is American and Google Play Store centric, so take that with a grain of salt.</p><p>What are the benefits?</p><p>In terms of risk mitigation — I’ve seen original private keys lost on several projects (and also seen posts on <a href="https://www.reddit.com/r/androiddev/?ref=jasonpearson.dev">/r/androidev</a> about it) — which is a crazy gotcha when getting started as an Android developer.</p><p>For users it enables all of the optimizations and dynamic delivery features that Google has been pushing with the AAB format: dramatically smaller file sizes simply make the Android ecosystem a faster and more accessible experience.</p><h3>Future</h3><p>Huawei already supported <a href="https://developer.huawei.com/consumer/en/codelab/AppBundle/index.html?ref=jasonpearson.dev#0">AAB</a> &amp; <a href="https://developer.huawei.com/consumer/en/doc/development/AppGallery-connect-Guides/agc-app_bundle?ref=jasonpearson.dev">app signing</a>[1] as of mid-2021. You’re probably going to see other stores support AAB &amp; store app signing eventually. Even in such a world it doesn’t seem like any of this is actually platform lock-in — as long as we all keep our original private keys and consistently use them in the different stores. Otherwise yeah our apps will have different signatures on different stores, which would prevent an end user from downloading/upgrading your app from a store if they already have it installed from another store — which sounds only slightly annoying and just a couple more 1 star reviews in the endless tide.</p><p>1: <a href="https://www.reddit.com/r/androiddev/comments/h8cv3v/google_play_store_will_make_app_bundles_a/fuqeykd?utm_source=share&amp;utm_medium=web2x">Thanks to /u/_ALH_ for pointing out Huawei already implemented app signing.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=77fec44ed678" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android Tests]]></title>
            <link>https://medium.com/@kaeawc/android-tests-09dff7efd7be?source=rss-176cd46cdccd------2</link>
            <guid isPermaLink="false">https://medium.com/p/09dff7efd7be</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[testing]]></category>
            <dc:creator><![CDATA[Jason Pearson]]></dc:creator>
            <pubDate>Tue, 24 Sep 2024 04:00:33 GMT</pubDate>
            <atom:updated>2024-09-24T04:00:33.273Z</atom:updated>
            <content:encoded><![CDATA[<p>I saw a question on /r/androiddev that made me pause:</p><blockquote><a href="https://www.reddit.com/r/androiddev/comments/gyx6z3/weekly_questions_thread_june_08_2020/fthhqmg?utm_source=share&amp;utm_medium=web2x">Are these terms synonymous? instrumentation testinstrumented testinstrumented unit test– Fr4nkWh1te1</a></blockquote><p>Naming things is hard in software, but when I looked around at the Android docs I was surprised to find several separate references to these, some of which conflict with each other. Here’s my take on Android tests and how to apply generic software testing definitions to them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gHCsQhILKl7qTk5tdOcnVg.png" /></figure><h3>Tests</h3><p>Tests are small programs you write to test your actual program. Most modern languages and frameworks support writing, running, and reporting on tests in a variety of ways. Android is no different and really just builds on an existing <a href="https://spring.io/guides/gs/maven/?ref=jasonpearson.dev">Maven project structure for Java modules</a> — this is why some tests exist in the src/test/java directory. We&#39;ll get to the src/androidTest/java directory later.</p><h3>Unit Tests</h3><p>One of the first types of tests that we learn about when getting started in testing is <a href="https://en.wikipedia.org/wiki/Unit_testing?ref=jasonpearson.dev"><strong>unit tests</strong></a> which validate each unit of the software performs as expected. A <strong>unit</strong> is the smallest testable piece of your code, usually with some inputs and one deterministic output.</p><p><a href="https://developer.android.com/studio/test/?ref=jasonpearson.dev">The Android doc makes a reference to <strong>local unit tests</strong>:</a></p><blockquote>These are tests that run on your machine’s local Java Virtual Machine (JVM). Use these tests to minimize execution time when your tests have no Android framework dependencies or when you can mock the Android framework dependencies.</blockquote><blockquote>At runtime, these tests are executed against a modified version of android.jar where all final modifiers have been stripped off. This lets you use popular mocking libraries, like Mockito.</blockquote><p>Those bits are specific to Android development and writing <strong>unit tests</strong> for Android apps. The idea behind this is that actually running an android.jar requires either an emulator or device which has significant overhead. And since the Android Framework has its own tests and is not your code, unit tests should not be concerned with it.</p><p>Their documentation states that unit tests should be in the test directory, and this jives well with other project setups in most other languages. I will point out that other types of tests like <strong>integration tests</strong> that don&#39;t require the Android Framework could benefit from being in this directory, for example <a href="http://robolectric.org/?ref=jasonpearson.dev">Robolectric</a> (also <a href="https://github.com/robolectric/robolectric/issues/5358?ref=jasonpearson.dev">why don&#39;t they have https</a>?).</p><h3>Instrumented Tests</h3><p>The word <a href="https://english.stackexchange.com/questions/60732/instrumented-what-is-a-good-explanation-definition-of-the-word-english-tech?ref=jasonpearson.dev"><strong>instrumented</strong></a> means running a program with code tracing, debugging, monitoring, profiling, logging, and performance counters. The Android docs in my opinion abuse this definition a little bit when they say <a href="https://developer.android.com/training/testing/unit-testing/instrumented-unit-tests?ref=jasonpearson.dev"><strong>instrumented unit test</strong></a><strong> </strong>where they define it as you are running a unit test on some unit of your code but instead of a stubbed out android.jar you&#39;re running on a real device or emulator and exist in the androidTest directory instead of test. I believe this is immediately an <strong>integration test</strong> (where individual units are combined and tested together) because you&#39;re running a full Android environment with background services and apps as well as your entire application. And their own documentation conflicts with that page, as you can see <a href="https://developer.android.com/studio/test/?ref=jasonpearson.dev">here they refer to the same thing as instrumented tests</a>. I believe the correct way to refer to them is <strong>instrumented tests</strong> because <a href="https://developer.android.com/studio/test/?ref=jasonpearson.dev">their docs state</a>:</p><blockquote>These are tests that run on a hardware device or emulator. These tests have access to <strong>Instrumentation APIs</strong>, give you access to information such as the Context of the app you are testing, and let you control the app under test from your test code. Use these tests when writing integration and functional UI tests to automate user interaction, or when your tests have Android dependencies that mock objects cannot satisfy.</blockquote><p><strong>Instrumentation test</strong> is defined as either <a href="https://firebase.google.com/docs/test-lab/android/instrumentation-test?ref=jasonpearson.dev">just a UI test written in Espresso or UIAutomator</a> or <a href="https://source.android.com/compatibility/tests/development/instrumentation?ref=jasonpearson.dev">a special test execution environment as launched via the </a><a href="https://source.android.com/compatibility/tests/development/instrumentation?ref=jasonpearson.dev">am instrument command</a> depending on what you read. I believe the AOSP docs have the most correct definition and Firebase has a typo (I filed a support ticket to fix this).</p><h3>Summary</h3><p>Android’s test folders just split up functionality in running tests against a stubbed android.jar vs an actual Android environment. The names used in the documentation could be better.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=09dff7efd7be" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Billing on Android, Goodbye AIDL]]></title>
            <link>https://medium.com/@kaeawc/billing-on-android-goodbye-aidl-5ace895bac28?source=rss-176cd46cdccd------2</link>
            <guid isPermaLink="false">https://medium.com/p/5ace895bac28</guid>
            <dc:creator><![CDATA[Jason Pearson]]></dc:creator>
            <pubDate>Tue, 24 Sep 2024 03:59:10 GMT</pubDate>
            <atom:updated>2024-09-24T03:59:10.998Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iOscB9okmbujEd8e0VmR3Q.png" /></figure><p>Google released the Billing library which makes it considerably easier to handle subscriptions and consumables in Android apps. The reason it is easier to integrate is removing the need to communicate across <a href="https://developer.android.com/guide/components/aidl?ref=jasonpearson.dev">AIDL</a> (Android Interface Design Language), which added a lot of complexity on top of an already complex cognitive domain of showing products and verifying purchases.</p><p>The old way of doing things required making an Intent referencing the com.android.vending.billing.InAppBillingService in order to establish a ServiceConnection to obtain a Service defined as an interface against InAppBillingService. If that didn&#39;t already make your head spin, try dealing with any of the resulting errors.</p><p>I never did. Got on the Google Billing Library bandwagon at the first available production ready version (roughly 1.2.2) and never looked back.</p><p>I have seen questions about how to implement payment validation client-side only, and it just doesn’t make sense from a business perspective once the business makes enough to employ more than one engineer. The loss of revenue due to fraud is mostly going to be prevalent in the more popular applications since there will both be supply of tools and demand to avoid payment.</p><p>If you’re looking to find whether a given purchase has been refunded another API might help you with that — the <a href="https://developers.google.com/android-publisher/api-ref/purchases/products/get?ref=jasonpearson.dev">Google Play Developer API for purchases</a> — though again that should happen from a private server and not an Android client on a users phone. Both methods require using a private key that should not be exposed, and anything you put in the APK that goes out to users phones should be considered exposed information.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5ace895bac28" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[VAMPIRE Architecture]]></title>
            <link>https://medium.com/@kaeawc/vampire-architecture-e75f645786a5?source=rss-176cd46cdccd------2</link>
            <guid isPermaLink="false">https://medium.com/p/e75f645786a5</guid>
            <category><![CDATA[architecture]]></category>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Jason Pearson]]></dc:creator>
            <pubDate>Tue, 24 Sep 2024 03:57:10 GMT</pubDate>
            <atom:updated>2024-09-24T03:57:10.419Z</atom:updated>
            <content:encoded><![CDATA[<p>This idea is one that has its roots starting years ago when I started building the new Hinge Android app. Since I had a clear slate I decided to start with the best ideas I could find, including what the Hinge iOS team had already adopted as its architecture. If you’re curious about what that was like <a href="https://github.com/andrewcopp/Lessons-from-VIPER-Presentation/blob/master/LessonsFromVIPER.md?ref=jasonpearson.dev">the iOS lead at the time did a talk about it</a>. I want to talk about my reasoning and how things have evolved in the years since.</p><p>When deciding on the reasons to try this I could share ideas and practices about where code exists and eventually have some cross team code review (especially since I’ve been a team of 1). While honestly the cross team code review hasn’t manifested, I have been able to talk about and reason with the iOS devs at Hinge. Also the benefits such as clear layers of responsibility and being able to unit test them has been a major help.</p><p>A big difference between VIPER and the other MV* architectures is denoting a Router interface to be able to navigate between screens. This made building the app to be multi-module (currently at 58) in the first place quite easy and our transition from many Activities to a single Activity with Navigation Component handling Fragments much easier than it otherwise would have been.</p><p>Our Presenters are backed by AndroidX ViewModel. We have used RxJava for years, so it didn’t really make sense to switch to LiveData, especially since subscribing to Room queries is so easy and straightforward. We eventually decided it was easier to onboard new employees by calling these ViewModels and adapting our architecture documentation to fit rather than keep a neat sounding acronym.</p><p>Lastly, I would say that I have borrowed some of MVI in the sense of having a uni-directional flows of data that populate the app’s UI and drive the view. This eventually evolved into adopting UseCases and splitting up our gigantic ViewModels and Interactors.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e75f645786a5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>