Skip to main content

Android

1. Introduction to ADB

ADB (Android Debug Bridge) is a command-line tool that allows users to interact with Android devices or emulators. It serves as a crucial debugging tool in Android development, enabling developers to perform operations such as device management, app installation, log viewing, and file transfer. ADB operates on a client-server architecture for communication between a development machine and an Android device.

2. Hardware Connection

Connect the development board to the computer using a Type-C data cable (Note: This USB port is not a power port).

3. ADB Installation (Windows)

  1. Download the ADB installation package, extract it, and use it directly (click here to download).
  2. Right-click This PC and select Properties -> Advanced system settings -> Environment Variables.

  1. In System variables, edit Path and add the extracted ADB directory.

  1. Click OK to save the environment variables.

4. ADB Installation (Ubuntu)

  1. Install the ADB tool.
sudo apt-get install android-tools-adb -y
  1. If the correct udev rules are not configured, regular users cannot access USB devices. When running adb shell, errors such as “udev rules wrong” or insufficient permissions may appear.

  1. Use lsusb to check the device ID.

  1. Create or edit the udev rules file:
sudo vim /etc/udev/rules.d/51-android.rules
  1. Add the following content to grant read/write permissions to users in the plugdev group for devices with ID 2207:0019:
SUBSYSTEM=="usb", ATTR{idVendor}=="2207", ATTR{idProduct}=="0019", MODE="0666", GROUP="plugdev"
  1. After saving the file, change its permission:
sudo chmod 644 /etc/udev/rules.d/51-android.rules
  1. Reload the udev rules:
sudo udevadm control --reload-rules
sudo service udev restart
  1. Reconnect the device by unplugging and plugging it back in to ensure the new rules take effect.

5. ADB Debugging

  1. Press Win + R, enter CMD, and open the Windows terminal. Run an ADB command to confirm that ADB is available.

  1. If only one device is connected, run the following command in PowerShell or CMD:
adb shell
  1. If multiple devices are connected, view the list of currently connected ADB devices:
adb devices

Example:

C:\Users\cjw> adb devices

List of devices attached

103ea97dececc831 device
d48936ed7d1551fc device
  1. After confirming the target device, log in to the board by specifying the device serial number:
adb -s d48936ed7d1551fc shell
Tip

After plugging or unplugging the board, run adb devices again to confirm whether the target device has been recognized. If it is not recognized, try replacing the Type-C data cable and check whether the connector has poor contact.

6. ADB App Installation and Uninstallation

6.1 Installation

  1. Basic syntax:

    adb install [options] <apk_file_path>
    • adb: ADB command prefix.
    • install: Install an APK file.
    • <apk_file_path>: Path to the APK file (use full path or filename if in the current directory).
  2. Common options:

    • -r: Reinstall an existing app while preserving user data.
    • -d: Allow downgrading to an older app version.
    • -s: Install the app to the SD card instead of internal storage.
    • -g: Grant all runtime permissions during installation.
    • -t: Allow installation of test-signed apps.
  3. Example:

    PS D:\Download\NFCTag_CN> adb install test.apk
    3200 KB/s (17677887 bytes in 5.393s)
    Success

6.2 Uninstallation

  1. Basic syntax:

    adb uninstall <package_name>
    • adb: ADB command tool.
    • uninstall: Remove an app.
    • <package_name>: App package name (e.g., luckfox).
  2. Example:

    adb uninstall luckfox
    • Failure [DELETE_FAILED_INTERNAL_ERROR]: Verify the package name using adb shell pm list packages.
    • Failure [DELETE_FAILED_DEVICE_POLICY_MANAGER]: Disable device admin privileges in SettingsSecurityDevice administrators before uninstalling.