Android command line tool linux

How to install Android SDK Build Tools on the command line?

The result is that nothing in folder build-tools, and I want is aapt and apkbuilder, since I want to build apk from command line without ant.

20 Answers 20

By default, the SDK Manager from the command line does not include the build tools in the list. They’re in the «obsolete» category. To see all available downloads, use

And then to get one of the packages in that list from the command line, use:

Where -u stands for —no-ui, -a stands for —all and -t stands for —filter.

If you need to install multiple packages do:

android update sdk -u -a -t 1,2,3,4. n

Where 1,2. n is the package number listed with the list command above

If you are missing build-tools like 18.1.1 then this is the right way to install it using the command line.

@DanielJonker Yes, it is. Just echo «yes» to the command, i.e. echo yes | android update sdk —all —filter tools —no-ui —force > /dev/null

echo «yes» can be shortened to echo «y» , but that doesn’t work in all cases anyway. In some cases you can get more than one y/n license prompt, depending on the filter and specific packages. echo «y» will respond to the first prompt only, but not the rest. I’m trying to make it work with yes command with no success so far.

@AlexanderMalakhov I agree, if your host OS has the utility, using it is the best option. I looked at expect first, but in my case I have to run the script on a certain Linux distributive running in AWS cloud. That distro does not have expect installed and I don’t have enough rights to install it as part of build plan. After looking around, the best solution that I found is

 # update Android SDK on headless server FILTER=tool,platform,android-20 ( sleep 5 && while [ 1 ]; do sleep 1; echo y; done ) \ | android update sdk --no-ui --all \ --filter $

As mentioned in other answers, you can use the —filter option to limit the installed packages:

android update sdk —filter .

The other answers don’t mention that you can use constant string identifiers instead of indexes (which will change) for the filter options. This is helpful for unattended or scripted installs. Man for —filter option:

. This also accepts the identifiers returned by ‘list sdk —extended’.

android list sdk —all —extended :

Packages available for installation or update: 97 ---------- id: 1 or "tools" Type: Tool Desc: Android SDK Tools, revision 22.6.2 ---------- id: 2 or "platform-tools" Type: PlatformTool Desc: Android SDK Platform-tools, revision 19.0.1 ---------- id: 3 or "build-tools-19.0.3" Type: BuildTool Desc: Android SDK Build-tools, revision 19.0.3 

Then you can use the string ids as the filter options to precisely specify the versions you want:

Читайте также:  Linux обновить днс кэш

android update sdk —filter tools,platform-tools,build-tools-19.0.3 etc

android update will also require the —all option, otherwise usage help is displayed. For example: android update sdk —no-ui —all —filter build-tools-21.1.0 (and +1 for the —extended option which allows you to see the aliases like build-tools-21.1.0 )

I was looking for that —extended option so I could write a script and use it in my Continuous Integration Server where it can refresh the sdk resources itself. Nice tip !

Version 25.2.3 (and higher) of Android SDK Tools package contains new tool — sdkmanager — which simplifies this task of installing build-tools from the command line.
It is located in android_sdk/tools/bin folder.

Usage (from documentation):

List installed and available packages:

sdkmanager --list [options] \ [--channel=channel_id] // Channels: 0 (stable), 1 (beta), 2 (dev), or 3 (canary) 

Use the channel option to include a package from a channel up to and including channel_id. For example, specify the canary channel to list packages from all channels.

Install packages:

sdkmanager packages [options] 

The packages argument is an SDK-style path, wrapped in quotes (for example, «build-tools;25.0.0» or «platforms;android-25» ). You can pass multiple package paths, separated with a space, but they must each be wrapped in their own set of quotes.

Example usage (on my Mac):

alex@mbpro:~/sdk/tools/bin$ ls ../../build-tools/ 25.0.0/ alex@mbpro:~/sdk/tools/bin$ ./sdkmanager "build-tools;25.0.2" done alex@mbpro:~/sdk/tools/bin$ ls ../../build-tools/ 25.0.0/ 25.0.2/ 

You can also specify various options, for example to force all connections to use HTTP ( —no_https ), or in order to use proxy server ( —proxy_host=address and —proxy_port=port ).

To check the available options, use the —help flag. On my machine (Mac), the output is as following:

alex@mbpro:~/sdk/tools/bin$ ./sdkmanager --help Usage: sdkmanager [--uninstall] [] \ [--package_file ] [. ] sdkmanager --update [] sdkmanager --list [] In its first form, installs, or uninstalls, or updates packages. is a sdk-style path (e.g. "build-tools;23.0.0" or "platforms;android-23"). is a text file where each line is a sdk-style path of a package to install or uninstall. Multiple --package_file arguments may be specified in combination with explicit paths. In its second form (with --update), currently installed packages are updated to the latest version. In its third form, all installed and available packages are printed out. Common Arguments: --sdk_root=: Use the specified SDK root instead of the SDK containing this tool --channel=: Include packages in channels up to . Common channels are: 0 (Stable), 1 (Beta), 2 (Dev), and 3 (Canary). --include_obsolete: With --list, show obsolete packages in the package listing. With --update, update obsolete packages as well as non-obsolete. --no_https: Force all connections to use http rather than https. --proxy=: Connect via a proxy of the given type. --proxy_host=: IP or DNS address of the proxy to use. --proxy_port=: Proxy port to connect to. * If the env var REPO_OS_OVERRIDE is set to "windows", "macosx", or "linux", packages will be downloaded for that OS. 

Источник

Rofram / readme.md

The latest version of cmdline tools (7302050_latest) seems to have a different directory structure. The folder is now called cmdline-tools instead of tools so when you extract the folder it won’t work as expected. sdkmanager also seems to expect to want to be in $/cmdline-tools/latest/bin but extracting it in ANDROID_HOME will just give you $/cmdline-tools/bin.

Читайте также:  Linux узнать температуру видеокарты

So it looks like unzipping the newest version to $/cmdline-tools/cmdline-tools will fix this, and remove the need to run sdkmanager —sdk_root. Easiest way might just be to mkdir -p Android/cmdline-tools and unzip to there & rename the second cmdline-tools to latest

Not sure how this whole forking gists thing is supposed to work but here are the changes I used: https://gist.github.com/jason-s-yu/30375db45c1f71c1259e042d216e4bd3

wget https://dl.google.com/android/repository/commandlinetools-linux-7302050_latest.zip mkdir -p Android/cmdline-tools unzip commandlinetools-linux-6200805_latest.zip -d Android/cmdline-tools mv Android/cmdline-tools/cmdline-tools Android/cmdline-tools/latest export ANDROID_HOME=$HOME/Android

Make sure emulator path comes before tools. Had trouble on Ubuntu with emulator from /tools being loaded

instead of the one from /emulator

export PATH="$ANDROID_HOME/emulator:$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_HOME/cmdline-tools/latest:$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/platform-tools:$PATH"
sdkmanager --sdk_root=$ "tools"
sdkmanager --update sdkmanager --list
sdkmanager --list | grep build-tools sdkmanager "build-tools;30.0.3" "platform-tools" "platforms;android-30" "tools" sdkmanager --licenses

Источник

Command-line tools

The Android SDK is composed of multiple packages that are required for app development. This page lists the most important command-line tools that are available, organized by the packages in which they’re delivered.

You can install and update each package using Android Studio’s SDK Manager or the sdkmanager command-line tool. All of the packages are downloaded into your Android SDK directory, which you can locate as follows:

  1. In Android Studio, click File > Project Structure.
  2. Select SDK Location in the left pane. The path is shown under Android SDK location.

Set environment variables

We recommend setting the environment variable for ANDROID_HOME when using the command line. Also, set your command search path to include ANDROID_HOME/tools , ANDROID_HOME/tools/bin , and ANDROID_HOME/platform-tools to find the most common tools. The steps vary depending on your OS, but read How to set environment variables for general guidance.

Android SDK Command-Line Tools

Located in: android_sdk /cmdline-tools/ version /bin/

Note: The Android SDK Command-Line Tools package, located in cmdline-tools , replaces the SDK Tools package, located in tools . With the new package, you can select the version of the command line tools you want to install, and you can install multiple versions at a time. With the old package, you can only install the latest version of the tools. Thus, the new package lets you depend on specific versions of the command-line tools without having your code break when new versions are released. For information about the deprecated SDK Tools package, see the SDK Tools release notes.

If you are not using Android Studio, you can download the command-line tools package here.

apkanalyzer Provides insight into the composition of your APK after the build process completes. avdmanager Lets you create and manage Android Virtual Devices (AVDs) from the command line. lint Scans code to help you identify and correct problems with the structural quality of your code. retrace For applications compiled by R8, retrace decodes an obfuscated stack trace that maps back to your original source code. sdkmanager Lets you view, install, update, and uninstall packages for the Android SDK

Android SDK Build Tools

Located in: android_sdk /build-tools/ version /
See SDK Build Tools release notes for more information.

This package is required to build Android apps. Most of the tools in this package are invoked by the build tools and not intended for you. However, the following command-line tools might be useful:

AAPT2 Parses, indexes, and compiles Android resources into a binary format that is optimized for the Android platform and packages the compiled resources into a single output. apksigner Signs APKs and checks whether APK signatures will be verified successfully on all platform versions that a given APK supports. zipalign Optimizes APK files by ensuring that all uncompressed data starts with a particular alignment relative to the start of the file.

Note: You can have multiple versions of the build tools to build your app for different Android versions.

Android SDK Platform Tools

Located in: android_sdk /platform-tools/
See SDK Platform Tools release notes for more information.

These tools are updated for every new version of the Android platform to support new features and fix or improve the tools, and each update is backward compatible with earlier platform versions.

In addition to downloading from the SDK Manager, you can download the SDK Platform Tools here.

adb Android Debug Bridge (adb) is a versatile tool that lets you manage the state of an emulator instance or Android-powered device. You can also use it to install an APK on a device. etc1tool A command-line utility that lets you encode PNG images to the ETC1 compression standard and decode ETC1 compressed images back to PNG. fastboot Flashes a device with platform and other system images. For flashing instructions, see Factory Images for Nexus and Pixel Devices. logcat Invoked by adb to view app and system logs.

Android Emulator

Located in: android_sdk /emulator/
See Android Emulator release notes for more information.

This package is required to use the Android Emulator. It includes the following:

emulator A QEMU-based device-emulation tool that you can use to debug and test your applications in an actual Android run-time environment. mksdcard Helps you create a disk image that you can use with the emulator to simulate the presence of an external storage card, such as an SD card.

Note: Prior to revision 25.3.0, the emulator tools were included with the SDK Tools package.

Jetifier

Jetifier reads a library that uses Support Library classes and outputs an equivalent library that uses the newer AndroidX classes.

Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Last updated 2023-04-12 UTC.

Источник

Оцените статью
Adblock
detector