Building for Android

From Stellarium Wiki
Revision as of 08:14, 8 February 2012 by Brady Brenot (Talk | contribs)
Jump to: navigation, search

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)

Contents

Prerequisites

All

  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

Linux

Through your distro's package manager, install:

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

OS X

  1. cmake
  2. MacPorts

Use MacPorts to install Bazaar. In a terminal window:

$ sudo port install bzr

Windows

  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.

Build

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.

Configure

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

Build

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

./build-all.sh

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:

./install-apk.sh
./run-apk.sh

to install, then run the apk, or:

./build-run-apk.sh

To quickly rebuild/install/run it.

Debug (C++)

Debug with gdb

(These instructions do not work. Not loading the symbols for some reason? Figuring it out...)

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.

Now, on the device (or, do it on your workstation by prefixing these commands with "adb shell"):

Find the process ID for Stellarium.

ps | grep stellarium

Then attach gdbserver to it

gdbserver :5039 --attach pid

On your workstation, have ADB forward port from the device

adb forward tcp:5039 tcp:5039

Now, I have the feeling that the build process doesn't strip symbols from debug executables (if we'd used ndk-build, it would), so you likely don't have to give gdb an unstripped version of the library. However, the downside is that the library is enormous... then again, it's probably dwarfed by the size of the supporting files, so no biggie.

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

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.

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 necessitas-qtcreator.sh script. This will start necessitas' QtCreator.

Edit the build-stel.sh script, uncommenting the lines to echo the cmake flags and then exit. Run it, saving the cmake flags out to a file (./build-stel.sh > 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
Namespaces
Variants
Actions
in this wiki
other languages
Toolbox