Building for Android

(Difference between revisions)
Jump to: navigation, search
m (Debug with gdb: don't forget
(Debug with gdb: may as well just use adb all the way, no sense in trying to type on the device itself)
Line 72: Line 72:
Now, on the device (or, do it on your workstation by prefixing these commands with "adb shell"):  
With the device attached to adb (test with <code>adb devices</code>):
Find the process ID for Stellarium.
Find the process ID for Stellarium.
  ps | grep stellarium
  adb shell ps | grep stellarium
Then attach gdbserver to it
Then attach gdbserver to it
  gdbserver :5039 --attach ''pid''
  adb shell gdbserver :5039 --attach ''pid''
On your workstation, have ADB forward port from the device
On your workstation, have ADB forward port from the device

Revision as of 04:56, 9 February 2012

The build instructions should differ only minimally between operating systems. It might be possible to build through QtCreator, but I've no idea how to do so (see below)




  1. Necessitas (the Qt port for Android). The necessitas package includes the Android SDK and NDK, QtCreator, and the Qt libraries
    • API 11 is the current target, so you may want to install that (it may be wise for us to target 10 or an earlier one, however); if using another target, be sure to comment out the bits of the necessitas Java code that aren't applicable (they're prefixed by //@ANDROID-XX; it looks like necessitas QtCreator is supposed to treat these as preprocessor directives)
  2. JDK 6. Not JRE, not JDK 7
    • If you have JRE installed, the JAVA_HOME environment variable may be pointing at that instead of the JDK; you need this to point to the JDK root directory for ant to work properly


Through your distro's package manager, install:

  1. cmake (>= 2.8 is required)
  2. bazaar


  1. cmake
  2. MacPorts

Use MacPorts to install Bazaar. In a terminal window:

$ sudo port install bzr


  1. cmake
  2. bazaar (you'll likely want to check TortoiseBzr in the installer)
  3. MinGW/MSYS (be sure you check "MSYS shell environment" in in the installer)

Sync to experimental Android branch

The code currently resides in a personal branch.

bzr checkout lp:~brady.brenot/stellarium/android-port

More instructions for using Bazaar and Launchpad can be found in the Bazaar and Launchpad documentation.


I'm using build scripts based on QGIS' Android port from Marco Bernasocchi. These will make sure the build environment is set up correctly, that everything is set up for cross-compiling instead of compiling for your system, that the files all end up in the right places, and that the apk is built from those files. You can do all of this manually, but it's a considerably larger amount of typing than is required to build for the other platforms.


Within the stellarium/android/util directory, copy config.templ to config.conf, and edit according to the instructions within.


Open up a terminal, head into the stellarium/android/util directory, and run


Assuming you configured the config.conf correctly, Stellarium should build without a hitch.

Deploy to device

This is a necessary step to test Stellarium, as the Android emulator lacks OpenGL ES 2 support and will crash very quickly. Get the Android device connected to your computer by USB and make sure the adb drivers are installed (may be automatic, but it varies according to device), or use adbWireless to connect over wifi. Once you've connected and got adb working, run:


to install, then run the apk, or:


To quickly rebuild/install/run it.

Debug (C++)

Debug with gdb

(incomplete) (also, should write our own version of the ndk-gdb script to automate some of this)

If you need to debug as soon as the native code starts, import the project into Eclipse as described below, and set a breakpoint right before the necessitas code starts up the native side of the app. This line in should do the trick:


With the device attached to adb (test with adb devices):

Find the process ID for Stellarium.

adb shell ps | grep stellarium

Then attach gdbserver to it

adb shell gdbserver :5039 --attach pid

On your workstation, have ADB forward port from the device

adb forward tcp:5039 tcp:5039

Pull the app process off the device; this is the process starts and runs Android apps, so it's the process you're going to be debugging. gdb needs this.

adb pull /system/bin/app_process

Pull for debugging

adb pull /system/lib/

Open gdb, which should reside somewhere in the android ndk or sdk directories (figure out where).

Tell gdb where your source is

directory path/to/source

Give gdb the executable that it's going to be debugging, app_process

file path/to/app_process

And give it the locations of and so it can find them (you can run the command multiple times, it will add directory to the search path)

set solib-search-path /path/to/lib

Instructions on using gdb are beyond the scope of this document. You're on your own.

Now you should be able to resume in Eclipse and in gdb, and debug as usual.

It should be possible to hook gdb into Eclipse to allow GUI debugging. May want to investigate that at some point.

Debug with QtCreator

I haven't the foggiest. If anyone wants to investigate this, please go right ahead :)

To import the project into QtCreator

Run the script. This will start necessitas' QtCreator.

Edit the script, uncommenting the lines to echo the cmake flags and then exit. Run it, saving the cmake flags out to a file (./ > flags.out). Copy the flags.

In QtCreator, open the CMakeLists.txt in the root of the directory where you've checked out Stellarium. In the following windows, choose "MinGW Makefiles" or "Unix Makefiles" as the generator, paste the flags into the cmake arguments box, and click "Run cmake". Proceed, and you should be done.

However, when you try to run or debug the app, it builds the code and then does nothing with it. Not sure how to resolve that, or how to get it to attach to a process on a device. QtCreator is still a very nice IDE for editing the code, though.

Debug (Java)

There is some Java code here, but thanks to necessitas it should be kept to a minimum (aside from localization and bits from necessitas itself).

Debug with Eclipse

Install Eclipse (preferably Eclipse Classic). Follow the directions for installing ADT.

Create a new project, choose Android project, and choose "Create project from existing source". Point Eclipse at the stellarium/android/java directory. Go to Project -> Properties, and set the JDK compliance level to 1.6. You can now use Eclipse to build and debug the software. If debugging, as noted above, you must use a device. Stellarium will not run in the Android emulator.

Personal tools
in this wiki
other languages