1f4e6591494a0d36f86f330cc5548e0ccbf8ad8a
[nit.git] / lib / android / README.md
1 The `android` module provides support for the Android platform
2
3 # Compilation for Android
4
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.
8
9 # Host system configuration
10
11 To compile for Android, you must install the Android SDK and NDK.
12 The tools `android`, `ndk-build` and `ant` must be in your PATH.
13
14 # Configure your Android application
15
16 The `app.nit` framework and this project offers some services to
17 customized the generated Android application.
18
19 ## Module annotations
20
21 * `app_version` specifies the version of the generated APK file.
22 It takes 3 arguments: the major, minor and revision version numbers.
23 The special function `git_revision` will use the prefix of the hash of the
24 latest git commit. The default version is 1.0.
25
26     Example: `app_version(1, 0, git_revision)`
27
28 * `app_name` takes a single argument, the visible name of the Android
29 application. By default, the compiler would use the name of the target
30 module. This name will be used as the name of the main activity and
31 as the launcher name.
32
33     Example: `app_name "My App"`
34
35 * `java_package` specifies the package used by the generated Java
36 classes and the APK file. Once the application is published, this
37 value should not be changed. By default, the compiler will use
38 the package `org.nitlanguage.{module_name}`.
39
40 * Custom information can be added to the Android manifest file
41 using the annotations `android_manifest`, `android_manifest_application`
42 and `android_manifest_activity`.
43
44     Example usage to specify an extra permission:
45
46     ~~~
47     android_manifest """<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>"""
48     ~~~
49
50 * The API version target can be specified with `min_api_version`,
51 `max_api_version` and `target_api_version`. These take a single
52 integer as argument. They are applied in the Android manifest as
53 `minSdkVesion`, `targetSdkVersion` and `maxSdkVersion`.
54
55     See http://developer.android.com/guide/topics/manifest/uses-sdk-element.html
56
57 ## Project entry points
58
59 Importing `android::landscape` or `android::portrait` locks the generated
60 application in the specified orientation. This can be useful for games and
61 other multimedia applications.
62
63 # Compilation modes
64
65 There are two compilation modes for the Android platform, debug and release.
66 Theses modes are also applied to the generated Android projects.
67 The compilation mode is specified as an argument to `nitc`, only
68 `--release` can be specified as debug is the default behavior.
69
70 ## Debug mode
71
72 Debug mode enables compiling to an APK file without handling signing keys
73 and their password. The APK file can be installed to a local device with
74 USB debugging enabled, but it cannot be published on the Play Store.
75
76 By default, `nitc` will compile Android applications in debug mode.
77
78 ## Release mode
79
80 Building in release mode will use your private key to sign the
81 APK file, it can then be published on the Play Store.
82
83 1. Have a keystore with a valid key to sign your APK file.
84
85     To create a new keystore, avoid using the default values of `jarsigner`
86 as they change between versions of the Java SDK. You should instead use a
87 command similar to the following, replacing `KEYSTORE_PATH` and `KEY_ALIAS`
88 with the desired values.
89
90     ~~~
91     keytool -genkey -keystore KEYSTORE_PATH -alias KEY_ALIAS -sigalg MD5withRSA -keyalg RSA -keysize 1024 -validity 10000
92     ~~~
93
94 2. Set the environment variables used by `nitc`: `KEYSTORE`, `KEY_ALIAS` and
95 optionally `TSA_SERVER`. These settings can be set in a startup script such as
96 `~/.bashrc` or in a local Makefile.
97
98     You can use the following commands by replacing the right hand values
99 to your own configuration.
100
101     ~~~
102     export KEYSTORE=keystore_path
103     export KEY_ALIAS=key_alias
104     export TSA_SERVER=timestamp_authority_server_url # Optional
105     ~~~
106
107 3. Call `nitc` with the `--release` options. You will be prompted for the
108 required passwords as needed by `jarsigner`.