chore: save state before monorepo refactor

This commit is contained in:
Max 2026-03-19 16:43:52 +08:00
parent c36ea7bfc8
commit 163f0a89f9
4 changed files with 83 additions and 0 deletions

38
doc/plan.md Normal file
View File

@ -0,0 +1,38 @@
# Role
你是一个拥有 8 年经验的资深 Flutter & Android 系统架构师。你擅长对已有的 Flutter 遗留项目进行工程化改造特别是接入多风味Flavors和白标White-label架构。
# Context & Goal
我目前已经有了一个开发好的 Flutter 壳项目。现在需要对这个**已有项目**进行 Flavors 改造,使其能够通过不同的打包命令,输出两个完全独立的 App。
**注意:本项目是纯 Android 定制平板项目,绝对不需要任何 iOS 相关的配置和代码!**
这两个 App 是:
1. 劝学 (Flavor: `quanxue`) - 包名: `com.wanmake.quanxue`,应用名: "劝学"
2. 点智学 (Flavor: `dianzhi`) - 包名: `com.wanmake.dianzhi`,应用名: "点智学"
# Execution Steps (请提供修改现有文件的差异代码与执行步骤)
## Step 1: Dart 侧运行环境变量改造
由于是已有项目,请帮我生成一个优雅的单例配置类 `AppEnvironment`
1. 使用 `const String.fromEnvironment('APP_FLAVOR')` 来捕获打包时传入的参数。
2. 根据捕获到的 Flavor向外暴露当前 App 的主题色、`appName` 和对应的接口 `baseUrl`
3. 请给出 `main.dart` 中如何初始化并读取这个配置类的极简示例。
## Step 2: Android 端 Gradle 深度改造
请直接输出 `android/app/build.gradle` 需要修改的补丁代码Patch
1. 移除 `defaultConfig` 中的硬编码 `applicationId`
2. 增加 `flavorDimensions "app_type"`
3. 编写 `productFlavors` 代码块,配置 `quanxue``dianzhi`,分别注入其 `applicationId`
4. 使用 `resValue` 将 "劝学" 和 "点智学" 注入为 `app_name`
## Step 3: AndroidManifest.xml 动态化
请给出 `android/app/src/main/AndroidManifest.xml` 的修改代码:
1. 将 `<application>` 标签的 `android:label` 属性修改为读取注入的 `@string/app_name`
2. 确保没有任何硬编码的应用名称残留。
## Step 4: 资源配置文件 (YAML) 生成
1. 请帮我生成 4 个 YAML 配置文件,用于配合 `flutter_launcher_icons``flutter_native_splash` 插件。
2. 为 `quanxue``dianzhi` 分别配置独立的图标和启动页路径,路径统一指向 `assets/branding/{flavor}/...`
3. **关键:** 在这 4 个 YAML 文件中,必须显式设置 `android: true` 并且 **`ios: false`**。
## Step 5: 打包与测试脚本
提供完整的终端测试与打包命令示例,仅限 Android 平台(包含如何传入 `--flavor``--dart-define` 打包 APK )。

View File

@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig"

View File

@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Generated.xcconfig"

43
ios/Podfile Normal file
View File

@ -0,0 +1,43 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '13.0'
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}
def flutter_root
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
unless File.exist?(generated_xcode_build_settings_path)
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
end
File.foreach(generated_xcode_build_settings_path) do |line|
matches = line.match(/FLUTTER_ROOT\=(.*)/)
return matches[1].strip if matches
end
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end
require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)
flutter_ios_podfile_setup
target 'Runner' do
use_frameworks!
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
target 'RunnerTests' do
inherit! :search_paths
end
end
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
end