Flutter项目执行flutter build apk时出现:generateReleaseBuildConfig错误
执行flutter build apk时触发如下错误:
FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':generateReleaseBuildConfig'. > Error while evaluating property 'applicationId' of task ':generateReleaseBuildConfig' > Failed to calculate the value of task ':generateReleaseBuildConfig' property 'applicationId'. > Failed to query the value of property 'applicationId'. > Manifest file does not exist: C:\Repos\yousafe\android\src\main\AndroidManifest.xml * 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 8s Running Gradle task 'assembleRelease'... 9.2s Gradle task assembleRelease failed with exit code 1
实际AndroidManifest.xml位于Android\app\src\main目录下,settings.gradle和build.gradle无异常,Flutter Doctor仅提示未安装Android Studio,其余检查正常。以下是具体排查步骤:
检查Gradle模块与路径配置
确认android/settings.gradle中是否包含:app模块配置(include ':app'),同时检查android/build.gradle和android/app/build.gradle中,是否存在错误指定Manifest路径的sourceSets配置,确保路径指向app/src/main下的Manifest文件。清理项目缓存
执行以下命令清理Flutter和Gradle缓存,解决缓存导致的路径识别异常:flutter clean cd android gradlew clean cd .. flutter pub get重新生成Android项目文件
若缓存清理无效,可重新生成Android配置文件(执行前备份自定义的Manifest、build.gradle等文件):flutter create --platforms android .验证路径与文件权限
检查项目路径是否存在大小写混合(如Android与android混用),Windows系统下Gradle可能因大小写识别问题出错;同时确认AndroidManifest.xml文件当前用户有读取权限,避免权限限制导致无法读取。手动指定Manifest路径(临时方案)
在android/app/build.gradle的android块中手动指定Manifest路径:android { sourceSets { main { manifest.srcFile 'src/main/AndroidManifest.xml' } } // 其他原有配置 }
内容的提问来源于stack exchange,提问作者Samson Royal

