Which kotlin versions should I use for Android Studio 3.0 Canary 1?
I have a medium sized Kotlin project that uses anko and kotlin android extensions, specifically synthetic properties from resource IDs. They all stopped working with my update to Android Studio 3.0 Canary 1. Although it seems that they also stopped working for AS 2.3.2.
Here is the relevant top-level compilation script:
buildscript {
ext.kotlin_version = '1.1.2'
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
...
And in my application module script, the relevant parts are:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
repositories {
mavenCentral()
jcenter()
}
android {
compileSdkVersion 25
buildToolsVersion '25.0.2'
dataBinding {
enabled = true
}
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile 'org.jetbrains.anko:anko-sdk21:0.9.1'
compile 'org.jetbrains.anko:anko-support-v4:0.9.1'
compile 'org.jetbrains.anko:anko-appcompat-v7:0.9.1'
kapt "com.android.databinding:compiler:2.5.0-alpha-preview-02"
}
kapt {
generateStubs = true
}
My team was built successfully; in fact, the build in the IDE succeeds. But Kotlin gives me red IDs for all of my synthetic properties.
One possible hint is that Kotlin doesn't seem to recognize my Activity (AppCompatActivity) as a subclass of the context:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
MultiDex.install(this)
"this" underscores the error, saying it was expecting a context! and got MainActivity; my MainActivity is defined as:
class MainActivity : AppCompatActivity() {
My Kotlin IDE plugin 1.1.2-4. I don't know how to get it back to an older version.
I tried to reinstall Android Studio 2.3.2, but none of the Kotlin plugins work anymore.
source to share
you can change build.gradle (Module: app) file from
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
compile "org.jetbrains.anko:anko-commons:$anko_version"
compile('com.crashlytics.sdk.android:crashlytics:2.6.8@aar')
{
transitive = true;
}
compile "com.squareup.retrofit2:retrofit:$retrofit_version"
compile "com.squareup.retrofit2:converter-gson:$retrofit_version"
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile 'com.android.support:design:25.3.1'
}
To:
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation "org.jetbrains.anko:anko-commons:$anko_version"
implementation('com.crashlytics.sdk.android:crashlytics:2.6.8@aar')
{
transitive = true;
}
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
implementation 'com.android.support:appcompat-v7:25.3.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:design:25.3.1'
}
Then the red IDs will disappear.
source to share