### sdk install examples Source: https://developer.android.com/tools/agents/android-cli Examples for installing SDK packages, including specifying versions and channels. ```bash android sdk install platforms/android-34 build-tools/34.0.0 ``` ```bash android sdk install platforms/android-34@2 ``` ```bash android sdk install --canary system-images/android-35/google_apis/x86_6 ``` ```bash android sdk install --force platforms/android-33@1 ``` -------------------------------- ### Android CLI emulator start example Source: https://developer.android.com/tools/agents/android-cli Example of how to launch a specified virtual device using the 'emulator start' command. ```bash android emulator start medium_phone ``` -------------------------------- ### Install multiple packages Source: https://developer.android.com/tools/sdkmanager This example shows how to install multiple packages, such as the latest platform tools and the SDK tools for API level 36, by passing their SDK-style paths separated by spaces. ```bash sdkmanager "platform-tools" "platforms;android-36" ``` -------------------------------- ### Example Source: https://developer.android.com/tools/mksdcard Create the `mySdCardFile.img` disk image and start two emulators with different AVDs using the created disk image. ```bash mksdcard -l mySdCard 1024M mySdCardFile.img ``` ```bash emulator -avd Pixel_API_25 -sdcard mySdCardFile.img ``` ```bash emulator -avd NEXUS_6_API_25 -sdcard mySdCardFile.img ``` -------------------------------- ### Install packages from a file Source: https://developer.android.com/tools/sdkmanager This command installs packages listed in a text file, where each line is an SDK-style path of a package to install. ```bash sdkmanager --package_file=package_file [options] ``` -------------------------------- ### Install NDK from a specific channel Source: https://developer.android.com/tools/sdkmanager This example installs a specific NDK version, ensuring it's from the canary channel or below. ```bash sdkmanager --install "ndk;21.3.6528147" --channel=3 // Install the NDK from the canary channel (or below) ``` -------------------------------- ### Install a specific version of CMake Source: https://developer.android.com/tools/sdkmanager This example installs a specific version of CMake. ```bash sdkmanager --install "cmake;10.24988404" // Install a specific version of CMake ``` -------------------------------- ### Convert command example Source: https://developer.android.com/tools/aapt2?hl=pl Example of converting an APK to protobuf format. ```bash aapt2 convert -o output.apk --output-format proto --enable-sparse-encoding input.apk ``` -------------------------------- ### Example link command Source: https://developer.android.com/tools/aapt2 An example of merging intermediate files and linking against `android.jar`. ```bash aapt2 link -o output.apk -I android_sdk/platforms/android_version/android.jar compiled/res/values_values.arsc.flat compiled/res/drawable_Image.flat --manifest /path/to/AndroidManifest.xml -v ``` -------------------------------- ### Version output example Source: https://developer.android.com/tools/aapt2?hl=zh-CN Example output of the version command. ```text Android Asset Packaging Tool (aapt) 2.19-8678579 ``` -------------------------------- ### skills add example Source: https://developer.android.com/tools/agents/android-cli Example for adding Android skills for a specific agent. ```bash android skills add --agent='gemini' edge-to-edge ``` -------------------------------- ### skills find example Source: https://developer.android.com/tools/agents/android-cli Example for finding skills that match a given string. ```bash android skills find 'performance' ``` -------------------------------- ### Dump resources example Source: https://developer.android.com/tools/aapt2 The following example prints content from the resource table of the specified APK: ```bash aapt2 dump resources output.apk ``` -------------------------------- ### Send commands to a specific device Source: https://developer.android.com/tools/adb Example of using 'adb devices' to get serial numbers and then using the '-s' option to install an APK on a specific device. ```bash $ adb devices List of devices attached emulator-5554 device emulator-5555 device 0.0.0.0:6520 device # To install on emulator-5555 $ adb -s emulator-5555 install helloWorld.apk # To install on 0.0.0.0:6520 $ adb -s 0.0.0.0:6520 install helloWorld.apk ``` -------------------------------- ### Get help text for a specific service Source: https://developer.android.com/tools/dumpsys Example of how to get help text and additional options for a specific service, using 'procstats' as an example. ```bash adb shell dumpsys procstats -h ``` -------------------------------- ### Example: Optimizing resources and creating a new APK Source: https://developer.android.com/tools/aapt2?hl=pl Example of optimizing resources in an input APK and creating a new, optimized APK. This replaces the normal flat table representation with a more compact one, leading to reduced APK size, memory usage, and launch latency, with a slight increase in per-resource lookup time after launch. ```bash aapt2 optimize -o output.apk --enable-sparse-encoding input.apk ``` -------------------------------- ### Example output of `adb devices` Source: https://developer.android.com/tools/adb?hl=de This example shows the output of the `devices` command with three devices running: two emulators and one hardware device. ```bash $ adb devices List of devices attached emulator-5556 device product:sdk_google_phone_x86_64 model:Android_SDK_built_for_x86_64 device:generic_x86_64 emulator-5554 device product:sdk_google_phone_x86 model:Android_SDK_built_for_x86 device:generic_x86 0a388e93 device usb:1-1 product:razor model:Nexus_7 device:flo ``` -------------------------------- ### Example: Get APK file size Source: https://developer.android.com/tools/apkanalyzer An example of how to use the apkanalyzer command to get the file size of an APK in a human-readable format. ```bash apkanalyzer -h apk file-size myapk.apk ``` -------------------------------- ### Troubleshooting: Emulator listed (Scenario 2) Source: https://developer.android.com/tools/adb?hl=de This command sequence shows how to ensure the device list from `adb devices` is displayed by starting the adb server first. ```bash $ adb kill-server $ emulator -avd Nexus_6_API_25 -port 5557 $ adb start-server $ adb devices List of devices attached emulator-5557 device ``` -------------------------------- ### Optimize example Source: https://developer.android.com/tools/aapt2 The following example optimizes the resources in `input.apk` and creates a new, optimized APK in `output.apk`. It replaces the usual flat table representation with a more compact representation, leading to a reduction in APK size, memory usage, and startup latency, and a small increase in individual resource lookup time after startup. ```bash aapt2 optimize -o output.apk --enable-sparse-encoding input.apk ``` -------------------------------- ### Install Location Source: https://developer.android.com/tools/adb Commands to change and get the default install location for applications. ```shell adb shell pm set-install-location location adb shell get-install-location ``` -------------------------------- ### Example recording session Source: https://developer.android.com/tools/adb A complete example of starting, stopping, and pulling a screen recording. ```shell $ adb shell shell@ $ screenrecord --verbose /sdcard/demo.mp4 (press Control + C to stop) shell@ $ exit $ adb pull /sdcard/demo.mp4 ``` -------------------------------- ### QEMU Separate Audio Input/Output Example (Linux) Source: https://developer.android.com/tools/variables?hl=ja Example of setting separate audio input and output drivers for the emulator on Linux using QEMU_AUDIO_OUT_DRV and QEMU_AUDIO_IN_DRV. ```bash set QEMU_AUDIO_OUT=esd set QEMU_AUDIO_IN=oss ``` -------------------------------- ### ADB Install with ANDROID_SERIAL Source: https://developer.android.com/tools/variables?hl=ja Example of setting the ANDROID_SERIAL environment variable to specify the target emulator for the adb install command. ```bash set ANDROID_SERIAL=emulator-555 adb install helloWorld.apk ``` -------------------------------- ### List available templates Source: https://developer.android.com/tools/agents/android-cli?hl=zh-TW Usage: `android create list` Description: Lists all available templates to create a new project from. ```bash android create list ``` -------------------------------- ### sdk update examples Source: https://developer.android.com/tools/agents/android-cli Examples for updating SDK packages, including updating all packages or specific ones, and using different channels. ```bash android sdk update ``` ```bash android sdk update build-tools/34.0.0 ``` ```bash android sdk update --canary platforms/android-35 ``` -------------------------------- ### Emulator not listed - Example 2 Source: https://developer.android.com/tools/adb Demonstrates the correct command sequence to ensure emulators are listed by 'adb devices' by starting the adb server first. ```bash $ adb kill-server $ emulator -avd Nexus_6_API_25 -port 5557 $ adb start-server $ adb devices List of devices attached emulator-5557 device ``` -------------------------------- ### Android CLI create command example Source: https://developer.android.com/tools/agents/android-cli Example of how to create a new project using the 'create' command with dry-run and verbose options, specifying a template. ```bash android create --dry-run --verbose empty-activity-agp-9 ``` -------------------------------- ### Issue activity manager commands directly from adb Source: https://developer.android.com/tools/adb You can execute activity manager commands directly using adb without entering a remote shell. For example, to start an activity: ```bash adb shell am start -a android.intent.action.VIEW ``` -------------------------------- ### Start the sqlite3 tool Source: https://developer.android.com/tools/sqlite3 From the remote shell, start the sqlite3 tool. ```bash sqlite3 ```