nightmare-space / adb_kit

使用 Flutter 开发的 ADB GUI 客户端
BSD 3-Clause "New" or "Revised" License
492 stars 69 forks source link

How do you run adb from Android? #4

Closed sharpordie closed 2 years ago

sharpordie commented 2 years ago

I used the asset files from your project:
https://github.com/nightmare-space/adb_tool/tree/main/assets/android

And I used this code to extract them to the phone's memory and make them executable with chmod +x. Unfortunately I always get a permission error when I try running adb --version command.

List<String> androidFiles = [
    'adb',
    'adb_binary',
    'adb.bin-armeabi',
    'libbrotlidec.so',
    'libbrotlienc.so',
    'libc++_shared.so',
    'liblz4.so.1',
    'libprotobuf.so',
    'libusb-1.0.so',
    'libz.so.1',
    'libzstd.so.1',
    'libbrotlicommon.so',
];

for (var element in androidFiles) {
    ByteData data = await rootBundle.load('assets/android/$element');
    List<int> bytes = data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
    var program = '/data/data/com.example.my_app/files/usr/bin/$element';  // Is it correct?
    var file = File(program);
    file = await file.create(recursive: true);
    file.writeAsBytes(bytes);
    await Process.run('chmod', ['+x', program]);
}

var results = await Process.run('/data/data/com.example.my_app/files/usr/bin/adb', ['--version']);
var version = results.stdout;

My application name is com.example.my_app. Did I put the asset files in the right place?

Thank you in advance.

sharpordie commented 2 years ago

And what is the purpose of the native adblib library here so: https://github.com/nightmare-space/adb_tool/tree/main/android/app/src/main/java/com/nightmare/adbtools/adblib

It seems to be an implementarion of adb but in java... Are you really using the adb binary from assets in adb_tool?

mengyanshou commented 2 years ago

what the result of results.stdout,now i haven't see any problem with your code,have you try downgrade target version to 28?

mengyanshou commented 2 years ago

And what is the purpose of the native adblib library here so: https://github.com/nightmare-space/adb_tool/tree/main/android/app/src/main/java/com/nightmare/adbtools/adblib

It seems to be an implementarion of adb but in java... Are you really using the adb binary from assets in adb_tool?

adblib is the java code which implement adb protcol,but it only work with otg,the other time this project allways use adb binary from assets.

sharpordie commented 2 years ago

have you try downgrade target version to 28?

I replaced targetSdkVersion flutter.targetSdkVersion with targetSdkVersion 28 and everything works!

Thanks you very much!