首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法初始化类DefaultKotlinSourceSetKt

无法初始化类DefaultKotlinSourceSetKt
EN

Stack Overflow用户
提问于 2020-05-10 15:42:38
回答 2查看 1.9K关注 0票数 2

我遵循了安卓的解毒指南在我的反应-本机项目- https://github.com/wix/Detox/blob/master/docs/Introduction.Android.md上安装。但是在运行react-native run-android之后,构建了这个应用程序。我得到以下错误评估项目:detox

代码语言:javascript
复制
1: Task failed with an exception.
-----------
* Where:
Build file 'C:\Users\brian\Documents\Projects\react-native-prototyping\node_modules\detox\android\detox\build.gradle' line: 2

* What went wrong:
A problem occurred evaluating project ':detox'.
> Could not initialize class org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSetKt

我看过他们的问题追踪器,但没有看到相关的问题。从Kotlin周围的类似问题来看,似乎这可能是我的kotlin和gradle版本之间的冲突。但我不知道如何确定要使用的正确版本。我还在android文件夹中做了一个./gradlew clean,但没有结果。

问题:

如何解决“未能初始化类..sources.DefaultKotlinSourceSetKt”错误?

我的分级和包设置的一些细节如下:

代码语言:javascript
复制
"devDependencies": {
        "detox": "^16.5.0",
    },

根build.gradle:

代码语言:javascript
复制
buildscript {
    ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 18
        compileSdkVersion = 28
        targetSdkVersion = 28
        kotlinVersion = '1.3.0'

    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:3.5.2")
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

应用程序/build.gradle:

代码语言:javascript
复制
android {
    compileSdkVersion rootProject.ext.compileSdkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        applicationId "com.testapp"
        minSdkVersion rootProject.ext.minSdkVersion
        compileSdkVersion rootProject.ext.compileSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        // detox automated tests config
        // This will later be used to control the test apk build type
        testBuildType System.getProperty('testBuildType', 'debug')  
        testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
        }
    }
    signingConfigs {
        debug {
            storeFile file('debug.keystore')
            storePassword 'android'
            keyAlias 'androiddebugkey'
            keyPassword 'android'
        }
        release {
            storeFile file(System.getenv("KEYSTORE") ?: "keystore.jks")
            storePassword System.getenv("KEYSTORE_PASSWORD")
            keyAlias System.getenv("KEY_ALIAS")
            keyPassword System.getenv("KEY_PASSWORD")
        }
    }
    buildTypes {
        debug {
            signingConfig signingConfigs.debug
        }
        release {
            // Caution! In production, you need to generate your own keystore file.
            // see https://facebook.github.io/react-native/docs/signed-apk-android.
            signingConfig signingConfigs.release
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            // Detox-specific additions to pro-guard
            proguardFile "${rootProject.projectDir}/../node_modules/detox/android/detox/proguard-rules-app.pro"
        }
    }

    packagingOptions {
        pickFirst "lib/armeabi-v7a/libc++_shared.so"
        pickFirst "lib/arm64-v8a/libc++_shared.so"
        pickFirst "lib/x86/libc++_shared.so"
        pickFirst "lib/x86_64/libc++_shared.so"
    }



dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    //noinspection GradleDynamicVersion
    implementation "com.facebook.react:react-native:+"  // From node_modules


    if (enableHermes) {
        def hermesPath = "../../node_modules/hermes-engine/android/";
        debugImplementation files(hermesPath + "hermes-debug.aar")
        releaseImplementation files(hermesPath + "hermes-release.aar")
    } else {
        implementation jscFlavor
    }

    androidTestImplementation(project(path: ":detox"))
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-05-10 16:11:21

结果,我不得不在build.gradle中更改我的kotlin版本,以匹配我的gradle版本-- buildscript。见- https://github.com/wix/Detox/blob/master/examples/demo-react-native/android/build.gradle

代码语言:javascript
复制
 {
    ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 18
        compileSdkVersion = 28
        targetSdkVersion = 28
        kotlinVersion = '1.3.41'

    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:3.5.2")
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
票数 4
EN

Stack Overflow用户

发布于 2020-06-26 02:10:15

This answer帮了我。我需要更新我的Kotlin版本。

Tools -> Kotlin ->配置Kotlin插件更新->现在检查更新

更新后,我更改了build.gradle (项目)中的版本,以与新更新的版本相匹配。即

代码语言:javascript
复制
buildscript {
    ext {
        kotlin_version = '1.3.72'
        ...
    }
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61714619

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档