如何用flutter在Android应用程序中执行ADB?

发布于 2025-01-30 19:02:02 字数 1305 浏览 2 评论 0原文

可以在没有根的情况下运行Android Flutter应用程序中的ADB。

有一个应用程序可以做到的,并且可以按预期工作:
https://github.com/nightmare-pace/nightmare-pace/adb_tool

就像我们在这里看到的Android:
https://github.com/nightmare.com/night-mare-pace/night-mare-pace/adb_tool/adb_tool/tree/主要/资产/Android

但是,即使有完整的来源,我也找不到它的工作原理。

您可以看到,ADB已安装到一个奇怪的位置: “”

我试图复制它,但根本不起作用。

final deposit = (await getApplicationDocumentsDirectory()).path;
const program = '/data/data/com.example.my_app/files/usr/bin/adb';
ByteData data = await rootBundle.load('assets/android/adb');
List<int> bytes = data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
var file = File(program);
file = await file.create(recursive: true);
file.writeAsBytes(bytes);
await Process.run('chmod', ['+x', program]);
var results = await Process.run(program, ['--version']); // Permission error.

setState(() {
  _counter += 1;
  textarea.text = results.stdout;
});

It possible to run ADB inside android flutter application without root.

There is an application that did it and it works as expected:
https://github.com/nightmare-space/adb_tool

It is using ADB binary compiled for Android like we can see here:
https://github.com/nightmare-space/adb_tool/tree/main/assets/android

However I can't find how it works, even with the full source.

ADB is installed to a strange location as you can see:

I tried to replicate this but it doesn't work at all.

final deposit = (await getApplicationDocumentsDirectory()).path;
const program = '/data/data/com.example.my_app/files/usr/bin/adb';
ByteData data = await rootBundle.load('assets/android/adb');
List<int> bytes = data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
var file = File(program);
file = await file.create(recursive: true);
file.writeAsBytes(bytes);
await Process.run('chmod', ['+x', program]);
var results = await Process.run(program, ['--version']); // Permission error.

setState(() {
  _counter += 1;
  textarea.text = results.stdout;
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文