当前位置:   article > 正文

[Flutter]打包APK报错The binary version of its metadata is 1.9.0, expected version is 1.6.0.

the binary version of its metadata is 1.9.0, expected version is 1.6.0.

问题:

flutter run运行项目没任何问题,但打包时终端会报错,最后打包还能成功。虽然能打包,不过这个错误警告还是要处理。

e: /Users/gamin/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.9.23/dbaadea1f5e68f790d242a91a38355a83ec38747/kotlin-stdlib-1.9.23.jar!/META-INF/kotlin-stdlib-jdk8.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.6.0.

Flutter Fix

│ [!] Your project requires a newer version of the Kotlin Gradle plugin.                           

│ Find the latest version on https://kotlinlang.org/docs/releases.html#release-details, then update

│ /Users/gamin/Documents/sanqi/app_teleprompter/android/build.gradle:                             

│ ext.kotlin_version = '<latest-version>'

在stackoverflow上有这个问题

https://stackoverflow.com/questions/67699823/module-was-compiled-with-an-incompatible-version-of-kotlin-the-binary-version-o/74425347#74425347

修复:

1.在项目级android/build.gradle如下配置

  1. buildscript {
  2.     ext.kotlin_version = '1.9.23' // 定义一个扩展属性来指定 Kotlin 的版本
  3.     repositories {
  4.         google()
  5.         mavenCentral()
  6.     }
  7.     dependencies {
  8.         classpath 'com.android.tools.build:gradle:8.1.3'
  9.         classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
  10.     }
  11. }
  12. allprojects {
  13.     repositories {
  14.         google()
  15.         mavenCentral()
  16.     }
  17. }
  18. rootProject.buildDir = '../build'
  19. subprojects {
  20.     project.buildDir = "${rootProject.buildDir}/${project.name}"
  21. }
  22. subprojects {
  23.     project.evaluationDependsOn(':app')
  24. }
  25. tasks.register("clean", Delete) {
  26.     delete rootProject.buildDir
  27. }

2.在settings.gradle中注意com.android.application和org.jetbrains.kotlin.android指定的版本

  1. plugins {
  2. ...
  3.     id "com.android.application" version "8.1.3" apply false
  4.     id "org.jetbrains.kotlin.android" version "1.9.23" apply false
  5. }

3.在android/gradle/wrapper/gradle-wrapper.properties指定Gradle Wrapper的版本

  1. ...
  2. # distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-all.zip
  3. distributionUrl = https\://services.gradle.org/distributions/gradle-8.4-bin.zip

4.配置的版本需要对应

比如,文档中说Android Gradle插件版本为8.3时所需的最低Gradle版本为8.4。这时,你com.android.tools.build:gradle配置8.3.x后Gradle Wrapper版本就要改成gradle-8.4-bin.zip。

本来上面我使用版本8.3.1,但同步时报错,就改成8.1.3了。

The project is using an incompatible version (AGP 8.3.1) of the Android Gradle plugin.  Latest supported version is AGP 8.1.3

注意:有时遇到同步问题,就去Android Studio中去同步,会有错误提示。在VS Code中运行时,看不到详细提示。

5.相关网站

其中ext.kotlin_version版本信息查询:

Kotlin releases | Kotlin Documentation

com.android.tools.build版本信息查询:

https://maven.google.com/web/index.html?q=com.android.tools.build

https://mvnrepository.com/artifact/com.android.tools.build/gradle

Android Gradle插件版本配置说明:

https://developer.android.com/build/releases/gradle-plugin?hl=zh-cn#updating-gradle

distributionUrl查询:

https://services.gradle.org/distributions/

6.重新打包APK

  1. $ flutter clean
  2. $ flutter pub get
  3. $ flutter run
  4. $ flutter build apk

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/643415
推荐阅读
相关标签
  

闽ICP备14008679号