kotlin.jvm.KotlinReflectionNotSupportedError:実行時にKotlinリフレクションの実装が見つかりません。kotlin-reflect.jarがあることを確認してください


83

コンパイルすると、上記のエラーが発生しました。以下の私のgradleファイル:-

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()
}

そして、私のプロジェクトは以下のようにグラドルします

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
}

何かを追加するのを逃しましたか?

回答:


158

エラーから、私は推測します:

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

あなたの中のdependencies標準ライブラリにで追加。


2
ありがとう!kotlinlang.org/docs/reference/using-gradle.htmlにあるcompile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version"ように必要であることがわかりました
Elye

おそらく明らかではありません:(1)一重引用符ではなく二重引用符である必要があります。そうでない場合、$ kotlin_versionは展開されません。(2)kotlinlang.org/docs/reference/…によると、:$ kotlin_versionは、> = 1.1の場合は省略できます。 .2。しかし、それは私には壊れているようです(私の$ kotlin_versionは現在1.2.10です)。エラーメッセージは、などの偽のURLを作成していることを示していますhttps://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-reflect//kotlin-reflect-.jar。だから、私はまだこの答えのレシピを使用しています。
ドンハッチ

4
言及する価値があるのimplementationは、現在、以下よりも好まれている指令compileです: implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
kip2 2018年

この依存関係に対するプロガードルールはありますか?
トリニティ

1

私にとって問題は、同じバージョンのkotlinがないことでした。私はモジュールとライブラリなので、同じバージョンを使用するように強制する必要がありました。

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

1

これをbuild.gradleに追加することで解決しました

implementation "org.jetbrains.kotlin:kotlin-reflect:1.3.61"
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.