Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
wsvn53 committed Jun 1, 2022
1 parent 8006a5d commit f3cfb80
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 1 deletion.
76 changes: 75 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,76 @@
# adb-mobile
Porting adb to mobile platform(Android/iOS).

Android Debug Bridge (adb) ported version for mobile apps, the goal of this project is supporting both iOS App and Android App to connect to Android devices in developer mode (TCP/IP Mode) and execute supported ADB commands by integrating the libraries generated by this project.

Currently only iOS platform is supported, Android version is under development.

[中文文档](README.zh-ch.md)

## Build Library

The project has already finished the build scripts to generate libadb in a few simple steps:

```sh
# 1. checkout all the submodules
git submodule update --init --recursive

# 2. build
make
```

The generated libadb product can be found in the output folder of the project directory, for iOS is "libadb.a" that you can located at output folder.

## Integrate

iOS Project:

```ini
# Build Settings - Header Search Paths
HEADER_SEARCH_PATHS = $(SRCROOT)/../../output/include

# Build Settings - Library Search Paths
LIBRARY_SEARCH_PATHS = $(SRCROOT)/../../output

# Build Settings - Other Linker Flags
OTHER_LDFLAGS = -ladb -lc++ -lz
```

## API Usage

iOS App:

```objc
#import "adb_puiblic.h"

// Enable trace debug message
adb_enable_trace();

// Setup the ADB listening port, the default is 5037
adb_set_server_port("15037");

// Setup the ADB private key and data directory, which is usually the Documents directory of the App
NSArray <NSString *> *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
const char *document_home = documentPaths.lastObject.UTF8String;
adb_set_home(document_home);

// Connecting Android devices
const char *argv[] = { "connect", "x.x.x." };
const char *output = null;
int ret = adb_commandline_porting(2, argv, &output);

// Execute the ADB commands
const char *argv[] = { "shell", "ip", "route" };
const char *output = null;
int ret = adb_commandline_porting(2, argv, &output);
```
ADB Status Callback:
```objc
// By define the adb_connect_status_updated callback method to get the adb connection status
void adb_connect_status_updated(const char *serial, const char *status) {
NSLog(@"ADB Status: %s, %s", serial, status);
}
```

You can also see how to use this library in the example/adb-demo project.
76 changes: 76 additions & 0 deletions README.zh-cn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# adb-mobile

Android Debug Bridge (adb) 移植到移动端的版本,目标是支持 iOS App 和 Android App 通过集成本项目生成的库可以连接开发者模式 (TCP/IP Mode) 的 Android 设备,并执行支持的 ADB 命令。

当前仅支持 iOS 平台,Android 版本正在开发中。

[英文文档](README.md)

## 编译库

项目已经适配好了编译参数和脚本,仅需通过简单几步即可生成 libadb:

```sh
# 1. 检出依赖的 submodules
git submodule update --init --recursive

# 2. 编译
make
```

生成的 libadb 产物可以在项目目录下的 output 文件夹里找到,iOS 为 libadb.a。

## 集成到工程

iOS 工程:

```ini
# 设置头文件路径 - Header Search Paths
HEADER_SEARCH_PATHS = $(SRCROOT)/../../output/include

# 设置库搜索路径 - Library Search Paths
LIBRARY_SEARCH_PATHS = $(SRCROOT)/../../output

# 设置连接器参数 - Other Linker Flags
OTHER_LDFLAGS = -ladb -lc++ -lz
```

## 使用说明

iOS App:

```objc
#import "adb_puiblic.h"

// 开启调试信息输出,有助于排查问题
adb_enable_trace();

// 设置 ADB 的监听端口,默认为 5037
adb_set_server_port("15037");

// 设置 ADB 私钥和数据存放目录,一般为 App 的 Documents 目录
NSArray <NSString *> *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
const char *document_home = documentPaths.lastObject.UTF8String;
adb_set_home(document_home);

// 连接 Android 设备
const char *argv[] = { "connect", "x.x.x." };
const char *output = null;
int ret = adb_commandline_porting(2, argv, &output);

// 执行 ADB 命令
const char *argv[] = { "shell", "ip", "route" };
const char *output = null;
int ret = adb_commandline_porting(2, argv, &output);
```
ADB 状态回调:
```objc
// 实现 adb_connect_status_updated 回调方法,可以获取 adb 连接状态
void adb_connect_status_updated(const char *serial, const char *status) {
NSLog(@"ADB Status: %s, %s", serial, status);
}
```

也可以通过 example/adb-demo 工程查看具体使用方法。
Binary file not shown.

0 comments on commit f3cfb80

Please sign in to comment.