如何用flutter在Android应用程序中执行ADB?
可以在没有根的情况下运行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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论