Resolving Android SDK Manager Command Line Tool Issues

Resolving Android SDK Manager Command Line Tool Issues

5 April 2024 Stephan Petzl Leave a comment Tech-Help

When working with Android development, specifically with continuous integration (CI) systems such as GitLab CI, you may encounter an issue where the Android SDK Manager command line tools throw a warning that it could not create settings. This can be a frustrating roadblock, but the solution involves understanding changes to the directory structure of the SDK tools and adjusting accordingly.

Understanding the Issue

The warning message often looks like this:

Warning: Could not create settings
java.lang.IllegalArgumentException
    at com.android.sdklib.tool.sdkmanager.SdkManagerCliSettings.<init>(SdkManagerCliSettings.java:428)
    ...

This issue arises when attempting to run the sdkmanager command and can occur even when querying the version with sdkmanager --version.

Identifying the Cause

The root of the problem is a change in the directory hierarchy of the Android SDK Command-line Tools starting from version 1.0.0 (6200805). The tools directory, which was previously located directly under ANDROID_HOME (now deprecated and replaced by ANDROID_SDK_ROOT), must now be placed inside a directory named cmdline-tools.

Applying the Solution

To resolve the issue, follow these steps:

  1. Set your preferred ANDROID_SDK_ROOT environment variable.
  2. Download and unpack the commandlinetools zip file into a directory called cmdline-tools, which is inside ANDROID_SDK_ROOT.
  3. Append the directory $ANDROID_SDK_ROOT/cmdline-tools/tools/bin to the PATH environment variable, so that the system knows where to find sdkmanager.

This will result in a directory structure like so:

ANDROID_SDK_ROOT/
├── build-tools/
├── cmdline-tools/
│   └── tools/
│       ├── bin/
│       ├── lib/
│       └── source.properties
├── emulator/
├── licenses/
├── patcher/
├── platform-tools/
├── platforms/
└── system-images/

Additional Considerations

Since the release of Android SDK Command-line Tools 3.0 (build 6858069), the structure has slightly changed again. After unzipping, you’ll find the top-most directory named cmdline-tools. Rename this directory from cmdline-tools to tools and place it under $ANDROID_SDK_ROOT/cmdline-tools, so it appears as $ANDROID_SDK_ROOT/cmdline-tools/tools.

Updating the PATH

For the PATH environment variable, it’s recommended to set it as follows:

PATH=$PATH:$ANDROID_SDK_ROOT/cmdline-tools/latest/bin:$ANDROID_SDK_ROOT/cmdline-tools/tools/bin

After updating, the latest sdkmanager will be located under $ANDROID_SDK_ROOT/cmdline-tools/latest/bin. Placing it in front gives it higher priority.

Final Thoughts

By understanding the changes to the Android SDK’s directory structure and updating your environment accordingly, you can overcome the sdkmanager warning and continue with your Android development workflow. This solution is relevant for setups involving GitLab CI, but can also be adapted for use in other environments where command line access to the Android SDK is necessary.

Like this article? there’s more where that came from!