blob: 1c5b3088a1ba95132f19b6a01e3c22c5d53c92f5 [file] [log] [blame] [view]
Alexander Afanasyevbd74ad22016-01-06 18:09:10 -08001Developer Notes
2===============
3
Alexander Afanasyev14fd3e22018-07-04 14:20:53 -04004## To build debug version of NDN-Android
Alexander Afanasyevbd74ad22016-01-06 18:09:10 -08005
6Configure `ndk.dir` and `sdk.dir` in `local.properties` file. For example:
7
Alexander Afanasyev14fd3e22018-07-04 14:20:53 -04008 sdk.dir=/opt/android-sdk
9 ndk.dir=/opt/android-sdk/ndk-bundle
Alexander Afanasyevbd74ad22016-01-06 18:09:10 -080010
11Build process can be customized using several environment variables:
12
13- `NDK_DEBUG`
14
15 If set, the native code is built in debug mode. For example:
16
Alexander Afanasyeva8d404b2016-11-05 10:07:08 -060017 NDK_DEBUG=1 ./gradlew assembleDebug
Alexander Afanasyevbd74ad22016-01-06 18:09:10 -080018
Alexander Afanasyevbd74ad22016-01-06 18:09:10 -080019## To build the release version of NFD
20
21In order to build the release version of NFD, it needs to be properly signed. In order to specify keystore, keystore's password, key in the keystore, and key's password, add the following configuration into `local.properties` file:
22
23
24 keystore=<path-to-.keystore-file>
25 keystore.password=<keystore-password>
26 keystore.key.alias=<key-alias-in-keystore>
27 keystore.key.password=<key-password>
28
Alexander Afanasyev14fd3e22018-07-04 14:20:53 -040029For more information about application signing and instructions on how to generate keys, refer to [Android Documentation](https://developer.android.com/studio/publish/app-signing).
Alexander Afanasyevbd74ad22016-01-06 18:09:10 -080030
31## To publish the release version on Google Play
32
33The release version of NFD can be automatically uploaded to Google Play, if Google Play parameters are configured in `local.properties` files:
34
35 google-play=<path-to-json-config>
36
37Note that `.json` config can be downloaded from Google Developer Console. For more information, refer to [Google Play Publishing Plugin](https://github.com/Triple-T/gradle-play-publisher).
Alexander Afanasyev14fd3e22018-07-04 14:20:53 -040038
39## Building NDN-Android with different version of underlying NFD, ndn-cxx, or other dependencies
40
41NDN-Android build assumes existence of prebuilt binaries (=shared libraries) for all dependencies, including NFD, ndn-cxx, boost, sqlite, libssl. As of version 0.6.2-1, these dependencies are managed by an external tool called [crew tool](https://github.com/named-data-mobile/android-crew-staging), a hacked version of the official tool that was designed for [CrystaX NDK](https://github.com/crystax/android-crew-staging) (the hacked version targeting the official NDK r18, support specifically clang, and not all packages would work).
42
43The basic workflow with the crew tool is as follows:
44
45- Getting the tool into the right place relative to NDK folder:
46
47 cd /opt/android-sdk/android-ndk
48 git clone https://github.com/named-data-mobile/android-crew-staging crew.dir
49
50- Installing precompiled binary (downloaded from Github relese page)
51
52 ./crew.dir/crew install target/<package>[:<version>]
53
54 `target/` indicates that the package is intended for Android target. The official tool also supports installing dependencies for the host system (`host/`), but the hacked version has not been tested for that.
55
56 `<package>` one of the available packages.
57
58 `:<version>` an optional version, in case there are multiple versions available
59
60 To get list of all available packages and their versions, you can use `./crew.dir/crew list` command.
61
62- Installing packages from source
63
64 The process is similar to installing precompiled binary but split into two stages: getting source and actually building the package
65
66 Get the source
67
68 ./crew.dir/crew source <package>[:<version>]
69
70 Build
71
72 ./crew.dir/crew build target/<package>[:<version>]
73
74 The `source` command downloading source of the specified package (URL or git repo defined in `crew.dir/formula/packages/<package>.rb` --- note that getting code from git repo may fail with old versions of ruby. If you are getting strange segfaults, try using a different version of ruby, known to work with version 2.5.1p57). After downloading, it will apply any patches for the package version in `./crew.dir/patches/packages/<package>/<version>` (all `.patch` files will be applied to the source).
75
76 If additional patches need to be applied or old patch re-applied, you need to remove source and add source again:
77
78 ./crew.dir/crew remove-source <package>[:<version>]
79 ./crew.dir/crew source <package>[:<version>]
80
81 NOTE. To build package from a different source code, you need to modify the package definition (`./crew.dir/formula/packages/<package>.rb`): source code can be downloaded from an online archive or any git source (using tag or commit-id). See the existing packages for reference.
82
83- To delete the downloaded version of a package:
84
85 ./crew.dir/crew remove <package>[:<version>]
86
87- To delete source and the built version of a package:
88
89 ./crew.dir/crew remove-source <package>[:<version>]
90 ./crew.dir/crew remove <package>[:<version>]
91
92Note that whenever `ndn_cxx`, `nfd`, or dependencies package is (re-)built or (re-)installed, you just need to clean and re-build NDN-android (`./gradlew clean` and `./gradlew assembleDebug`). It will automatically use the available package. However, if you changed version of built/installed NFD, you will need to update `app/src/main/jni/Android.mk`, which hardcodes the specific version of NFD package. All other dependencies are transitively defined by the crew tool and do not need to be explicitly defined.
93
94### Quick reference for crew tool internals
95
96A trimmed file structure:
97
98 ├── etc
99 │   ├── ca-certificates.crt
100 │   └── shasums.txt
101 ├── library
102 │   ├── arch.rb
103 │   ├── base_package.rb
104 │   ├── build.rb
105 │   ├── build_dependency.rb
106 │   ├── cmd
107 │   │   ├── <...>.rb
108 │   ├── command_options.rb
109 │   ├── compiler_wrapper_helper.rb
110 │   ├── deb.rb
111 │   ├── exceptions.rb
112 │   ├── extend
113 │   │   ├── dir.rb
114 │   │   └── module.rb
115 │   ├── formula.rb
116 │   ├── formulary.rb
117 │   ├── github.rb
118 │   ├── global.rb
119 │   ├── host_base.rb
120 │   ├── multi_version.rb
121 │   ├── package.rb
122 │   ├── patch.rb
123 │   ├── platform.rb
124 │   ├── properties.rb
125 │   ├── release.rb
126 │   ├── shasum.rb
127 │   ├── single_version.rb
128 │   ├── target_base.rb
129 │   ├── tool.rb
130 │   ├── toolchain.rb
131 │   ├── utility.rb
132 │   └── utils.rb
133 ├── formula
134 │   ├── packages
135 │   │   ├── <package-formula>.rb
136 │   └── tools
137 │   ├── <tool>.rb
138 │   └── ....rb
139 ├── patches
140 │   ├── packages
141 │   │   ├── <package-name>
142 │   │   │   └── <package-version>
143 │   │   │   ├── <file1>.patch
144 │   │   │   ├── <file2>.patch
145 │   │   │   └── ...
146
147
148Notable places:
149
150- `formula/packages/<package-formula>.rb`: ruby scripts defining formula where to download source, dependencies, and how to build the package
151
152- `patches/packages/<package-name>/<package-version>/`: patch files to be applied for a version of a package
153
154- `library/toolchain.rb`: definition of the toolchains, including necessary compilation flags for different platforms.
155
156- `library/package.rb`: default/available options to customize package build and basic build stages. Note that to build a package, crew tool creates "compiler wrapper" placed in the build directory of a package using the specified name. This wrapper, internally, runs a proper compiler executable with any additional parameters (as defined in `library/toolchain.rb`). Depending on the options defined for the package, the wrapper can also "wrap" compilation and linking flags, but it may not work. Normally, during the build, the crew tool defines `CFLAGS`, `CXXGLAGS`, `LDFLAGS`, and bunch of other flags (including paths to various tools such as nm, ar, etc.).