Browse Source

feat : 自动打包工具

dev
徐振升 3 weeks ago
parent
commit
fcc7684ad5
  1. 119
      build_flutter_app.dart
  2. 4
      linux/flutter/generated_plugin_registrant.cc
  3. 1
      linux/flutter/generated_plugins.cmake
  4. 4
      macos/Flutter/GeneratedPluginRegistrant.swift
  5. 182
      pubspec.lock
  6. 2
      pubspec.yaml
  7. 3
      windows/flutter/generated_plugin_registrant.cc
  8. 1
      windows/flutter/generated_plugins.cmake

119
build_flutter_app.dart

@ -0,0 +1,119 @@
import 'dart:io';
import 'dart:convert';
void main(List<String> arguments) async {
print('🚀 开始构建Flutter Android应用...');
// ARM64 + ARM32
final targetPlatform = arguments.contains('--arm64-only')
? 'android-arm64'
: 'android-arm64,android-arm';
try {
// Flutter环境
await checkFlutterEnvironment();
// Flutter Android应用
final apkPath = await buildFlutterApp(targetPlatform);
// version.json文件
await generateVersionJson(apkPath, targetPlatform);
print('✅ 构建完成!');
print('📦 APK位置: $apkPath');
} catch (e) {
print('❌ 构建过程中出现错误: $e');
exit(1);
}
}
Future<String> buildFlutterApp(String targetPlatform) async {
print('📱 正在构建Flutter Android应用...');
print('🎯 目标平台: $targetPlatform');
//
print('🧹 清理构建缓存...');
await runFlutterCommand(['clean']);
// pub依赖
print('📦 获取依赖...');
await runFlutterCommand(['pub', 'get']);
// APK
print('🔨 构建Release APK...');
await runFlutterCommand([
'build',
'apk',
'--release',
'--target-platform=$targetPlatform',
]);
print('✅ Flutter应用构建成功!');
// APK文件名
String apkName;
if (targetPlatform == 'android-arm64') {
apkName = 'app-arm64-release.apk';
} else if (targetPlatform == 'android-arm') {
apkName = 'app-arm-release.apk';
} else {
apkName = 'app-release.apk';
}
return 'build/app/outputs/flutter-apk/$apkName';
}
Future<void> runFlutterCommand(List<String> args) async {
final result = await Process.run('flutter', args, runInShell: true);
if (result.exitCode != 0) {
throw Exception('Flutter命令执行失败: ${result.stderr}');
}
}
Future<void> generateVersionJson(String apkPath, String targetPlatform) async {
print('📄 正在生成version.json文件...');
final apkFile = File(apkPath);
String fileSize = '未知';
if (await apkFile.exists()) {
final apkSize = await apkFile.length();
fileSize = '${(apkSize / (1024 * 1024)).toStringAsFixed(1)}MB';
print('📦 APK文件大小: $fileSize');
}
final now = DateTime.now();
final buildTime =
'${now.year}-${now.month.toString().padLeft(2, '0')}-${now.day.toString().padLeft(2, '0')} ${now.hour.toString().padLeft(2, '0')}:${now.minute.toString().padLeft(2, '0')}';
final versionInfo = {
"version": "1.0.1",
"build_number": getBuildNumber(),
"build_time": buildTime,
"target_platform": targetPlatform,
"file_size": fileSize,
"url": "http://xhota.anxincloud.cn/problem/app-release-problem.apk",
"description": "1. 修复了xxx bug。\n2. 新增了xxx功能。\n3. 优化了用户体验。",
"platform": "android",
};
final jsonFile = File('build/app/outputs/flutter-apk/version.json');
await jsonFile.writeAsString(
const JsonEncoder.withIndent(' ').convert(versionInfo),
);
print('✅ version.json文件生成成功!');
}
String getBuildNumber() {
final now = DateTime.now();
return '${now.year}${now.month.toString().padLeft(2, '0')}${now.day.toString().padLeft(2, '0')}${now.hour.toString().padLeft(2, '0')}${now.minute.toString().padLeft(2, '0')}';
}
Future<void> checkFlutterEnvironment() async {
final result = await Process.run('flutter', ['--version'], runInShell: true);
if (result.exitCode != 0) {
throw Exception('Flutter环境检查失败');
}
print('✅ Flutter环境正常');
}

4
linux/flutter/generated_plugin_registrant.cc

@ -8,7 +8,6 @@
#include <file_selector_linux/file_selector_plugin.h>
#include <open_file_linux/open_file_linux_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>
void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) file_selector_linux_registrar =
@ -17,7 +16,4 @@ void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) open_file_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "OpenFileLinuxPlugin");
open_file_linux_plugin_register_with_registrar(open_file_linux_registrar);
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
}

1
linux/flutter/generated_plugins.cmake

@ -5,7 +5,6 @@
list(APPEND FLUTTER_PLUGIN_LIST
file_selector_linux
open_file_linux
url_launcher_linux
)
list(APPEND FLUTTER_FFI_PLUGIN_LIST

4
macos/Flutter/GeneratedPluginRegistrant.swift

@ -10,9 +10,7 @@ import file_selector_macos
import open_file_mac
import package_info_plus
import path_provider_foundation
import shared_preferences_foundation
import sqflite_darwin
import url_launcher_macos
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
ConnectivityPlusPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlusPlugin"))
@ -20,7 +18,5 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
OpenFilePlugin.register(with: registry.registrar(forPlugin: "OpenFilePlugin"))
FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
}

182
pubspec.lock

@ -169,14 +169,6 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.0.6"
csslib:
dependency: transitive
description:
name: csslib
sha256: "09bad715f418841f976c77db72d5398dc1253c21fb9c0c7f0b0b985860b2d58e"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.2"
dart_style:
dependency: transitive
description:
@ -397,14 +389,6 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.3.2"
html:
dependency: transitive
description:
name: html
sha256: "6d1264f2dffa1b1101c25a91dff0dc2daee4c18e87cd8538729773c073dbf602"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.15.6"
http:
dependency: transitive
description:
@ -529,26 +513,26 @@ packages:
dependency: transitive
description:
name: leak_tracker
sha256: "6bb818ecbdffe216e81182c2f0714a2e62b593f4a4f13098713ff1685dfb6ab0"
sha256: "33e2e26bdd85a0112ec15400c8cbffea70d0f9c3407491f672a2fad47915e2de"
url: "https://pub.flutter-io.cn"
source: hosted
version: "10.0.9"
version: "11.0.2"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: f8b613e7e6a13ec79cfdc0e97638fddb3ab848452eff057653abd3edba760573
sha256: "1dbc140bb5a23c75ea9c4811222756104fbcd1a27173f0c34ca01e16bea473c1"
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.0.9"
version: "3.0.10"
leak_tracker_testing:
dependency: transitive
description:
name: leak_tracker_testing
sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3"
sha256: "8d5a2d49f4a66b49744b23b018848400d23e54caf9463f4eb20df3eb8acb2eb1"
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.0.1"
version: "3.0.2"
lints:
dependency: transitive
description:
@ -669,14 +653,6 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.0.3"
os_detect:
dependency: transitive
description:
name: os_detect
sha256: "7d87c0dd98c6faf110d5aa498e9a6df02ffce4bb78cc9cfc8ad02929be9bb71f"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.3"
package_config:
dependency: transitive
description:
@ -877,62 +853,6 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.5.0"
shared_preferences:
dependency: transitive
description:
name: shared_preferences
sha256: "6e8bf70b7fef813df4e9a36f658ac46d107db4b4cfe1048b477d4e453a8159f5"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.5.3"
shared_preferences_android:
dependency: transitive
description:
name: shared_preferences_android
sha256: bd14436108211b0d4ee5038689a56d4ae3620fd72fd6036e113bf1345bc74d9e
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.4.13"
shared_preferences_foundation:
dependency: transitive
description:
name: shared_preferences_foundation
sha256: "6a52cfcdaeac77cad8c97b539ff688ccfc458c007b4db12be584fbe5c0e49e03"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.5.4"
shared_preferences_linux:
dependency: transitive
description:
name: shared_preferences_linux
sha256: "580abfd40f415611503cae30adf626e6656dfb2f0cee8f465ece7b6defb40f2f"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.4.1"
shared_preferences_platform_interface:
dependency: transitive
description:
name: shared_preferences_platform_interface
sha256: "57cbf196c486bc2cf1f02b85784932c6094376284b3ad5779d1b1c6c6a816b80"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.4.1"
shared_preferences_web:
dependency: transitive
description:
name: shared_preferences_web
sha256: c49bd060261c9a3f0ff445892695d6212ff603ef3115edbb448509d407600019
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.4.3"
shared_preferences_windows:
dependency: transitive
description:
name: shared_preferences_windows
sha256: "94ef0f72b2d71bc3e700e025db3710911bd51a71cefb65cc609dd0d9a982e3c1"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.4.1"
shelf:
dependency: transitive
description:
@ -1094,10 +1014,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: fb31f383e2ee25fbbfe06b40fe21e1e458d14080e3c67e7ba0acfde4df4e0bbd
sha256: "522f00f556e73044315fa4585ec3270f1808a4b186c936e612cab0b565ff1e00"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.7.4"
version: "0.7.6"
typed_data:
dependency: transitive
description:
@ -1106,78 +1026,6 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.4.0"
upgrader:
dependency: "direct main"
description:
name: upgrader
sha256: a28de64108db70f77e5eacf8b87c1bdfaf9374ece9cab26f9aeac26ac3403eff
url: "https://pub.flutter-io.cn"
source: hosted
version: "12.1.0"
url_launcher:
dependency: transitive
description:
name: url_launcher
sha256: f6a7e5c4835bb4e3026a04793a4199ca2d14c739ec378fdfe23fc8075d0439f8
url: "https://pub.flutter-io.cn"
source: hosted
version: "6.3.2"
url_launcher_android:
dependency: transitive
description:
name: url_launcher_android
sha256: "81777b08c498a292d93ff2feead633174c386291e35612f8da438d6e92c4447e"
url: "https://pub.flutter-io.cn"
source: hosted
version: "6.3.20"
url_launcher_ios:
dependency: transitive
description:
name: url_launcher_ios
sha256: d80b3f567a617cb923546034cc94bfe44eb15f989fe670b37f26abdb9d939cb7
url: "https://pub.flutter-io.cn"
source: hosted
version: "6.3.4"
url_launcher_linux:
dependency: transitive
description:
name: url_launcher_linux
sha256: "4e9ba368772369e3e08f231d2301b4ef72b9ff87c31192ef471b380ef29a4935"
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.2.1"
url_launcher_macos:
dependency: transitive
description:
name: url_launcher_macos
sha256: c043a77d6600ac9c38300567f33ef12b0ef4f4783a2c1f00231d2b1941fea13f
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.2.3"
url_launcher_platform_interface:
dependency: transitive
description:
name: url_launcher_platform_interface
sha256: "552f8a1e663569be95a8190206a38187b531910283c3e982193e4f2733f01029"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.3.2"
url_launcher_web:
dependency: transitive
description:
name: url_launcher_web
sha256: "4bd2b7b4dc4d4d0b94e5babfffbca8eac1a126c7f3d6ecbc1a11013faa3abba2"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.4.1"
url_launcher_windows:
dependency: transitive
description:
name: url_launcher_windows
sha256: "3284b6d2ac454cf34f114e1d3319866fdd1e19cdc329999057e44ffe936cfa77"
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.1.4"
uuid:
dependency: "direct main"
description:
@ -1190,18 +1038,10 @@ packages:
dependency: transitive
description:
name: vector_math
sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803"
sha256: d530bd74fea330e6e364cda7a85019c434070188383e1cd8d9777ee586914c5b
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.4"
version:
dependency: transitive
description:
name: version
sha256: "3d4140128e6ea10d83da32fef2fa4003fccbf6852217bb854845802f04191f94"
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.0.2"
version: "2.2.0"
vm_service:
dependency: transitive
description:
@ -1267,7 +1107,7 @@ packages:
source: hosted
version: "6.6.1"
yaml:
dependency: transitive
dependency: "direct main"
description:
name: yaml
sha256: b9da305ac7c39faa3f030eccd175340f968459dae4af175130b3fc47e40d76ce

2
pubspec.yaml

@ -30,8 +30,8 @@ dependencies:
pretty_dio_logger: ^1.4.0
sqflite: ^2.4.2
tdesign_flutter: ^0.2.4
upgrader: ^12.1.0
uuid: ^4.5.1
yaml: ^3.1.3
dev_dependencies:
flutter_test:

3
windows/flutter/generated_plugin_registrant.cc

@ -9,7 +9,6 @@
#include <connectivity_plus/connectivity_plus_windows_plugin.h>
#include <file_selector_windows/file_selector_windows.h>
#include <permission_handler_windows/permission_handler_windows_plugin.h>
#include <url_launcher_windows/url_launcher_windows.h>
void RegisterPlugins(flutter::PluginRegistry* registry) {
ConnectivityPlusWindowsPluginRegisterWithRegistrar(
@ -18,6 +17,4 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
registry->GetRegistrarForPlugin("FileSelectorWindows"));
PermissionHandlerWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin"));
UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
}

1
windows/flutter/generated_plugins.cmake

@ -6,7 +6,6 @@ list(APPEND FLUTTER_PLUGIN_LIST
connectivity_plus
file_selector_windows
permission_handler_windows
url_launcher_windows
)
list(APPEND FLUTTER_FFI_PLUGIN_LIST

Loading…
Cancel
Save