112

When I compile I got the above error. My gradle file as below : -

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 23
    buildToolsVersion "24.0.0 rc2"

    defaultConfig {
        applicationId "package.name"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 6
        versionName "2.0"
    }

    buildTypes {
        debug {
            minifyEnabled false
            signingConfig signingConfigs.debug
        }
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }
    }
    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile "com.android.support:appcompat-v7:$support_version"
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    compile "org.jetbrains.anko:anko-sdk15:$anko_version"
    compile "org.jetbrains.anko:anko-support-v4:$anko_version"
    compile "com.android.support:recyclerview-v7:$support_version"
}

buildscript {
    ext.kotlin_version = '1.0.1-2'
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
    }
}
repositories {
    mavenCentral()
}

And my project gradle as below

buildscript {
    ext.support_version = '23.2.1'
    ext.kotlin_version = '1.0.1'
    ext.anko_version = '0.8.3'
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0-alpha3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Did I miss adding anything?

3 Answers 3

187

From the error, I assume:

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

in your dependencies in addition to the standard library.

Sign up to request clarification or add additional context in comments.

7 Comments

Thanks! Found we need compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version" as per in kotlinlang.org/docs/reference/using-gradle.html
Perhaps not obvious: (1) must be double quotes, not single, otherwise $kotlin_version won't expand, (2) according to kotlinlang.org/docs/reference/… , the :$kotlin_version can be omitted if it's >= 1.1.2. But that seems to be broken for me (my $kotlin_version is 1.2.10 currently); the error message shows that it constructs a bogus url such as https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-reflect//kotlin-reflect-.jar. So, I am still using the recipe in this answer.
Worth mentioning that implementation is now the favored directive over compile: implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
is there any proguard rule for this dependency?
I still get the error.. Even using the shadow jar plugin (and indeed I confirmed that kotlin-reflect is in the .jar
|
8

I resolved this by adding this in build.gradle

implementation "org.jetbrains.kotlin:kotlin-reflect:1.3.61"

Comments

1

For me the issue was not having the same versions of kotlin I'm my modules and lib so I had to force them to use the same version

configurations.all {
    resolutionStrategy {
        eachDependency { DependencyResolveDetails details ->
            if (details.requested.group == 'org.jetbrains.kotlin') {
                details.useVersion versions.kotlin
            }
        }
    }}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.