Parameter specified as non-null is null: method com.flutter.gradle.VersionUtils.mostRecentSemanticVersion, parameter....

原创文章
声明:作者声明此文章为原创,未经作者同意,请勿转载,若转载,务必注明本站出处,本平台保留追究侵权法律责任的权利。
全栈老韩
全栈工程师,擅长iOS App开发、前端(vue、react、nuxt、小程序&Taro)开发、Flutter、React Native、后端(midwayjs、golang、express、koa)开发、docker容器、seo优化等。

记一次flutter编译报错的问题.

我的pubspec.yaml中引入了better_player_plusflutter_vlc_player,配置是:

pubspec.yaml 复制代码
...
dependencies:
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.8
  better_player_plus: ^1.0.8
  flutter_vlc_player: ^7.4.3

dev_dependencies:
  flutter_test:
    sdk: flutter
...

问题1

Launching lib/main.dart on sdk gphone64 x86 64 in debug mode...
Running Gradle task 'assembleDebug'...
Warning: Flutter support for your project's Android Gradle Plugin version (Android Gradle Plugin version 8.1.0) will soon be dropped. Please upgrade your Android Gradle Plugin version to a version of at least Android Gradle Plugin version 8.3.0 soon.
Alternatively, use the flag "--android-skip-build-dependency-validation" to bypass this check.

Potential fix: Your project's AGP version is typically defined in the plugins block of the settings.gradle file (/Users/edy/Desktop/test/android/settings.gradle), by a plugin with the id of com.android.application.
If you don't see a plugins block, your project was likely created with an older template version. In this case it is most likely defined in the top-level build.gradle file (/Users/edy/Desktop/test/android/build.gradle) by the following line in the dependencies block of the buildscript: "classpath 'com.android.tools.build:gradle:'".

FAILURE: Build failed with an exception.

  • What went wrong:
    A problem occurred configuring project ':better_player_plus'.
    Parameter specified as non-null is null: method com.flutter.gradle.VersionUtils.mostRecentSemanticVersion, parameter version1

  • Try:
    Run with --stacktrace option to get the stack trace.
    Run with --info or --debug option to get more log output.
    Run with --scan to get full insights.
    Get more help at https://help.gradle.org.

BUILD FAILED in 1m 15s
Error: Gradle task assembleDebug failed with exit code 1

报错截图:
fllutter gradle error

这个问题出现在我使用了flutter的库:flutter_vlc_player: ^7.4.3,但我本地的flutter sdk环境是3.27.0-0.1.pre的问题.

在运行Android的时候,我Android studio中默认的gradle默认是8.1.0的,所以也会有警告.

解决办法

    1. 升级本地的flutter sdk
terminal 复制代码
flutter channel beta # 切换到最新的beta channel
    1. 更新dart版本
      之前是
pubspec.yaml 复制代码
...
environment:
  sdk: ^3.6.0-216.1.beta
...

升级后:

pubspec.yaml 复制代码
...
environment:
  sdk: ^3.7.0
...
    1. 配置android/settings.gradle
      之前:
settings.gradle 复制代码
...
plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version "8.1.0" apply false
    id "org.jetbrains.kotlin.android" version "1.8.22" apply false
}

include ":app"

配置后:

settings.gradle 复制代码
...
plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version "8.3.0" apply false // 升级这里
    id "org.jetbrains.kotlin.android" version "1.8.22" apply false
}

include ":app"

到这一步,再编译会有新的报错,错误在下面贴出来,并解决。

问题2

Launching lib/main.dart on sdk gphone64 x86 64 in debug mode...
Running Gradle task 'assembleDebug'...

FAILURE: Build failed with an exception.

  • Where:
    Build file '/Users/edy/Desktop/test/android/app/build.gradle' line: 2

  • What went wrong:
    An exception occurred applying plugin request [id: 'com.android.application']
    Failed to apply plugin 'com.android.internal.version-check'.
    Minimum supported Gradle version is 8.4. Current version is 8.3. If using the gradle wrapper, try editing the distributionUrl in /Users/edy/Desktop/test/android/gradle/wrapper/gradle-wrapper.properties to gradle-8.4-all.zip

  • Try:
    Run with --stacktrace option to get the stack trace.
    Run with --info or --debug option to get more log output.
    Run with --scan to get full insights.
    Get more help at https://help.gradle.org.

BUILD FAILED in 27s
Error: Gradle task assembleDebug failed with exit code 1

问题截图:
flutter gradle 8.4

从截图中已经看出解决办法了,提示我们要修改gradle-wrapper.properties的版本

解决办法

修改android/gradle/wrapper/gradle-wrapper.properties配置
之前配置是:

gradle-wrapper.properties 复制代码
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip

更新配置后:

gradle-wrapper.properties 复制代码
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip

再次运行,问题解决了。

希望对大家有借鉴意义。

暂无评论,快来发表第一条评论吧