flutter gradle版本更新到8.9

gradle版本更新到8.9

因为java版本更新到21.0.5,打开flutter项目时vscode提示需求更新gradle版本

项目一些需要变更的位置

gradle-wrapper.properties

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

报错提示: Cannot use @TaskAction annotation on method IncrementalTask.taskAction$gradle_core() because interface

复制代码
Script 'D:\Program Files\flutter\packages\flutter_tools\gradle\src\main\groovy\flutter.groovy' line: 1349
* Where:
Script 'D:\Program Files\flutter\packages\flutter_tools\gradle\src\main\groovy\flutter.groovy' line: 1349

* What went wrong:

* What went wrong:
A problem occurred evaluating root project 'android'.
A problem occurred evaluating root project 'android'.
> A problem occurred configuring project ':app'.
   > Could not create task ':app:copyFlutterAssetsDebug'.
> A problem occurred configuring project ':app'.
   > Could not create task ':app:copyFlutterAssetsDebug'.
      > Could not create task ':app:mergeDebugAssets'.
      > Could not create task ':app:mergeDebugAssets'.
         > Cannot use @TaskAction annotation on method IncrementalTask.taskAction$gradle_core() because interface org.gradle.api.tasks.incremental.IncrementalTaskInputs is not a valid parameter to an action method.  

android/build.gradle两处变更

复制代码
buildscript {
    ...略
    dependencies {
        classpath 'com.android.tools.build:gradle:8.7.0' // 对应gradle8.9版本
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
    ...略
}

gradle与插件版本对应关系

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

报错: Could not create an instance of type com.android.build.api.variant.impl.LibraryVariantBuilderImpl.

复制代码
FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':uni_links'.
> Could not create an instance of type com.android.build.api.variant.impl.LibraryVariantBuilderImpl.
   > Namespace not specified. Specify a namespace in the module's build file: C:\Users\alex\AppData\Local\Pub\Cache\hosted\pub.flutter-io.cn\uni_links-0.5.1\android\build.gradle. See https://d.android.com/r/tools/upgrade-assistant/set-namespace for information about setting the namespace.

     If you've specified the package attribute in the source AndroidManifest.xml, you can use the AGP Upgrade Assistant to migrate to the namespace value in the build file. Refer to https://d.android.com/r/tools/upgrade-assistant/agp-upgrade-assistant for general information about using the AGP Upgrade Assistant.

* 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.

android/app/build.gradle

增加namespace, 包括所有外部引入的包,否则会报如上错误

复制代码
...略
android {
    namespace 'xxx.xxx.xxx' // 增加namespace
}
...略
相关推荐
小雨下雨的雨5 分钟前
Flutter跨平台开发实战: 鸿蒙与循环交互艺术:无限循环的 Banner 引擎
flutter·ui·华为·交互·harmonyos·鸿蒙系统
奋斗的小青年!!27 分钟前
Flutter与鸿蒙深度融合:打造物理引擎驱动的3D卡片交互体验
flutter·3d·harmonyos·鸿蒙
恋猫de小郭37 分钟前
Google DeepMind :RAG 已死,无限上下文是伪命题?RLM 如何用“代码思维”终结 AI 的记忆焦虑
前端·flutter·ai编程
行者962 小时前
用Flutter打造适配OpenHarmony的打卡组件:实践与优化
flutter·harmonyos·鸿蒙
cn_mengbei2 小时前
Flutter for OpenHarmony 实战:DropdownButton 下拉选择按钮详解
flutter
cn_mengbei2 小时前
Flutter for OpenHarmony 实战:Checkbox 复选框详解
flutter
小雨下雨的雨2 小时前
Flutter跨平台开发实战: 鸿蒙与循环交互艺术:虚拟列表与百万级数据性能巅峰
flutter·华为·交互·harmonyos·鸿蒙系统
不爱吃糖的程序媛2 小时前
Flutter-OH三方库适配:从实践到社区共建的样板间打造
flutter
kirk_wang2 小时前
Flutter艺术探索-Flutter图片加载与缓存优化
flutter·移动开发·flutter教程·移动开发教程