android - 类 'kotlin.Unit' 是使用不兼容的 Kotlin 版本编译的。其元数据的二进制版本是1.6.0,预期版本是1.1.15

标签 android react-native kotlin

当我想将 "react-native-webview": "^11.22.4""react-native-video": "^5.2.0 一起使用时,我遇到了这个问题“。当我想使用React Native Video时出现问题

D:\Document\Nodejs\Github\trender\mobile-interface\node_modules\react-native-webview\android\src\main\java\com\reactnativecommunity\webview\events\TopShouldStartLoadWithRequestEvent.kt: (28, 21): 
Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
The class is loaded from C:/Users/Alex/.gradle/caches/transforms-3/dd0d00050014aa294dc6be948e80b5b3/transformed/jetified-kotlin-stdlib-1.6.10.jar!/kotlin/Unit.class

这是我的 build.gradle 文件

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "30.0.2"
        minSdkVersion = 21
        compileSdkVersion = 31
        targetSdkVersion = 30
        ndkVersion = "21.4.7075529"
        kotlin_version = '1.1.15'
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath ('com.google.gms:google-services:4.3.3')
        classpath("com.android.tools.build:gradle:4.2.2")
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenCentral()
        mavenLocal()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        }
        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }

        google()
        maven { url 'https://www.jitpack.io' }
        jcenter() {
            content {
                includeModule("com.yqritc", "android-scalablevideoview")
            }
        }
    }
}

最佳答案

在 android/build.gradle 中添加 kotlinVersion = "1.6.0"

    buildscript {
    ext {
        buildToolsVersion = "31.0.0"
        minSdkVersion = 21
        compileSdkVersion = 31
        targetSdkVersion = 31
        kotlinVersion = "1.6.0"

        if (System.properties['os.arch'] == "aarch64") {
            // For M1 Users we need to use the NDK 24 which added support for aarch64
            ndkVersion = "24.0.8215888"
        } else {
            // Otherwise we default to the side-by-side NDK version from AGP.
            ndkVersion = "21.4.7075529"
        }
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:7.0.4")
        classpath("com.facebook.react:react-native-gradle-plugin")
        classpath("de.undercouch:gradle-download-task:4.1.2")
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

关于android - 类 'kotlin.Unit' 是使用不兼容的 Kotlin 版本编译的。其元数据的二进制版本是1.6.0,预期版本是1.1.15,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72839008/

相关文章:

ios - 带有 Kotlin/Native 的原生 iOS 项目中的 Kotlin 文件

object - Kotlin:类中对象和伴随对象之间的区别

java - 在没有库的情况下转换为 JSONObject 并返回 Kotlin

javascript - 为什么我在 iOS 模拟器中收到这个奇怪的错误?

android - 如何在 Android NativeScript 应用程序上更改 TextView 底部强调色

安卓内存泄漏

android - 即使应用程序在任何屏幕尺寸上运行,如何将这四个按钮设置为一行?

javascript - 按钮单击时更改颜色

ios - 无法使用react-native-svg。 Xcode 无法打开 PerformanceBezier 和 QuartzBookPack

java - 我如何通知我的应用程序一个文件已从 SDCard (Android) 中删除?