错误:您的项目在升级后需要更新版本的KotlinGradle插件

c7rzv4ha  于 2022-11-14  发布在  Kotlin
关注(0)|答案(1)|浏览(178)

在运行我的项目时出现了一个错误
您的项目需要更新版本的KotlinGradle插件。
于是,我转到JetBrains GitHub Repo,发现最新的版本是:1.7.20.
因此,我转到android/build.gradle并将Kotlin版本更改为

ext.kotlin_version = "1.7.20"

dependencies {
  classpath 'com.android.tools.build:gradle:7.1.2'
  classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.20"
}

和android/应用程序/构建.gradle

apply plugin: 'kotlin-android'

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.20"
    implementation "org.jetbrains.kotlin:kotlin-reflect:1.7.20"
}

我的gradle-wrapper.properties是distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
flutter doctor -v的结果

[√] Flutter (Channel stable, 3.3.2, on Microsoft Windows [Version 10.0.19044.2006], locale en-US)
    • Flutter version 3.3.2 on channel stable at C:\Users\sayed\Documents\flutter_windows_2.2.3-stable\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision e3c29ec00c (4 weeks ago), 2022-09-14 08:46:55 -0500
    • Engine revision a4ff2c53d8
    • Dart version 2.18.1
    • DevTools version 2.15.0

[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at C:\Users\sayed\AppData\Local\Android\sdk
    • Platform android-33, build-tools 31.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[X] Visual Studio - develop for Windows
    X Visual Studio not installed; this is necessary for Windows development.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components

[√] Android Studio (version 2021.3)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[√] VS Code (version 1.72.0)
    • VS Code at C:\Users\sayed\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.50.0

[√] VS Code, 64-bit edition (version 1.63.0)
    • VS Code at C:\Program Files\Microsoft VS Code
    • Flutter extension version 3.50.0

[√] Connected device (4 available)
    • DRA LX2 (mobile)  • 5LX9K18817915788 • android-arm64  • Android 8.1.0 (API 27)
    • Windows (desktop) • windows          • windows-x64    • Microsoft Windows [Version 10.0.19044.2006]
    • Chrome (web)      • chrome           • web-javascript • Google Chrome 105.0.5195.127
    • Edge (web)        • edge             • web-javascript • Microsoft Edge 106.0.1370.37

[√] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.

当构建apk或运行发布错误时,会出现类似这样的错误

Exception: Gradle task assembleRelease failed with exit code 1
#0      throwToolExit (package:flutter_tools/src/base/common.dart:10:3)
#1      AndroidGradleBuilder.buildGradleApp (package:flutter_tools/src/android/gradle.dart:446:7)
<asynchronous suspension>
#2      AndroidGradleBuilder.buildApk (package:flutter_tools/src/android/gradle.dart:184:5)
<asynchronous suspension>
#3      AndroidDevice.startApp (package:flutter_tools/src/android/android_device.dart:575:7)
<asynchronous suspension>
#4      FlutterDevice.runCold (package:flutter_tools/src/resident_runner.dart:504:33)
<asynchronous suspension>
#5      ColdRunner.run (package:flutter_tools/src/run_cold.dart:57:28)
<asynchronous suspension>
#6      RunCommand.runCommand (package:flutter_tools/src/commands/run.dart:706:27)
<asynchronous suspension>
#7      FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1209:27)
<asynchronous suspension>
#8      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
<asynchronous suspension>
#9      CommandRunner.runCommand (package:args/command_runner.dart:209:13)
<asynchronous suspension>
#10     FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:281:9)
<asynchronous suspension>
#11     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
<asynchronous suspension>
#12     FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:229:5)
<asynchronous suspension>
#13     run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:62:9)
<asynchronous suspension>
#14     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
<asynchronous suspension>
#15     main (package:flutter_tools/executable.dart:91:3)
<asynchronous suspension>

我怎样才能解决这个问题?

rqqzpn5f

rqqzpn5f1#

尝试使用高于7.2的gradle版本,如

distributionUrl = "https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip"

在此路径中:android\gradle\wrapper\gradle-wrapper.properties

相关问题