Hey everyone. So we just upgraded our Android proj...
# announcements
d
Hey everyone. So we just upgraded our Android project to Kotlin 1.4, and things have gone OK. But we're having this strange problem with Android Studio. The project builds fine, but it's saying it can't find the StringBuilder.appendLine() extension. Yet it sees that StringBuilder.appendLn() is deprecated. and if I ctrl+click into appendLn(), the StringBuilderJVM.kt file clearly has appendLine() in it. Anyone have any ideas? Using AS 4.0.1 and the latest Kotlin plugin, 1.4.10-release-Studio4.0-1 from today.
Invalidate Caches & restart didn't help either 😞
Hrm, actually, looking closer at StringBuilderJVM.kt, there doesn't actually seem to be a appendLine() function in there! But things compile, where could it be?
s
Did u update your Gradle Dependencies to use the latest Kotlin version?
d
yes. I've got this in my settings.gradle.kts:
Copy code
pluginManagement {

    val kotlinVersion = "1.4.0"
    val androidGradleVersion = "4.0.1"
    val realmVersion = "6.1.0"
    val newRelicVersion = "5.27.0"
    val firebaseCrashlyticsVersion = "2.2.0"
    val googleServicesVersion = "4.3.3"
    val hiltVersion = "2.28.3-alpha"

    repositories {
        gradlePluginPortal()
        google()
    }

    @Suppress("UnstableApiUsage") plugins {
        // In the event we ever get a plugin that has a plugin marker artifact, we can set the
        // version of that plugin used across all modules here with an entry like this:
        // id("id.of.plugin") version "X.Y.Z"
    }

    data class PluginArtifactMapping(
        val pluginIds: List<String>,
        private val artifact: String,
        private val version: String
    ) {
        val pluginDependencyCoordinates: String
            get() = "$artifact:$version"
    }

    resolutionStrategy {

        val plugins = listOf(
            PluginArtifactMapping(
                listOf("com.android.application", "com.android.library"),
                "com.android.tools.build:gradle",
                androidGradleVersion
            ), PluginArtifactMapping(
                listOf("realm-android"), "io.realm:realm-gradle-plugin", realmVersion
            ), PluginArtifactMapping(
                listOf("newrelic"),
                "com.newrelic.agent.android:agent-gradle-plugin",
                newRelicVersion
            ), PluginArtifactMapping(
                listOf("com.google.gms.google-services"),
                "com.google.gms:google-services",
                googleServicesVersion
            ), PluginArtifactMapping(
                listOf("com.google.firebase.crashlytics"),
                "com.google.firebase:firebase-crashlytics-gradle",
                firebaseCrashlyticsVersion
            ), PluginArtifactMapping(
                listOf("dagger.hilt.android.plugin"),
                "com.google.dagger:hilt-android-gradle-plugin",
                hiltVersion
            )
        )

        eachPlugin {
            // Map the ID's of plugins using legacy way of registering with Gradle (meaning that
            // these plugins do not have plugin marker artifacts) to the module that contains the
            // plugin. This also has the effect of setting the version of these plugins, since the
            // module version is specified here
            plugins.forEach { payload ->
                if (requested.id.id in payload.pluginIds) {
                    useModule(payload.pluginDependencyCoordinates)
                    return@forEach
                }
            }

            // Set all Kotlin plugins to use the same version of Kotlin we want
            if (requested.id.namespace?.startsWith("org.jetbrains.kotlin") == true) {
                useVersion(kotlinVersion)
            }
        }
    }
}
And in my modules' build.gradle.kts, I've got this
Copy code
import com.albert.gradle.plugins.android.Deps

plugins {
    id("com.albert.gradle.plugins.android.albert-android-library")
    kotlin("kapt")
    id("realm-android")
}

dependencies {
    implementation(fileTree(mapOf("include" to listOf("*.jar"), "dir" to "libs")))
    implementation(project(":network"))
    implementation(project(":library_resources"))
    implementation(project(":library_extensions"))
    implementation(project(":utils"))
    implementation(Deps.kotlin.stdlib.jdk8)

    // Gson
    implementation(Deps.google.gson)

    // JodaTime
    implementation(Deps.jodaTime)

    // Realm Field Names
    kapt(Deps.realmFieldNames)
}
And here's the Deps.kotlin object from the custom plugin:
Copy code
object Kotlin {
        // TODO-gradle-refactor Can we pull this out somewhere and make it usable for plugins?
        private const val kotlinVersion = "1.4.0"

        val stdlib = Stdlib()
        val test = Test
        val kotlinx = Kotlinx

        const val reflect = "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"

        class Stdlib(
            private val name: String = "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
        ) : CharSequence by name {
            val jdk7 = "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
            val jdk8 = "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion"

            override fun toString(): String = name
        }

        object Test {
            const val common = "org.jetbrains.kotlin:kotlin-test-common:$kotlinVersion"
            const val js = "org.jetbrains.kotlin:kotlin-test-js:$kotlinVersion"
            const val junit = "org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion"
            const val annotationsCommon =
                "org.jetbrains.kotlin:kotlin-test-annotations-common:$kotlinVersion"
        }

        object Kotlinx {
            // Version number for dependencies from <https://github.com/Kotlin/kotlinx.coroutines>
            private const val kotlinCoroutinesVersion = "1.3.9"

            val test = Test

            const val coroutinesAndroid =
                "org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlinCoroutinesVersion"

            object Test {
                const val coroutines =
                    "org.jetbrains.kotlinx:kotlinx-coroutines-test:$kotlinCoroutinesVersion"
            }
        }
    }
a
Please try "File | Invalidate caches and restart" and removing your .idea directory (back it up first) and reimporting the project into AS.