例外:不支持的 Android 插件版本:4.2.1。当flutter运行时--release

day*_*mer 4 android android-studio android-gradle-plugin flutter

我正在使用最新的 flutter 稳定版本 flutter doctor -v 如下:

\n
    [\xe2\x9c\x93] Flutter (Channel stable, 2.2.2, on Mac OS X 10.15.7 19H2 darwin-x64, locale en-IN)\n    \xe2\x80\xa2 Flutter version 2.2.2 at /Users/daydreamers/Documents/development/flutter\n    \xe2\x80\xa2 Framework revision d79295af24 (2 weeks ago), 2021-06-11 08:56:01 -0700\n    \xe2\x80\xa2 Engine revision 91c9fc8fe0\n    \xe2\x80\xa2 Dart version 2.13.3\n\n[\xe2\x9c\x93] Android toolchain - develop for Android devices (Android SDK version 30.0.2)\n    \xe2\x80\xa2 Android SDK at /Users/daydreamers/Library/Android/sdk\n    \xe2\x80\xa2 Platform android-30, build-tools 30.0.2\n    \xe2\x80\xa2 ANDROID_HOME = /Users/daydreamers/Library/Android/sdk\n    \xe2\x80\xa2 Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java\n    \xe2\x80\xa2 Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)\n    \xe2\x80\xa2 All Android licenses accepted.\n\n[\xe2\x9c\x93] Xcode - develop for iOS and macOS\n    \xe2\x80\xa2 Xcode at /Applications/Xcode.app/Contents/Developer\n    \xe2\x80\xa2 Xcode 12.3, Build version 12C33\n    \xe2\x80\xa2 CocoaPods version 1.10.1\n\n[\xe2\x9c\x97] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome)\n    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.\n\n[\xe2\x9c\x93] Android Studio (version 4.2)\n    \xe2\x80\xa2 Android Studio at /Applications/Android Studio.app/Contents\n    \xe2\x80\xa2 Flutter plugin can be installed from:\n       https://plugins.jetbrains.com/plugin/9212-flutter\n    \xe2\x80\xa2 Dart plugin can be installed from:\n       https://plugins.jetbrains.com/plugin/6351-dart\n    \xe2\x80\xa2 Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)\n\n[\xe2\x9c\x93] VS Code (version 1.57.1)\n    \xe2\x80\xa2 VS Code at /Applications/Visual Studio Code.app/Contents\n    \xe2\x80\xa2 Flutter extension version 3.23.0\n\n[\xe2\x9c\x93] Connected device (1 available)\n
Run Code Online (Sandbox Code Playgroud)\n

我有 Android 版 Kotlin 代码,Kotlin 版本是

\n
ext.kotlin_version = '1.5.20'\n
Run Code Online (Sandbox Code Playgroud)\n

我的依赖项中有这个:

\n
classpath 'com.android.tools.build:gradle:4.2.1'\n
Run Code Online (Sandbox Code Playgroud)\n

运行 flutter run --release 时出现错误,但flutter run工作正常。

\n
Exception: Unsupported Android Plugin version: 4.2.1.\n
Run Code Online (Sandbox Code Playgroud)\n

我尝试过来自SO的其他答案,例如更新Kotlin目标VM的JVM版本(我将其从8设置为11)。

\n

distributionUrl=https\\://services.gradle.org/distributions/gradle-6.7.1-all.zip我在 gradle-wrapper.properties 中也有。

\n

任何帮助是极大的赞赏。

\n

fla*_*oad 5

看看你的应用程序中是否有类似下面的内容build.gradle(app/src/build.gradle)

    productFlavors {
        app_dev {
            dimension "version"
            applicationIdSuffix ".dev"
        }
        app_stg {
            signingConfig signingConfigs.debug
            dimension "version"
            applicationIdSuffix ".stg"
        }
        app_prod {
            signingConfig signingConfigs.release
            dimension "version"
        }
    }
Run Code Online (Sandbox Code Playgroud)

如果确实有类似的内容,那么您需要转到 “运行” -> “编辑配置” ->“选择main.dart左侧”-> “构建风味”内,将“app_dev”放入文本框内(字符串可以是任何内容,具体取决于你的里面有什么productFlavors { ... }

这帮助我解决了我的问题。