5

I am trying to use Anko with my Android Kotlin Project. I have added the line to my dependencies / gradle module file as follows:

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:$anko_version"
    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support:design:26.+'
    compile 'com.android.support:support-vector-drawable:26.+'
    compile 'com.android.support:support-v4:26.+'
    testCompile 'junit:junit:4.12'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
}

But I get the following error when trying to do a gradle sync:

Error:(36, 0) Could not get unknown property 'anko_version' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. Open File

How can I properly incorporate Anko in my project?

For reference, I am using Android Studio 2.0.

arcade16
  • 1,535
  • 4
  • 23
  • 45

4 Answers4

7

Add anko_version in ext block above the dependencies block:

ext {
   anko_version = '0.10.1'
}

Another option, as Naetmul suggested in the comments, is to replace the $anko_version with 0.10.1

Bob
  • 13,447
  • 7
  • 35
  • 45
2

You can define it in your project level build.gradle file.

enter image description here

OR

You can replace with current version which is 0.10.1 (on 1 Sep 2017)

Pravin Londhe
  • 865
  • 7
  • 14
0

This is how I do it and it works great:

  1. Open your project gradle.
  2. Add a ext block within the buildscript block.
  3. Add your versions properties.

enter image description here

Within your app gradle, set your versions like so:

enter image description here

Barakuda
  • 790
  • 8
  • 16
0

Use this

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

Don't use this

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

and don't use this

implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
Islam Ahmed
  • 668
  • 9
  • 19