1 Android platform support and APIs
3 # Compilation for Android
5 The compiler generates an APK file as the output when the `android`
6 module is imported by the compilation target. The path to the generated
7 file can be specified using the `-o` and `--dir` options.
9 # Host system configuration
11 Some configuration is required to compile for the Android platform from a GNU/Linux host.
13 1. Download and install the latest Android SDK __and__ NDK.
15 2. Update PATH so it includes the tools `android`, `ndk-build` and `ant`.
16 You should add something like the following snippet to your .bashrc or equivalent,
17 be careful to replace `ANDROID_SDK` and `ANDROID_NDK` with the full path where you installed each package.
20 export PATH=$PATH:ANDROID_SDK/tools/:ANDROID_SDK/platform-tools/:ANDROID_NDK/
23 2. Using the `android` executable, download the latest `tools, build-tools` and within the Android 4.0.3 (API 15) folder, install `SDK platform`.
24 You may have to install additional SDK platforms for applications with different targets.
26 3. Using your OS package manager, install `apt openjdk-7-jdk lib32stdc++6 lib32z1`.
27 On Debian and Ubuntu the command is:
30 sudo apt-get install apt openjdk-7-jdk lib32stdc++6 lib32z1
33 # Configure your Android application
35 The _app.nit_ framework and this project offers some services to
36 customize the generated Android application.
40 * All _app.nit_ annotations are applied to Android projects:
41 `app_name`, `app_namespace` and `app_version`.
43 See: `../app/README.md`
45 * Custom information can be added to the Android manifest file
46 using the annotations `android_manifest`, `android_manifest_application`
47 and `android_manifest_activity`.
49 Example usage to specify an extra permission:
52 android_manifest """<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>"""
55 * The API version target can be specified with `android_api_min`,
56 `android_api_max` and `android_api_target`. These take a single
57 integer as argument. They are applied in the Android manifest as
58 `minSdkVesion`, `targetSdkVersion` and `maxSdkVersion`.
60 See http://developer.android.com/guide/topics/manifest/uses-sdk-element.html
62 * The annotation `android_activity` defines a Java class used as an
63 entry point to your application. As of now, this annotation should
64 only be used by low-level implementations of Nit on Android.
65 Its usefulness will be extended in the future to customize user applications.
67 ## Project entry points
69 Importing `android::landscape` or `android::portrait` locks the generated
70 application in the specified orientation. This can be useful for games and
71 other multimedia applications.
75 There are two compilation modes for the Android platform, debug and release.
76 Theses modes are also applied to the generated Android projects.
77 The compilation mode is specified as an argument to `nitc`, only
78 `--release` can be specified as debug is the default behavior.
82 Debug mode enables compiling to an APK file without handling signing keys
83 and their password. The APK file can be installed to a local device with
84 USB debugging enabled, but it cannot be published on the Play Store.
86 By default, `nitc` will compile Android applications in debug mode.
90 Building in release mode will use your private key to sign the
91 APK file, it can then be published on the Play Store.
93 1. Have a keystore with a valid key to sign your APK file.
95 To create a new keystore, avoid using the default values of `jarsigner`
96 as they change between versions of the Java SDK. You should instead use a
97 command similar to the following, replacing `KEYSTORE_PATH` and `KEY_ALIAS`
98 with the desired values.
101 keytool -genkey -keystore KEYSTORE_PATH -alias KEY_ALIAS -sigalg MD5withRSA -keyalg RSA -keysize 1024 -validity 10000
104 2. Set the environment variables used by `nitc`: `KEYSTORE`, `KEY_ALIAS` and
105 optionally `TSA_SERVER`. These settings can be set in a startup script such as
106 `~/.bashrc` or in a local Makefile.
108 You can use the following commands by replacing the right-hand values
109 to your own configuration.
112 export KEYSTORE=keystore_path
113 export KEY_ALIAS=key_alias
114 export TSA_SERVER=timestamp_authority_server_url # Optional
117 3. Call `nitc` with the `--release` options. You will be prompted for the
118 required passwords as needed by `jarsigner`.