Command line "Android update sdk" on headless Linux

Android

Android Problem Overview


How can I update/install the Android SDK platforms on a headless Linux server?

All I got was the following error:

It seems like the action "update sdk" is actually not supported.

~/android-sdk-linux_86/tools$ ./android --verbose update sdk
No command line parameters provided, launching UI.
See 'android --help' for operations from the command line.
Exception in thread "main" java.lang.UnsatisfiedLinkError: no swt-pi-gtk-3550 or swt-pi-gtk in swt.library.path, java.library.path or the jar file
        at org.eclipse.swt.internal.Library.loadLibrary(Unknown Source)
        at org.eclipse.swt.internal.Library.loadLibrary(Unknown Source)
        at org.eclipse.swt.internal.gtk.OS.<clinit>(Unknown Source)
        at org.eclipse.swt.internal.Converter.wcsToMbcs(Unknown Source)
        at org.eclipse.swt.internal.Converter.wcsToMbcs(Unknown Source)
        at org.eclipse.swt.widgets.Display.<clinit>(Unknown Source)
        at com.android.sdkuilib.internal.repository.UpdaterWindowImpl.open(UpdaterWindowImpl.java:93)
        at com.android.sdkuilib.repository.UpdaterWindow.open(UpdaterWindow.java:110)
        at com.android.sdkmanager.Main.showMainWindow(Main.java:281)
        at com.android.sdkmanager.Main.doAction(Main.java:251)
        at com.android.sdkmanager.Main.run(Main.java:92)
        at com.android.sdkmanager.Main.main(Main.java:81)


The question was asked when headless update wasn't supported. As of 2012, it is now possible to do just a android update sdk --no-ui.

Android Solutions


Solution 1 - Android

You can use the --no-ui option:

android update sdk --no-ui

If you'd like to automate it, you could accept all licenses by using the expect tool with this hack (the --accept-license option is currently not fully integrated in the android tool):

expect -c '
set timeout -1;
spawn android - update sdk --no-ui;
expect {
    "Do you accept the license" { exp_send "y\r" ; exp_continue }
    eof
}
'

Solution 2 - Android

Updating Android SDK headless and automatically is described in Stack Overflow question Is there a way to automate the Android SDK installation?.

Solution 3 - Android

I just ran into the same problem. I found a workaround though.

The first one is a cop-out: Download the platforms on a headed system and simply copy the platform subdirectories into your Android sdk/platforms directory.

If, like me, you don't have immediate access to another headed Android development environment, you can go to Google's SDK archives and download one of the other SDK's that included the platforms. This way means that you can only develop for Android 1.1 and 1.5 though.

The download to get for Linux systems is their Android 1.5 r3. Of course, Google's SDK download pages aren't Lynx-friendly, so I had to get the direct link from another GUI system.

wget http://dl.google.com/android/archives/android-sdk-linux_x86-1.5_r3.zip

Then it's simply a matter of unzipping the archive, and moving the platform subdirectories to your newer SDK platform directory.

android create avd -t 3 -p path/to/avd/dir -n "name"

This creates an AVD for the 1.5 platform with your specified name and directory. Note that the avd directory shouldn't exist. If you want to overwrite, add --force to the command.

Getting this far has a platform installed and creates an AVD. Unfortunately, trying to build failed at this point for me, because I run a 64-bit server, and Google only releases 32-bit tools.

I found a solution for this in the accepted answer of this Stack Overflow question and used sudo apt-get install ia32-libs to enable the ability to run the 32-bit tools.

Then you should be able to use the android tool on the CLI to either convert an Eclipse project (for 1.5 or lower) to have an Ant build system, or you can have it create a new project for you to start working on.

Solution 4 - Android

Yes, it works but you need the GUI libraries installed and you need your DISPLAY environment variable set to what X server you want it to display.

I have it working now on CentOS 5.4 and had to use the "Server - GUI" verse "Server" install option. Then I just use "ssh -X" from the system where I want it to display.

Solution 5 - Android

I just created a small command line tool that does the update in any environment (GUI or non-GUI). Didn't have the chance to test it extensively, but as far as I can tell it does what it should.

The command line tool updates a pre-installed base Android SDK with all currently available platforms, add-ons, extras, docs, samples and tools. This should be enough for a build server (I need this for my Hudson CI installation with Maven).

Please go here for more details:

http://code.google.com/p/android-sdk-tool

Solution 6 - Android

I had to analyze it using strace -f -v -s1024 -o/tmp/android.log ./android. I found the needed libs were being automatically created, and found, under /tmp/swtlib-64/. However, I still got the above error. Digging further into /tmp/android.log, I found libgtk-x11-2.0.so.0 was not found. So after sudo apt install libgtk2.0-0, I could run the android installer graphically using ssh -X to the headless server.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionfocuserView Question on Stackoverflow
Solution 1 - Androidx2onView Answer on Stackoverflow
Solution 2 - AndroidDiego Torres MilanoView Answer on Stackoverflow
Solution 3 - AndroidMarcView Answer on Stackoverflow
Solution 4 - AndroidJasonView Answer on Stackoverflow
Solution 5 - AndroidcheetahView Answer on Stackoverflow
Solution 6 - Androidjcomeau_ictxView Answer on Stackoverflow