mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-12-10 09:07:29 +00:00
feat: add android build support
This commit is contained in:
parent
38dc934f40
commit
3e1f8eac6a
@ -0,0 +1,90 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:args/command_runner.dart';
|
||||||
|
import 'package:collection/collection.dart';
|
||||||
|
import 'package:path/path.dart';
|
||||||
|
import 'package:xml/xml.dart';
|
||||||
|
|
||||||
|
import '../../core/env.dart';
|
||||||
|
import 'common.dart';
|
||||||
|
|
||||||
|
class AndroidBuildCommand extends Command with BuildCommandCommonSteps {
|
||||||
|
@override
|
||||||
|
String get description => "Build for android";
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get name => "android";
|
||||||
|
|
||||||
|
@override
|
||||||
|
FutureOr? run() async {
|
||||||
|
await bootstrap();
|
||||||
|
|
||||||
|
await shell.run(
|
||||||
|
"flutter build apk --flavor ${CliEnv.channel}",
|
||||||
|
);
|
||||||
|
|
||||||
|
await dotEnvFile.writeAsString(
|
||||||
|
"\nENABLE_UPDATE_CHECK=0",
|
||||||
|
mode: FileMode.append,
|
||||||
|
);
|
||||||
|
|
||||||
|
final androidManifestFile = File(
|
||||||
|
join(cwd.path, "android", "app", "src", "main", "AndroidManifest.xml"));
|
||||||
|
|
||||||
|
final androidManifestXml =
|
||||||
|
XmlDocument.parse(await androidManifestFile.readAsString());
|
||||||
|
|
||||||
|
final deletingElement =
|
||||||
|
androidManifestXml.findAllElements("meta-data").firstWhereOrNull(
|
||||||
|
(el) =>
|
||||||
|
el.getAttribute("android:name") ==
|
||||||
|
"com.google.android.gms.car.application",
|
||||||
|
);
|
||||||
|
|
||||||
|
deletingElement?.parent?.children.remove(deletingElement);
|
||||||
|
|
||||||
|
await androidManifestFile.writeAsString(
|
||||||
|
androidManifestXml.toXmlString(pretty: true),
|
||||||
|
);
|
||||||
|
|
||||||
|
await shell.run(
|
||||||
|
"""
|
||||||
|
dart run build_runner build --delete-conflicting-outputs
|
||||||
|
flutter build appbundle --flavor ${CliEnv.channel}
|
||||||
|
""",
|
||||||
|
);
|
||||||
|
|
||||||
|
final ogApkFile = File(
|
||||||
|
join(
|
||||||
|
"build",
|
||||||
|
"app",
|
||||||
|
"outputs",
|
||||||
|
"flutter-apk",
|
||||||
|
"app-${CliEnv.channel}-release.apk",
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
await ogApkFile.copy(
|
||||||
|
join(cwd.path, "build", "Spotube-android-all-arch.apk"),
|
||||||
|
);
|
||||||
|
|
||||||
|
final ogAppbundleFile = File(
|
||||||
|
join(
|
||||||
|
cwd.path,
|
||||||
|
"build",
|
||||||
|
"app",
|
||||||
|
"outputs",
|
||||||
|
"bundle",
|
||||||
|
"${CliEnv.channel}Release",
|
||||||
|
"app-${CliEnv.channel}-release.aab",
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
await ogAppbundleFile.copy(
|
||||||
|
join(cwd.path, "dist", "Spotube-playstore-all-arch.aab"),
|
||||||
|
);
|
||||||
|
|
||||||
|
stdout.writeln("✅ Built Android Apk and Appbundle");
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -5,6 +5,8 @@ import 'package:path/path.dart';
|
|||||||
import 'package:process_run/shell_run.dart';
|
import 'package:process_run/shell_run.dart';
|
||||||
import 'package:pubspec_parse/pubspec_parse.dart';
|
import 'package:pubspec_parse/pubspec_parse.dart';
|
||||||
|
|
||||||
|
import '../../core/env.dart';
|
||||||
|
|
||||||
mixin BuildCommandCommonSteps on Command {
|
mixin BuildCommandCommonSteps on Command {
|
||||||
final shell = Shell();
|
final shell = Shell();
|
||||||
Directory get cwd => Directory.current;
|
Directory get cwd => Directory.current;
|
||||||
@ -29,7 +31,13 @@ mixin BuildCommandCommonSteps on Command {
|
|||||||
RegExp get versionVarRegExp =>
|
RegExp get versionVarRegExp =>
|
||||||
RegExp(r"\%\{\{SPOTUBE_VERSION\}\}\%", multiLine: true);
|
RegExp(r"\%\{\{SPOTUBE_VERSION\}\}\%", multiLine: true);
|
||||||
|
|
||||||
|
File get dotEnvFile => File(join(cwd.path, ".env"));
|
||||||
|
|
||||||
Future<void> bootstrap() async {
|
Future<void> bootstrap() async {
|
||||||
|
await dotEnvFile.create(recursive: true);
|
||||||
|
|
||||||
|
await dotEnvFile.writeAsString(CliEnv.dotenv);
|
||||||
|
|
||||||
await shell.run(
|
await shell.run(
|
||||||
"""
|
"""
|
||||||
flutter pub get
|
flutter pub get
|
||||||
|
|||||||
@ -2470,7 +2470,7 @@ packages:
|
|||||||
source: hosted
|
source: hosted
|
||||||
version: "1.0.4"
|
version: "1.0.4"
|
||||||
xml:
|
xml:
|
||||||
dependency: transitive
|
dependency: "direct dev"
|
||||||
description:
|
description:
|
||||||
name: xml
|
name: xml
|
||||||
sha256: b015a8ad1c488f66851d762d3090a21c600e479dc75e68328c52774040cf9226
|
sha256: b015a8ad1c488f66851d762d3090a21c600e479dc75e68328c52774040cf9226
|
||||||
|
|||||||
@ -145,6 +145,7 @@ dev_dependencies:
|
|||||||
custom_lint: ^0.6.4
|
custom_lint: ^0.6.4
|
||||||
riverpod_lint: ^2.3.10
|
riverpod_lint: ^2.3.10
|
||||||
process_run: ^0.14.2
|
process_run: ^0.14.2
|
||||||
|
xml: ^6.5.0
|
||||||
|
|
||||||
dependency_overrides:
|
dependency_overrides:
|
||||||
uuid: ^4.4.0
|
uuid: ^4.4.0
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user