Android - Experimental Gradle Plugin 0.2.0

Currently, the kotlin-android Gradle plugin does not work with the next-generation Android gradle plugin, which supports native code and better script execution times. To verify this, clone the git repository at:

git@github.com:googlesamples/android-ndk.git

Then use Android Studio to open one of the projects contained in that repository (I chose hello-jni). Compiling the project should work, but it will not after adding the following to app/build.gradle:

apply plugin: 'kotlin-android'

``

Error:(2, 0) Extension with name ‘android’ does not exist. Currently registered extension names: [ext, sources, binaries, defaultArtifacts, reporting, buildTypes, flavors, toolChains]


Where (2,0) is the location of the “apply kotlin-android” line in build.gradle. My guess is that this is because the redesigned DSL they’re moving to for the Android plugin contains several changes - the most relevant of which is that “android” has been renamed to “model.android”.

I understand that it’s very fast-moving, prerelease software, so I don’t want to make a feature request to add support for this. I am wondering, however, if any Gradle experts might be able to chime in with a workaround that can perhaps point the Kotlin plugin to the information it’s looking for from the original Android plugin.

If I'm not mistaken, I think that "kotlin-android-extensions" had already been deprecated in favor of anko.

And also make sure that in the Android Studio you’ve already installed the Kotlin and Kotlin Android plugin.

A typical gradle file would be like this:

buildscript {   ext.kotlin_version = '0.13.1513'   ext.anko_version = '0.7'   ext.android_support_version = '23.0.1'

  repositories {
  jcenter()
  mavenCentral()
  }

  dependencies {
  classpath “org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version”
  }
}

apply plugin: 'com.android.application’
apply plugin: ‘kotlin-android’

android {
  compileSdkVersion 23
  buildToolsVersion “23.0.1”

  defaultConfig {
  applicationId “com.example.demo”
  minSdkVersion 9
  targetSdkVersion 23
  versionCode 1
  versionName “1.0”
  }

  compileOptions {
  sourceCompatibility JavaVersion.VERSION_1_7
  targetCompatibility JavaVersion.VERSION_1_7
  }

  buildTypes {
  release {
  minifyEnabled false
  proguardFiles getDefaultProguardFile(‘proguard-android.txt’), ‘proguard-rules.pro
  }
  }

  sourceSets {
  main.java.srcDirs += ‘src/main/kotlin’
  androidTest.java.srcDirs += ‘src/androidTest/kotlin’
  }

  packagingOptions {
  exclude ‘META-INF/LICENSE’
  exclude ‘META-INF/NOTICE’
  exclude ‘META-INF/LICENSE.txt’
  exclude ‘META-INF/NOTICE.txt’
  }
}

repositories {
  jcenter()
  mavenCentral()
}

dependencies {
  compile fileTree(include: [’*.jar’], dir: ‘libs’)

  compile ‘com.android.support:multidex:1.0.1’

  compile “com.android.support:design:$android_support_version”
  compile “com.android.support:recyclerview-v7:$android_support_version”
  compile “com.android.support:cardview-v7:$android_support_version”
  compile “com.android.support:gridlayout-v7:$android_support_version”

  compile “org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version”

  // anko
  compile “org.jetbrains.anko:anko-sdk23:$anko_version”
  compile “org.jetbrains.anko:anko-support-v4:$anko_version”
  compile “org.jetbrains.anko:anko-appcompat-v7:$anko_version”
  compile “org.jetbrains.anko:anko-common:$anko_version”
  compile “org.jetbrains.anko:anko-design:$anko_version”
  compile “org.jetbrains.anko:anko-recyclerview-v7:$anko_version”
  compile “org.jetbrains.anko:anko-gridlayout-v7:$anko_version”
  compile “org.jetbrains.anko:anko-cardview-v7:$anko_version”
  compile “org.jetbrains.anko:anko-percent:$anko_version”

}

Android Extensions and Anko are two complimentary projects, none is a successor of the other.

My Kotlin environment works correctly, and I'm not having any trouble writing traditional Android apps using Kotlin.

The topic of my post exclusively pertains to Android Studio’s upcoming support for native C development, which depends on a newer version of the Android Gradle plugin, which as outlined in OP appears to be incompatible with the current version of Kotlin’s Gradle plugin.