After applying Kotlin Android Extensions plugin I wasn't able to enable its experimental mode.
After applying Kotlin/Android plugins in build.gradle (Groovy version):
apply plugin: "com.android.application"
apply plugin: "kotlin-android"
apply plugin: "kotlin-android-extensions"
we could enable Kotlin Android Extensions experimental mode:
androidExtensions {
experimental = true
}
./gradle dependencies shows that there is a org.jetbrains.kotlin:kotlin-android-extensions-runtime:1.2.10 runtime dependency.
After applying plugins in build.gradle.kts:
plugins {
id("com.android.application")
kotlin("android")
id("kotlin-android-extensions")
}
androidExtensions {
isExperimental = true
}
experimental mode actually is not enabled e.g. I wasn't able to import kotlinx.android.extensions.LayoutContainer class and there is no org.jetbrains.kotlin:kotlin-android-extensions-runtime:1.2.10 runtime dependency
build.gradle.kts:
plugins {
id("com.android.application")
kotlin("android")
id("kotlin-android-extensions")
}
androidExtensions {
isExperimental = true
}
After that try to import any experimental Kotlin Android Extensions classes e.g. kotlinx.android.extensions.LayoutContainer
Update: I've created a sample project demonstrating the issue: https://github.com/nobodysfault/hello-android
It's just a cloned hello-android sample with added Kotlin Android Extensions and experimental = true.
Does your script compile on the command line? I would expect some sort of failure messages to pop up regarding plugin resolution.
One issue may be that the plugin id("com.android.application") isn't resolving to the correct plugin for - see this example https://github.com/gradle/kotlin-dsl/blob/4719d5c5af97a826335f97f9fdba4d8d43601a91/samples/hello-android/settings.gradle.kts#L1-L13
Other issue may be the wrong Id for id("kotlin-android-extensions") - should probably be kotlin("kotlin-android-extensions") or id("org.jetbrains.kotlin.android.extensions").
Another issue may be you haven't specified versions in any of your plugins like id("com.android.application") version "3.0.0" - see this example https://github.com/gradle/kotlin-dsl/blob/master/samples/hello-android/build.gradle.kts#L2
@mkobit yes, it compiles. Basic Kotlin Android Extensions functionality works (like synthetic package etc.), but not the experimental one. It looks like this experimental flag just isn't resolved somehow.
I'll try other things you've suggested, thanks!
@mkobit I wasn't able to specify plugin version:
Error resolving plugin [id: 'org.jetbrains.kotlin.android.extensions', version: '1.2.10']
> Plugin request for plugin already on the classpath must not include a version
and I'm sure I don't have this plugin on the classpath already.
As for com.android.application - yes, it resolves correctly.
Can you please post your settings.gradle? Maybe that would help?! 🤷♂️
On Dec 29, 2017 10:20 AM, "nobodysfault" notifications@github.com wrote:
@mkobit https://github.com/mkobit I wasn't able to specify plugin
version:Error resolving plugin [id: 'org.jetbrains.kotlin.android.extensions', version: '1.2.10']
Plugin request for plugin already on the classpath must not include a version
and I'm sure I don't have this plugin on the classpath already.
As for com.android.application - yes, it resolves correctly.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/gradle/kotlin-dsl/issues/644#issuecomment-354420455,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AJwYe9ZsVfjttif61SCyMQnxpWlsTACwks5tFK7dgaJpZM4ROVsL
.
@StefMa basically it's just
include ':project'
but I've tried custom resolution strategy like this:
pluginManagement {
repositories {
gradlePluginPortal()
google()
}
resolutionStrategy {
eachPlugin {
if (requested.id.id == "com.android.application") {
useModule("com.android.tools.build:gradle:${requested.version}")
}
if (requested.id.id == "kotlin-android-extensions") {
useModule("org.jetbrains.com:kotlin-android-extensions:${requested.version}")
}
}
}
}
even with custom overridden versions, but no luck
kotlin("android.extensions") version "1.2.10"
@iNoles build script compiles, but with isExperimental = true kotlin-android-extensions-runtime is still not on the classpath.
I've cloned hello-android sample and added Kotlin Android Extensions:
https://github.com/nobodysfault/hello-android
I've added kotlinx.android.extensions.LayoutContainer import into MainActivity.kt to check if experimental mode works. Hope it helps.
I've looked into the Kotlin gradle plugin code to find out what happened
under the hood.
As you can see in this file (especially the
class AndroidExtensionsSubpluginIndicator):
https://github.com/JetBrains/kotlin/blob/master/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/AndroidSubplugin.kt
You have to apply the kotlin-android. Otherwise it just ignore
"everything"...
TL/DR: Just apply the kotlin-android plugin before the
kotlin-android-extensions and it should work...
👍
On Jan 2, 2018 9:21 AM, "nobodysfault" notifications@github.com wrote:
@iNoles https://github.com/inoles build script compiles, but with
isExperimental = true kotlin-android-extensions-runtime is still not on
the classpath.I've cloned hello-android sample and added Kotlin Android Extensions here:
https://github.com/nobodysfault/hell-android
I've added kotlinx.android.extensions.LayoutContainer import into
MainActivity.kt to check if experimental mode works. Hope it helps.—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/gradle/kotlin-dsl/issues/644#issuecomment-354719109,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AJwYe4TXB9azRRSVhKbrL5ZKi5XOPvxMks5tGebugaJpZM4ROVsL
.
@StefMa it should log this error: "'kotlin-android' plugin should be enabled before 'kotlin-android-extensions'", but no error is logged.
As you could see in https://github.com/nobodysfault/hello-android/blob/master/build.gradle.kts kotlin-android plugin is loaded before kotlin-android-extensions, but still no luck.
I've ran hello-android build with --debug, and it looks like this function works:
https://github.com/JetBrains/kotlin/blob/e2306ecf94d179074b4d0e2fc5098e039a22fa59/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/AndroidSubplugin.kt#L142
cause there are -P plugin:org.jetbrains.kotlin.android:experimental=true,plugin:org.jetbrains.kotlin.android:defaultCacheImplementation=hashMap in compiler args, but Android Extensions runtime is not added to the runtime dependencies.
For me it looks like a problem with the following code:
extension.setEvaluatedHandler { evaluatedExtension ->
if (evaluatedExtension.isExperimental) {
addAndroidExtensionsRuntimeIfNeeded(project)
}
}
but I'm not sure how could I check it. Could it behave differently with the old Groovy build.gradle and kotlin-dsl?
Ah sry of course. It was my mistake. You already apple kotlin-android 🤦♂️
On Jan 2, 2018 11:05 AM, "nobodysfault" notifications@github.com wrote:
I've ran hello-android build with --debug, and it looks like this
function works:
https://github.com/JetBrains/kotlin/blob/e2306ecf94d179074b4d0e2fc5098e
039a22fa59/libraries/tools/kotlin-gradle-plugin/src/main/
kotlin/org/jetbrains/kotlin/gradle/internal/AndroidSubplugin.kt#L142
cause there are -P plugin:org.jetbrains.kotlin.android:experimental=true,
plugin:org.jetbrains.kotlin.android:defaultCacheImplementation=hashMap in
compiler args, but Android Extensions runtime is not added to the runtime
dependencies.For me it looks like a problem with the following code:
extension.setEvaluatedHandler { evaluatedExtension -> if (evaluatedExtension.isExperimental) { addAndroidExtensionsRuntimeIfNeeded(project) } }but I'm not sure how could I check it.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/gradle/kotlin-dsl/issues/644#issuecomment-354734077,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AJwYe6Bx_HQo0vNcPOE3Ibt1zFMWlcpLks5tGf9-gaJpZM4ROVsL
.
The way the kotlin-android plugin handle the isExperimental flag seems a bit convoluted to me.
First, it relies on org.gradle.util.Configurable which is not API, it is internal.
Moreover, a plugin implemented in, say, plain Java doing extensions.getByType(AndroidExtensionsExtension.class).experimental = true won't trigger this "evaluated handler" either.
It will only work in Groovy scripts.
@nobodysfault, could you report this issue on the Kotlin gradle plugin?
@eskatos thanks for the investigation and explanation. I've reported the issue: https://youtrack.jetbrains.com/issue/KT-22213
I've been able to circumvent this by creating a Groovy Gradle script which just enables the experimental mode, and applying the said script in my Kotlin Gradle script.
experimentalExtensions.gradle:
androidExtensions { experimental = true }
build.gradle.kts:
// ...
apply { from("experimentalExtensions.gradle") }
// ...
Kotlin "released" 1.2.20 yesterday and according to their changelog they have fixed
I think you can give it another try with 1.2.20 ;)
Kotlin 1.2.20 Gradle plugins are not deployed to the plugin portal yet, latest available version is 1.2.10: https://plugins.gradle.org/plugin/org.jetbrains.kotlin.jvm
https://github.com/gradle/kotlin-dsl/issues/664#issuecomment-358245686
@StefMa @eskatos Nope, it still doesn't work. I've updated Kotlin in my test project and checked it: https://github.com/nobodysfault/hello-android/commit/c8f23a195329b63870085106c3c1defc08b61688
And KT-22213 is still in "Open" state.
Yep, KT-20235 is unrelated to this issue.
Another workaround:
androidExtensions {
configure(delegateClosureOf<AndroidExtensionsExtension> {
isExperimental = true
})
}
Good night. In my case i only coment the apply plugin: 'kotlin-android' just like that:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
// apply plugin: 'kotlin-android'
androidExtensions {
experimental = true
}
and it works. Does it will cause any trouble to me?
Good morning i solved this issue changing the Sync project that was in off-line mode to on-line mode. to me that was my problem. Thanks guys
@Parcelize still not found
plugins {
id("com.android.library")
id("kotlin-android")
id("kotlin-android-extensions")
kotlin("android")
kotlin("kapt")
kotlin("android.extensions")
}
androidExtensions {
isExperimental = true
configure(delegateClosureOf<AndroidExtensionsExtension> {
isExperimental = true
})
}
it recongnized kotlinx.android.parcel as a package name however it's empty
@hereisderek you have some duplicate lines:
id("kotlin-android") is the same as kotlin("android"). And id("kotlin-android-extensions") is the same as kotlin("android.extensions").
@hereisderek you have some duplicate lines:
id("kotlin-android")is the same askotlin("android"). Andid("kotlin-android-extensions")is the same askotlin("android.extensions").
I understand that. it was just me playing around and added the lines.
however it still doesn't explain why experimental is not enabled
Any updates about this issue?
The workaround is not longer needed for kotlin 1.3.30.
androidExtensions {
isExperimental = true
}
Works fine. Issue can be closed.
Thanks for the feedback @SimonSchubert!
Closing
I've looked into the Kotlin gradle plugin code to find out what happened under the hood. As you can see in this file (especially the class AndroidExtensionsSubpluginIndicator): https://github.com/JetBrains/kotlin/blob/master/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/AndroidSubplugin.kt You have to apply the kotlin-android. Otherwise it just ignore "everything"... TL/DR: Just apply the kotlin-android plugin before the kotlin-android-extensions and it should work... 👍
…
On Jan 2, 2018 9:21 AM, "nobodysfault" @.*> wrote: @iNoles https://github.com/inoles build script compiles, but with isExperimental = true kotlin-android-extensions-runtime is still not on the classpath. I've cloned hello-android sample and added Kotlin Android Extensions here: https://github.com/nobodysfault/hell-android I've added kotlinx.android.extensions.LayoutContainer import into MainActivity.kt to check if experimental mode works. Hope it helps. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#644 (comment)>, or mute the thread https://github.com/notifications/unsubscribe-auth/AJwYe4TXB9azRRSVhKbrL5ZKi5XOPvxMks5tGebugaJpZM4ROVsL .
It is worth mentioning that plugin order is important - it is what was causing this problem for me
maybe related... https://youtrack.jetbrains.com/issue/KT-31043 app start crashing for our users after apply https://github.com/gradle/kotlin-dsl/issues/644#issuecomment-482479624 and Kotlin 1.3.30
androidExtensions { isExperimental = true } on kotlin 1.3.30
still doesn't work for me
Creating configuration testReleaseCompile
Creating configuration testReleasePublish
Creating configuration testReleaseProvided
Creating configuration testReleaseApi
Creating configuration testReleaseImplementation
Creating configuration testReleaseRuntimeOnly
Creating configuration testReleaseCompileOnly
Creating configuration testReleaseWearApp
Creating configuration testReleaseAnnotationProcessor
Parsing the SDK, no caching allowed
SDK initialized in 0 ms
FAILURE: Build failed with an exception.
* Where:
Build file '/Volumes/Persistence/Data/Workspace/frsipMobile-android/FrSipProject/virtualmeeting/build.gradle' line: 26
* What went wrong:
A problem occurred evaluating project ':virtualmeeting'.
> Could not set unknown property 'isExperimental' for object of type org.jetbrains.kotlin.gradle.internal.AndroidExtensionsExtension.
* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output. Run with --scan to get full insights.
P.S.
syntax for gradle (not kotlin dsl) should be androidExtensions { experimental = true } and it's working
Guys , good answer , work for me
Kotlin plugin should be enabled before 'kotlin-android-extensions'
Please do not close, it still showing up on Android 3.5.3 Kotlin 1.3.61. I stilll can't get @Parcelize to be found.
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
.........................
}
androidExtensions {
experimental = true
features = ["parcelize"]
}
@neonwarge04 try the above with kotlin 1.3.70. Its worked for me..
The stackoverflow advice in @steam0111's comment above, worked for me.
Most helpful comment
Another workaround: