You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter升级Firebase依赖后Gradle插件废弃问题求助

升级Flutter和Firebase后Android构建警告的解决方案

升级Flutter(3.19.0稳定版)及Firebase依赖后,构建Android应用时出现两类核心警告:Gradle插件命令式应用方式废弃、NDK版本不足,尝试flutter clean和flutter build无效。以下是针对性解决方案:

一、修复Gradle插件命令式应用废弃警告

该警告源于当前使用了废弃的apply from方式引入插件,需迁移至声明式plugins块。

1. 修改settings.gradle

替换原有插件引入代码,修改后完整内容:

include ':app'

def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
def properties = new Properties()

assert localPropertiesFile.exists()
localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }

def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"

plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0" apply false
}

2. 修改app/build.gradle

将开头的apply plugin和apply from语句替换为plugins块,修改后开头部分如下:

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new FileNotFoundException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

plugins {
    id "com.android.application"
    id "kotlin-android"
    id "dev.flutter.flutter-gradle-plugin"
    id "com.google.gms.google-services" // 将原来末尾的apply plugin移到此处
}

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
 }

文件其余部分(android块、flutter块、dependencies等)保持不变。

二、修复NDK版本不足警告

直接在app/build.gradle的android块中指定要求的NDK版本:
找到android块中的ndkVersion flutter.ndkVersion,替换为:

ndkVersion "25.1.8937393"

修改后的android块开头示例:

android {
    namespace "com.example.egyreef_smart_doser"
    compileSdkVersion flutter.compileSdkVersion
    ndkVersion "25.1.8937393"

    // 其余原有代码不变
}

三、关于deprecated API和unchecked操作的提示

日志中提到的cloud_firestore插件内部代码警告,属于插件自身兼容性问题,不影响当前应用构建,等待插件官方更新即可。若需查看详细警告信息,可在编译时添加-Xlint:deprecation或-Xlint:unchecked参数,但一般无需额外处理。

内容的提问来源于stack exchange,提问作者Mohamed Gendia

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 12:43:16