Search code examples
javaandroidlinuxant

Compiling Android .apk on Linux Server


I want to be able to build .apk files programmatically given Android projects (folders, .java, .xml, etc files) with ant on my Ubuntu 10.04 i386 Server. I'm not using Eclipse or even a GUI.

1) I have already followed these instructions: http://source.android.com/source/initializing.html

2) I downloaded/unpacked the Android Linux SDK here: http://developer.android.com/sdk/index.html

3) Now when I navigate to /home/myusername/www/android-sdk-linux_x86/tools and type in ./android I get this error:

myusername@myserver:~/www/android-sdk-linux_x86/tools$ ./android
Starting Android SDK and AVD Manager
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.sdkmanager.Main.showMainWindow(Main.java:297)
    at com.android.sdkmanager.Main.doAction(Main.java:281)
    at com.android.sdkmanager.Main.run(Main.java:99)
    at com.android.sdkmanager.Main.main(Main.java:88)

Any ideas on what is going wrong?


Solution

  • When you run the ./android binary without arguments it tries to open a GUI window.

    From the output you presented, it seems that the ./android binary is working great, but since you are running a headless server it crashes.

    Here are the command-line steps to build an Android .apk:

    1. android create project --name ExampleProj --activity ExampleProj --path ./ --package com.example.project --target 2
    2. ant debug

    This will create an ExampleProj-debug.apk.

    A great source of help is the --help argument of the ./android binary, combined with the action you want to take. For instance:

    android --help create project
    

    Hope this helps.