I've been trying to combine the newly publicly released Android Instant Apps with the Kotlin programming language. After creating my project using the following (standard?) setup, I get an Error with the message "null cannot be cast to non-null type com.android.build.gradle.BasePlugin" when I try to build the application. Using Kotlin works fine with standard 'com.android.application' modules; the Error is thrown only when I try to use it within an Instant App module.
Top-level build.gradle:
buildscript {
repositories {
maven { url 'https://maven.google.com' }
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:3.0.0-alpha1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.2-4"
}
}
// ...
app module build.gradle, in which Kotlin does work:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android' // This will work.
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
// ...
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation project(':feature')
implementation project(':base')
}
base module build.gradle, in which Kotlin does not work:
apply plugin: 'com.android.feature'
apply plugin: 'kotlin-android' // This won't work.
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
baseFeature true
defaultConfig {
// ...
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
feature project(':tracker')
compile 'com.android.support:appcompat-v7:25.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
// Kotlin standard library.
compile "org.jetbrains.kotlin:kotlin-stdlib:${gradleKotlinVersion}"
}
instantapp module build.gradle:
apply plugin: 'com.android.instantapp'
dependencies {
implementation project(':feature')
implementation project(':base')
}
feature module build.gradle:
apply plugin: 'com.android.feature'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
// ...
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation project(':base')
testCompile 'junit:junit:4.12'
}
Again, the app module compiles without issues with this configuration; on the other hand, Android Studio / Gradle gives me this strange "null cannot be cast to non-null type com.android.build.gradle.BasePlugin" error message, with the suggestions to re-download dependencies and sync the project (done) or restart Android Studio.
Are Instant Apps actually compatible with the Kotlin programming language ? I'm looking forward to your answers :)
PS: I use Android Studio 3.0 Canary 1, with the latest updates installed from the Canary Channel for Build tools etc. My Kotlin plugin should be up-to-date as well.
This is addressed in Kotlin plugin v1.1.2-5. Please update your version and try again.
For reference, the issue with previous plugin versions is being tracked here:
38393607 | Issue building Instant apps with Kotlin enabled
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With