build_android.md 3.94 KB
Newer Older
1
# Build Cesium for Android
2

3
Cesium can be build as an Android App.
4

5 6
Cesium use [Ionic Framework v1.7.16](http://ionicframework.com/docs/v1/) with some Apache Cordova plugins.

7 8
## Prerequisites

9
### Install the development environment
10

11
Follow all the steps defined in the [Development guide](./development_guide.md).
12

13
After that you should be able to start the application using `npm start`, and to test it.
14 15 16 17 18

### Install JDK (Java Development Kit)

You can choose to install
 
19
- on Linux, install OpenJDK 8:
20 21 22
 
  * ``sudo apt-get install openjdk-8-jdk``
    
23
- or Oracle JDK 8 (all platforms supported):
24 25 26 27 28 29 30 31 32 33 34 35
  
   * Download it from [Oracle web site](http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html)
   
   <img src="./fr/img/fef4f4dfe7c2168cb27c9e7f5e399fd547ce774a.png" width="400">

   And choose the right version, depending on your platform.

### Install Android Studio


Download Android Studio from the [AndroidStudio-Downloads page](https://developer.android.com/studio/index.html#downloads)

36
- On MS Windows:
37 38 39 40
  
  * Download file **without** the Android SDK:
  <img src="./fr/img/3b8fa2f5c0465b13ae5ce74d49702e0c9f027866.png" width="690" height="237">
  
41
  * Then follow installation steps.
42

43
- On Linux : 
44 45 46 47 48 49 50 51 52 53 54 55 56 57
 
  * download the full archive, then uncompress it (e.g in `/opt/android-sdk`).

  * open a terminal, run the command:
  ```bash
  ./bin/studio.sh
  ```

At the end of the installation or the first launch, Android Studio will indicate that you do not have an SDK and will propose to install it.

Install the version that it proposes to you.

### Install Android NDK

58
> The NDK is used for code execution in C ++, need to build the NaCL cryptography library.
59

60
- Download NDK from [this page](https://developer.android.com/ndk/downloads/index.html)
61

62
  * **Warning**: Please use version `r10d` (not tested on newer versions).
63

64
- Uncompress the archive (e.g on Linux, in a new directory `/opt/android-ndk`).
65

66
- Launch Android-studio, then open the menu `File > Project Structure...`
67

68
  <img src="./fr/img/04e64b769cbd45b9d275cd5f81002a399a1a7684.png" width="300">
69

70
- A window like this should open: 
71

72
  <img src="./fr/img/ceb75301172038e75f5c43b328dd7febd7bedc7e.png" width="450">
73

74
- Fill in the installation path of the NDK.
75

76 77 78 79 80 81
### Install Gradle

- Download [Gradle 4.1](wget https://services.gradle.org/distributions/gradle-4.1-bin.zip)

- Uncompress the archive (e.g in `/opt/gradle`).

82 83 84 85
## Android configuration

Android need some configuration, to be able to build Cesium.

86
- First, create a properties file `local.properties` in the directory `platforms/android`:
87 88 89 90 91 92 93 94 95
 
```properties
# Path to your Android SDK installation
sdk.dir=/opt/android-sdk

# Path to your Android NDK installation
ndk.dir=/opt/android-ndk
```

96 97 98 99 100 101 102 103
- In order to sign your Android builds: 
 
  * Generate a new keystore file :
```
keytool -genkey -v -keystore Cesium.keystore -alias Cesium -keyalg RSA -keysize 2048 -validity 10000`
```

  * Create a file `release-signing.properties` in the directory `platforms/android`:
104
```properties
105
storeFile=/path/to/Cesium.keystore
106 107 108 109 110
keyAlias=Cesium
storePassword=YourStorePassword
keyPassword=YourKeyPassword
```

111
- Open Android Studio, then open the menu `File > Settings...`. Set `Gradle Home` to your fresh Gradle installation directory (e.g. `/opt/gradle`).
112 113 114

## Generate APK file

115
 - To build a signed APK file:
116 117 118 119
```
ionic build android --release
```

120
 - To build an unsigned (debug) APK:
121 122 123 124
```
ionic build android
```

125
Generated APK files should be in the directory `platforms/android/build/outputs/apk`.
126 127 128 129 130 131 132

### Troubleshooting

#### "Cannot run program (...)/aapt"

If you get this error:

133 134 135
```
Cannot run program "/opt/android-sdk/build-tools/21.1.2/aapt": error=2, No such file or folder
```
136

137
Then install two additional compatibility libraries (workaround found in [this post](http://stackoverflow.com/questions/22701405/aapt-ioexception-error-2-no-such-file-or-directory-why-cant-i-build-my-grad)):                            
138 139 140
```bash
sudo apt-get install lib32stdc++6 lib32z1
```