gitlab ci - Android Command line tools sdkmanager always shows: Warning: Could not create settings

gitlab ci - Android Command line tools sdkmanager always shows: Warning: Could not create settings

Kyle Elkins Author: Kyle Elkins Date: 2022-08-15
gitlab ci - Android Command line tools sdkmanager always shows: Warning: Could not create settings

All you need to know about gitlab ci - Android Command line tools sdkmanager always shows: Warning: Could not create settings , in addintion to Android: How to create a notification from the command line (terminal emulator or shell script)? , Cannot run android emulator using Command line tools on Linux (PANIC: Broken AVD system path.) , android - Could not find method commandLine() , flutter - Android sdkmanager not found. Update to the latest Android SDK and ensure that the cmdline-tools are installed to resolve this

  1. gitlab ci - Android Command line tools sdkmanager always shows: Warning: Could not create settings
  2. Question:

    I use the new command line tools for Android because the old sdk-tools repository of Android isn't available anymore. So I changed my gitlab-ci to load the commandlintools. But when I try to run it I get the following error:

    Warning: Could not create settings
    java.lang.IllegalArgumentException
        at com.android.sdklib.tool.sdkmanager.SdkManagerCliSettings.<init>(SdkManagerCliSettings.java:428)
        at com.android.sdklib.tool.sdkmanager.SdkManagerCliSettings.createSettings(SdkManagerCliSettings.java:152)
        at com.android.sdklib.tool.sdkmanager.SdkManagerCliSettings.createSettings(SdkManagerCliSettings.java:134)
        at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:57)
        at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:48)
    

    I already tried executing those commandy by hand, but I get the same error. Also if I run sdkmanager --version, the same error occurs. My gitlab-ci looks like:

    image: openjdk:9-jdk
    
    variables:
      ANDROID_COMPILE_SDK: "29"
      ANDROID_BUILD_TOOLS: "29.0.3"
      ANDROID_SDK_TOOLS:   "6200805"
    
    before_script:
      - apt-get --quiet update --yes
      - apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1
      - wget --quiet --output-document=android-sdk.zip https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_SDK_TOOLS}_latest.zip
      - unzip -d android-sdk-linux android-sdk.zip
      - echo y | android-sdk-linux/tools/bin/sdkmanager "platform-tools" "platforms;android-${ANDROID_COMPILE_SDK}" >/dev/null
      #- echo y | android-sdk-linux/tools/bin/sdkmanager "platform-tools" >/dev/null
      - echo y | android-sdk-linux/tools/bin/sdkmanager "build-tools;${ANDROID_BUILD_TOOLS}" >/dev/null
      - export ANDROID_HOME=$PWD/android-sdk-linux
      - export PATH=$PATH:$PWD/android-sdk-linux/platform-tools/
      - chmod +x ./gradlew
      # temporarily disable checking for EPIPE error and use yes to accept all licenses
      - set +o pipefail
      - yes | android-sdk-linux/tools/bin/sdkmanager --licenses
      - set -o pipefail
    
    stages:
      - build
      - test
    
    lintDebug:
      stage: build
      script:
        - ./gradlew -Pci --console=plain :app:lintDebug -PbuildDir=lint
    
    assembleDebug:
      stage: build
      script:
        - ./gradlew assembleDebug
      artifacts:
        paths:
        - app/build/outputs/
    
    debugTests:
      stage: test
      script:
        - ./gradlew -Pci --console=plain :app:testDebug
    


    Solution 1:

    Instead of passing the argument --sdk_root for each single command execution, let's deep dive into the real cause.

    Starting from Android SDK Command-line Tools 1.0.0 (6200805), in contrast to Android SDK 26.1.1 (4333796), the tools directory hierarchy has been changed. Previously it was placed right inside ANDROID_HOME (which is deprecated, we will use the term ANDROID_SDK_ROOT for the rest of the paragraph), now it's still named as tools (the only thing you'll get after unpacking the downloaded commandlinetools zip file), but differently, you have to place it inside a directory called cmdline-tools on your own. The name cmdline-tools comes from its package name, where you can get from listing packages command sdkmanager --list, whose outputs include cmdline-tools;1.0 | 1.0 | Android SDK Command-line Tools.

    Wrapping tools directory inside cmdline-tools directory would make it work, and help you get rid of the annoying --sdk_root argument. But what about the other parts?

    Well, that's all you have to change. Let me explain more.

    • The king - sdkmanager lives inside cmdline-tools/tools/bin, you'd better set in PATH environment variable
    • cmdline-tools should not be set as ANDROID_SDK_ROOT. Because later, when updating Android SDK, or installing more packages, the other packages will be placed under ANDROID_SDK_ROOT, but not under cmdline-tools.
    • The final, complete ANDROID_SDK_ROOT directory structure should look like below, consist of quite a few sub-directories: build-tools, cmdline-tools, emulator, licenses, patcher, platform-tools, platforms, system-images. You can easily point out that build-tools and cmdline-tools are siblings, all sit inside the parent ANDROID_SDK_ROOT.

    Let me recap in a simple way:

    • Set your preferred ANDROID_SDK_ROOT (just like before)
    • Download and unpack the commandlinetools zip file into a directory called cmdline-tools, which is inside ANDROID_SDK_ROOT
    • Append the directory $ANDROID_SDK_ROOT/cmdline-tools/tools/bin to environment variable PATH, so that the system knows where to find sdkmanager

    !!UPDATE!!

    The behavior has changed again since the build 6858069 (Android SDK Command-line Tools 3.0):

    • After unzipping the package, the top-most directory you'll get is cmdline-tools.
    • Rename the unpacked directory from cmdline-tools to tools, and place it under $ANDROID_SDK_ROOT/cmdline-tools, so now it should look like: $ANDROID_SDK_ROOT/cmdline-tools/tools. And inside it, you should have: NOTICE.txt bin lib source.properties. Actually according to the official Command-Line Tools doc, the tree structure should be android_sdk/cmdline-tools/version/bin/, but I've checked, using version or tools makes no difference here.
    • For your environment variable PATH, I would recommend you to set like this: PATH=$PATH:$ANDROID_SDK_ROOT/cmdline-tools/latest/bin:$ANDROID_SDK_ROOT/cmdline-tools/tools/bin, because after update later, you'll get the latest sdkmanager placed under $ANDROID_SDK_ROOT/cmdline-tools/latest/bin, put it in front will make it higher priority.

    Solution 2:

    This appears to be a bug with the way sdkmanager locates the SDK installation folder.

    A work-around is to set the flag --sdk_root. You can move ANDROID_HOME declaration higher, then use it with the subsequent commands.

     - export ANDROID_HOME=$PWD/android-sdk-linux
     - yes | android-sdk-linux/tools/bin/sdkmanager --sdk_root=${ANDROID_HOME} --licenses
     - android-sdk-linux/tools/bin/sdkmanager --sdk_root=${ANDROID_HOME} "platform-tools" "platforms;android-${ANDROID_COMPILE_SDK}" >/dev/null
    

    Also, moved blanket license acceptance command to the first command to clean up the echo y parts.

    Oddly enough if you run sdkmanager --sdk_root=${ANDROID_HOME} "tools" it will upgrade tools from 3.6.0 to 26.1.1 and sdkmanager no longer has this issue. This update takes time and bandwidth and isn't exactly necessary with the work-around.

    Solution 3:

    For those who struggled with installing Android Command Line Tools for Appium on Windows 10/x64 just do as following:

    1. Download latest Command line tools from android i.e. commandlinetools-win-6200805_latest.zip
    2. Unzip the downloaded file
    3. Create directory for storing commandline tools somewhere on your disk, with following path included: android/cmdline-tools/latest Basically when You unzip this Cmd line tools, just rename tools directory to latest and make sure You put this latest folder in android/cmdline-tools directory somewhere on your disk
    4. Create ANDROID_HOME environment variable for directory that stores the cmdline tools directory location like: C:\YourLocationWhereYouStoreTheDirectory\android\cmdline-tools\latest
    5. Create new entry in Path environment variable as %ANDROID_HOME%\bin

  3. Android: How to create a notification from the command line (terminal emulator or shell script)?
  4. Question:

    I would like to create a notification (icon in notification bar plus message in notification drawer) from a shell script that I'm running on my android device. I have CyanogenMod11, which comes with BusyBox v1.22.1 bionic.

    I've discovered how to create a toast (http://forum.xda-developers.com/showthread.php?t=773232) but what I need is a notification. For difference between toast and notification, see this excellent thread: https://android.stackexchange.com/questions/52789/popups-dialogs-notifications-toasts-whats-the-difference

    Can anyone point me in the right direction? I'm guessing it will involve the Android Activity Manager (am) but I've searched every nook and cranny of the internet and cannot find a way to create a notification from the command line on android.


    Solution 1:

    source: https://forum.xda-developers.com/showpost.php?p=69859668&postcount=18

    date: 30th November 2016, 02:32 PM

    Two years ago I was in need of a simple notification tool that could have been run by a command line in a script. So far the best I found was this thread and the tiny app made by corruptor64. That wasn't exactly what I was looking for so I finally decided to try to make the tool by myself. Starting from scratch (I am not an Android developer) in a few days of studying and developing I ended up with a working small app, that I named Notify4Scripts and I made it public only this past June, here on GitHub https://github.com/halnovemila/Notify4Scripts

    Note that since the app is basically a service that has to be launched by the Android's shell "am" (activity manager) command, the Android system needs to be rooted first in order to be able to use such am command and have notify4scripts executed.

  5. Cannot run android emulator using Command line tools on Linux (PANIC: Broken AVD system path.)
  6. Question:

    I'm trying to set up Jenkins slave machine for UI tests of an android project. I've run out of ideas how to proceed when I encountered this issue trying to run android emulator:

    [myuser@jenkins-slave-002 emulator]$ export ANDROID_SDK_ROOT="/var/lib/android"
    [myuser@jenkins-slave-002 emulator]$ ./emulator -avd pixel-2-api28 -no-window -verbose -show-kernel
    emulator: Android emulator version 30.0.5.0 (build_id 6306047) (CL:N/A)
    emulator: Found AVD name 'pixel-2-api28'
    emulator: Found AVD target architecture: x86
    emulator: argv[0]: './emulator'; program directory: '/var/lib/android/emulator'
    emulator:  Not a directory: /var/lib/android/android/system-images/android-28/google_apis/x86/
    
    PANIC: Broken AVD system path. Check your ANDROID_SDK_ROOT value [/var/lib/android]!
    

    What am I missing?

    Duplicated android folder in /var/lib/android/android/system-images/(...) doesn't look right, but I have no idea where this comes from. I think it should be /var/lib/android/system-images/(...).

    Details:

    Earlier I've done complete setup of android sdk this way

    /lib/var/android/ unzip commandlinetools-linux-6200805_latest.zip (taken from https://developer.android.com/studio#command-tools)
    

    I've installed packages using sdkmanager --sdk_root=${ANDROID_HOME} "<package>"

    current sdkmanager listing:

    [myuser@jenkins-slave-002 bin]$ sdkmanager --sdk_root=${ANDROID_HOME} --list
    
    Installed packages:=====================] 100% Computing updates...             
      Path                                     | Version | Description                             | Location                                 
      -------                                  | ------- | -------                                 | -------                                  
      emulator                                 | 30.0.5  | Android Emulator                        | emulator/                                
      patcher;v4                               | 1       | SDK Patch Applier v4                    | patcher/v4/                              
      platform-tools                           | 29.0.6  | Android SDK Platform-Tools              | platform-tools/                          
      platforms;android-28                     | 6       | Android SDK Platform 28                 | platforms/android-28/                    
      system-images;android-28;google_apis;x86 | 10      | Google APIs Intel x86 Atom System Image | system-images/android-28/google_apis/x86/
      tools                                    | 1.0.0   | Android SDK Tools 1                     | tools/                                   
    

    I created avd this way:

    [myuser@jenkins-slave-002 bin]$ avdmanager create avd -n pixel-2-api28 --device "pixel_2" -k "system-images;android-28;google_apis;x86"
    
    Warning: Observed package id 'emulator' in inconsistent location '/var/lib/android/emulator' (Expected '/var/lib/emulator')
    Warning: Observed package id 'patcher;v4' in inconsistent location '/var/lib/android/patcher/v4' (Expected '/var/lib/patcher/v4')
    Warning: Observed package id 'platform-tools' in inconsistent location '/var/lib/android/platform-tools' (Expected '/var/lib/platform-tools')
    Warning: Observed package id 'platforms;android-28' in inconsistent location '/var/lib/android/platforms/android-28' (Expected '/var/lib/platforms/android-28')
    Warning: Observed package id 'system-images;android-28;google_apis;x86' in inconsistent location '/var/lib/android/system-images/android-28/google_apis/x86' (Expected '/var/lib/system-images/android-28/google_apis/x86')
    Warning: Observed package id 'tools' in inconsistent location '/var/lib/android/tools' (Expected '/var/lib/tools')
    Auto-selecting single ABI x86===========] 100% Fetch remote repository...       
    Parsing /var/lib/android/emulator/package.xmlParsing /var/lib/android/patcher/v4/package.xmlParsing /var/lib/android/platform-tools/package.xmlParsing /var/lib/android/platforms/android-28/package.xmlParsing /var/lib/android/system-images/android-28/google_apis/x86/package.xmlParsing /var/lib/android/tools/package.xml
    

    My .bashrc contains this:

    export PATH="/var/lib/android/tools:$PATH"
    export PATH="/var/lib/android/tools/bin:$PATH"
    export ANDROID_SDK_HOME=/var/lib/android
    export ANDROID_HOME=/var/lib/android
    

    these SDK paths exists:

    /var/lib/android/tools/bin
    /var/lib/android/tools/lib
    /var/lib/android/tools
    /var/lib/android/.android/cache
    /var/lib/android/.android/avd/pixel-2-api28.avd
    /var/lib/android/.android/avd
    /var/lib/android/licenses
    /var/lib/android/patcher/v4
    /var/lib/android/patcher
    /var/lib/android/.temp
    /var/lib/android/emulator/
    /var/lib/android/platform-tools/
    /var/lib/android/system-images/android-28
    /var/lib/android/platforms/android-28
    

    The environment is CentOS 7 linux distribution running on a vmware


    Solution 1:

    I was able to run the emulator with fixing the image.sysdir.1 entry in /.android/avd/<avd_name>.avd/config.ini file.

    I found this tip in in this question: PANIC: Broken AVD system path. Check your ANDROID_SDK_ROOT value

    Go to <user_home>/.android/avd/<avd_name> and open config.ini. Find the image.sysdir.1 property. It points at the directory, inside the SDK directory, that contains the actual system image. Make sure that this directory exists and contains files like build.prop, system.img, etc. If it doesn't, then you have to open the SDK Manager and download system images your AVD requires (see below).
    

    Solution 2:

  7. android - Could not find method commandLine()
  8. Question:

    I'm attempting to add a pre-pre-build shell script to my gradle/Android-Studio build. I've added the following to app/build.gradle:

    task prePreBuild << {
      commandLine 'ls'
    }
    preBuild.dependsOn prePreBuild
    

    When I invoke my build with ./gradlew assembleDebug I get the following error:

    Could not find method commandLine() for arguments [ls] on project ':app'
    

    If I replace the commandLine line with something like println 'Hello' then it works fine, and I can see the output from my new task.

    I searched for other mentions of "Could not find method commandLine" and found nothing. What is the correct way to invoke a shell script from this gradle task?


    Solution 1:

    You need to indicate the type of the task or use the exec block:

    task execute(type: Exec) {
    
    }
    

    or

    exec {
    
    }
    

    You can find more info on https://docs.gradle.org/current/dsl/org.gradle.api.tasks.Exec.html

  9. flutter - Android sdkmanager not found. Update to the latest Android SDK and ensure that the cmdline-tools are installed to resolve this
  10. Question:

    I was following a tutorial to install an android emulator, without android studio, and I was told to run the command- flutter doctor. Upon running this, I got this error-

    X Android license status unknown.
          Run `flutter doctor --android-licenses` to accept the SDK licenses.
    

    So I tried running flutter doctor --android-licenses, and I got this error-

    Android sdkmanager not found. Update to the latest Android SDK and ensure that the cmdline-tools are installed to
    resolve this.
    

    This is my ANDROID_HOME directory-

    enter image description here

    And Inside platforms, I have android-32 installed.

    I saw some fixes for this, but those were all with android studio. How do I fix this? Thanks in advance!


    Solution 1:

    1. Open Android Studio
    2. Open Preferences
    3. Appearances tab on the left
    4. System Settings
    5. Android SDKenter image description here
    6. Click Show Package details
    7. Toggle SDK Tools
    8. Apply and restart Android Studio
    9. Run flutter doctor

    Solution 2:

    If you're using the command line tool without android studio been installed todevelop mobile app here's a way around this issue I was able to resolve it.

    enter image description here

    First check if there are packages to be updated

    sdkmanager --list
    

    if there are then run the command below ensure you've good internet connection and power

    sdkmanager --update
    

    Next run

    sdkmanager --install "cmdline-tools;latest"
    

    Next run the command below and the error will not be there again.

    flutter doctor --android-licenses
    
    flutter doctor 
    

    and you're good to go!!! enter image description here

    Solution 3:

    If you are using Android Studio:

    1. Open Android Studio
    2. Goto File -> Settings -> Appearance & Behavior -> System Settings -> Android SDK (Screenshot attached below)

    screenshot
    3. Update/Install Android Studio Command-line Tools.
    4. Click apply and restart android studio.