在之前的文章 鸿蒙Next开发之-解决鸿蒙next开发如何给测试同学测试包的问题 中,为了解决给测试同学安装鸿蒙APP的问题,我写了两个脚本,但是这还是不方便,对于我的用户(测试)来说,希望用手点点就行,而不是敲命名(万一敲错了呢)。因此后续计划使用flutter写一个桌面工具,来实现鸿蒙APP的重签名和安装。现在它来了。
效果如下:
主界面:
设置界面:
GitHub地址:github.com/HeQuanLi/oh…
使用须知
本机电脑安装python3且配置好环境变量
。因为该程序调用的是本机python3 命令执行脚本文件。核心代码如下:
///拖入完成
Future<void> _dragDone(DragDoneEvent event, Emitter<HomeState> emit) async {
var appFile = event.details.files.firstOrNull?.path;
if (appFile == null) {
debugPrint("文件路径获取失败");
emit(ErrorState("文件路径获取失败"));
return;
}
var result =
await SharedPreferencesUtil.getString(ConstantUtils.signPathInfo);
if (result == null) {
emit(ErrorState("配置信息错误"));
debugPrint("配置信息错误");
return;
}
SingPathInfo singPathInfo = SingPathInfo.fromJson(json.decode(result));
if (event.type == DropType.signed) {
debugPrint("签名");
emit(ExecuteState(Execute.running, event.type));
await _signedApp(appFile, singPathInfo);
emit(ExecuteState(Execute.complete, event.type));
} else {
debugPrint("安装");
emit(ExecuteState(Execute.running, event.type));
await _installApp(appFile, singPathInfo);
emit(ExecuteState(Execute.complete, event.type));
}
}
Future<void> _signedApp(String appFile, SingPathInfo singPathInfo) async {
var arguments = [ appFile, singPathInfo.signToolPath, singPathInfo.cerPath, singPathInfo.p7bPath, singPathInfo.p12Path, singPathInfo.alias, singPathInfo.pwd, singPathInfo.packageName ];
await _executeCommand(AssetsPy.ohos_app_signed, arguments);
}
Future<void> _installApp(String appFile, SingPathInfo singPathInfo) async {
var arguments = [appFile, singPathInfo.packageName];
await _executeCommand(AssetsPy.ohos_app_install, arguments);
}
Future<void> _executeCommand(String command, List<String> arguments) async {
var shell = Shell(verbose: false);
debugPrint("开始执行");
await shell.run('python3 $command ${arguments.join(" ")}');
debugPrint("执行完成");
}