I'm experimenting with using the Kotlin DSL in an Android project. The repository I'm playing with is scompt/android-gradle-kotlin-submodule. When the Android module is at the root level of the project (like in 8d8431), it works. If I move the module to be a sub-project, the project can't be configured. The Android project I'm using to test is the hello-android sample.
Using 9705c3, when I run ./gradlew tasks, I should see a bunch of tasks.
When I run ./gradlew tasks, I see these errors:
> Configure project :hello-android
e: /Users/scompt/checkouts/android-gradle-kotlin-submodule/hello-android/build.gradle.kts:17:1: Unresolved reference: android
e: /Users/scompt/checkouts/android-gradle-kotlin-submodule/hello-android/build.gradle.kts:18:5: Unresolved reference: buildToolsVersion
e: /Users/scompt/checkouts/android-gradle-kotlin-submodule/hello-android/build.gradle.kts:19:5: Unresolved reference: compileSdkVersion
e: /Users/scompt/checkouts/android-gradle-kotlin-submodule/hello-android/build.gradle.kts:21:5: Unresolved reference: defaultConfig
e: /Users/scompt/checkouts/android-gradle-kotlin-submodule/hello-android/build.gradle.kts:22:9: Unresolved reference: minSdkVersion
e: /Users/scompt/checkouts/android-gradle-kotlin-submodule/hello-android/build.gradle.kts:23:9: Unresolved reference: targetSdkVersion
e: /Users/scompt/checkouts/android-gradle-kotlin-submodule/hello-android/build.gradle.kts:25:9: Unresolved reference: applicationId
e: /Users/scompt/checkouts/android-gradle-kotlin-submodule/hello-android/build.gradle.kts:26:9: Unresolved reference: versionCode
e: /Users/scompt/checkouts/android-gradle-kotlin-submodule/hello-android/build.gradle.kts:27:9: Unresolved reference: versionName
e: /Users/scompt/checkouts/android-gradle-kotlin-submodule/hello-android/build.gradle.kts:30:5: Unresolved reference: buildTypes
e: /Users/scompt/checkouts/android-gradle-kotlin-submodule/hello-android/build.gradle.kts:31:9: Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
private fun <T : Any, U : [ERROR : Cyclic upper bounds]> PolymorphicDomainObjectContainer<???>.getByName(name: String, type: KClass<???>): ??? defined in org.gradle.kotlin.dsl
public inline fun <reified T : Any> ExtensionContainer.getByName(name: String): ??? defined in org.gradle.kotlin.dsl
e: /Users/scompt/checkouts/android-gradle-kotlin-submodule/hello-android/build.gradle.kts:32:13: Unresolved reference: isMinifyEnabled
e: /Users/scompt/checkouts/android-gradle-kotlin-submodule/hello-android/build.gradle.kts:33:13: Unresolved reference: proguardFiles
e: /Users/scompt/checkouts/android-gradle-kotlin-submodule/hello-android/build.gradle.kts:39:5: Unresolved reference: compile
e: /Users/scompt/checkouts/android-gradle-kotlin-submodule/hello-android/build.gradle.kts:40:5: Unresolved reference: compile
e: /Users/scompt/checkouts/android-gradle-kotlin-submodule/hello-android/build.gradle.kts:41:5: Unresolved reference: compile
Hi @scompt, thanks for the report!
This happens because your gradle/project-schema.json file is out of date after the project change. This file is needed because the com.android.application plugin is not applied using the plugins {} block.
To work around this limitation you could:
android { ... } by configure<com.android.build.gradle.AppExtension> { ... } in your build scriptcompile(..) by "compile"(..) in your build script./gradlew kotlinDslAccessorsSnapshotconfigure<com.android.build.gradle.AppExtension> { ... } by android { ... }"compile"(..) by compile(..)BUT, we recently updated the android sample to make use of a plugin resolution strategy that allows to apply com.android.application using the plugins {} block. Doing this remove the need for the gradle/project-schema.json file altogether, should make things easier and unblock you. It is on the develop branch for now, see https://github.com/gradle/kotlin-dsl/tree/develop/samples/hello-android
Also see doc/getting-started/Configuring-Plugins.md for more information on how to configure plugins.
I'm going to close this, feel free to reopen if you feel this needs more discussions.
Thanks @eskatos. Using the plugins block worked! (fc2948)
Hi @scompt, thanks for the report!
This happens because your
gradle/project-schema.jsonfile is out of date after the project change. This file is needed because thecom.android.applicationplugin is not applied using theplugins {}block.To work around this limitation you could:
- change
android { ... }byconfigure<com.android.build.gradle.AppExtension> { ... }in your build script- change dependency declarations
compile(..)by"compile"(..)in your build script- run
./gradlew kotlinDslAccessorsSnapshot- change back
configure<com.android.build.gradle.AppExtension> { ... }byandroid { ... }- change back
"compile"(..)bycompile(..)BUT, we recently updated the android sample to make use of a plugin resolution strategy that allows to apply
com.android.applicationusing theplugins {}block. Doing this remove the need for thegradle/project-schema.jsonfile altogether, should make things easier and unblock you. It is on thedevelopbranch for now, see https://github.com/gradle/kotlin-dsl/tree/develop/samples/hello-androidAlso see doc/getting-started/Configuring-Plugins.md for more information on how to configure plugins.
I'm going to close this, feel free to reopen if you feel this needs more discussions.
The page is not found anymore @eskatos
@mochadwi documentation moved at https://docs.gradle.org/current/userguide/kotlin_dsl.html
Most helpful comment
Hi @scompt, thanks for the report!
This happens because your
gradle/project-schema.jsonfile is out of date after the project change. This file is needed because thecom.android.applicationplugin is not applied using theplugins {}block.To work around this limitation you could:
android { ... }byconfigure<com.android.build.gradle.AppExtension> { ... }in your build scriptcompile(..)by"compile"(..)in your build script./gradlew kotlinDslAccessorsSnapshotconfigure<com.android.build.gradle.AppExtension> { ... }byandroid { ... }"compile"(..)bycompile(..)BUT, we recently updated the android sample to make use of a plugin resolution strategy that allows to apply
com.android.applicationusing theplugins {}block. Doing this remove the need for thegradle/project-schema.jsonfile altogether, should make things easier and unblock you. It is on thedevelopbranch for now, see https://github.com/gradle/kotlin-dsl/tree/develop/samples/hello-androidAlso see doc/getting-started/Configuring-Plugins.md for more information on how to configure plugins.
I'm going to close this, feel free to reopen if you feel this needs more discussions.