2023-02-13 Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.

注:

Rn:(react-nativ)

as:(android studio)

电脑:win10

测试环境:Android

在新电脑用as跑一下老项目,报错:Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.

翻译:模块是用不兼容的Kotlin版本编译的。其元数据的二进制版本为1.6.0,预期版本为1.1.15。

踩坑(可忽略不看):

1、更新Rn版本。kotlin需要1.1.15版本,而我已经安装了1.6.0版本,我没有去卸载kotlin,然后再安装1.1.15,而是直接更新了Rn(事实上我不会卸载kotlin,因为我压根不知道它在哪);

更新Rn是因为别的网友给我提供的方案,我照做了,然并卵,我把 Rn 0.64.2 升级 到了 ^0.71.2,用as再跑一下,结果build failed。

我强烈建议非必要不更新Rn,我又把它的版本给恢复了 0.64.2。

2、更新kotlin版本。然并卵。

3、(解决方案):请不要降低kotlin的版本,它说它想要1.1.15版本,而你已经是1.6.0了,那么请你在项目的build.gradle文件中的buildscript对象中添加一行代码:

ext.kotlin_version = '1.6.0',然后在同文件中,找到dependencies对象,添加一行:classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"。
总共就两行代码,我的代码如下:
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "29.0.3"
        minSdkVersion = 21
        compileSdkVersion = 31
        targetSdkVersion = 29
        ndkVersion = "20.1.5948944"
        kotlin_version = '1.6.0' // ❗🔺添加这行代码
    }
    
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:4.1.0")
        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 { 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() jcenter() maven { url 'https://www.jitpack.io' } } }

OK!焜耀了我击添的问题终于解决了,但我想你接下来会遇到诸如内存不足的问题!。。。。

posted @ 2023-02-13 11:38  叶乘风  阅读(4169)  评论(0编辑  收藏  举报