[TIMOB-27798] Android: Module build should auto-download NDK if not installed
GitHub Issue | n/a |
---|---|
Type | Improvement |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2020-05-05T23:25:09.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 9.0.2 |
Components | Android |
Labels | android, build, gradle, module, ndk |
Reporter | Joshua Quick |
Assignee | Joshua Quick |
Created | 2020-03-10T18:42:35.000+0000 |
Updated | 2020-05-05T23:25:09.000+0000 |
Description
*Summary:*
Google's gradle tool supports downloading the Android NDK for C/C++ builds. Titanium's module build system should automatically download the NDK in case it's not already installed. This will help reduce tech-support issues.
*Recommended Solution:*
When we upgrade the Android gradle plugin to v3.6.0 or higher, we can specify the exact NDK version we want to download in the
build.gradle
as follows.
https://developer.android.com/studio/projects/install-ndk#apply-specific-version
android {
ndkVersion "major.minor.build"
}
We should do the above if the CLI fails to find the Android NDK path in our [_buildModule.js](https://github.com/appcelerator/titanium_mobile/blob/master/android/cli/commands/_buildModule.js) script. In this case, we should also omit the NDK path from the gradle local.properties
file [here](https://github.com/appcelerator/titanium_mobile/blob/master/android/cli/commands/_buildModule.js#L517).
*Research Results:*
Using android.ndkVersion
to download a specific version (as noted above) appears to be unreliable.
https://issuetracker.google.com/issues/132876707
https://stackoverflow.com/questions/60404457/android-no-version-of-ndk-matched-the-requested-version
Attempting to set this to NDK version 19.2.5345600
causes the following build error.
No version of NDK matched the requested version 19.2.5345600. Versions available locally: 20.1.5948944
Attempting to set this to NDK version 20.0.5594570
causes the following build error. This appears to be a recent issue.
No version of NDK matched the requested version 20.0.5594570. Versions available locally: 20.1.5948944
It seems like when new NDK versions get released, older NDK versions appear to stop downloading via gradle (this is speculation). Because of this, we should avoid this feature at the moment. If we don't set the NDK version in gradle, then the gradle build system will download the newest NDK version which has a minor issue noted in [TIMOB-27776] but it still works.
PR (master): https://github.com/appcelerator/titanium_mobile/pull/11531 PR (9.0.x): https://github.com/appcelerator/titanium_mobile/pull/11532
*FR Passed* NDK auto installs if it isn't already installed. Verified with the test case listed on the PR. Waiting to merge PR.
PR's merged.
Currently on Catalina Beta 1 (10.15.1 Beta (19B68f)) I see the following issue when following the test steps below: (I will add to this when I update to newest beta of Catalina and when I have done a fresh install of Android studio and its tools).
Use a machine that does not have the NDK installed.
Download the zipped source of module ti.nfc
Open the Terminal.
CD to android directory within the module
Enter: appc run -p android
Verify that you see log message similar to the below. This may take a few minutes.
[INFO] [GRADLE] Preparing "Install NDK (revision: 21.0.6113669)"
Verify that the module builds and its example project runs.
The builds fails if NDK not installed
Verified on: Mac OS: 10.15.1 SDK: 9.0.1.v20200408050151, 9.1.0.v20200406120646 Appc CLI: 8.0.0 JDK: 11.0.4 Node: 10.17.0
This started happening when we updated Android gradle tool to
3.6.0
via [TIMOB-27778]. This appears to be a bug in Android gradle tool3.6.0
,3.6.1
, and3.6.2
. If anndk.dir
is not provided via a "local.properties" file, then the Android gradle tool defaults to NDK version20.0.5594570
which is an *unstable* release. The gradle tools only supports downloading *stable* releases listed by the links below, which is why it fails. https://developer.android.com/ndk/downloads https://developer.android.com/ndk/downloads/older_releases I'll have to find a work-around.Since Google's default NDK version is an unstable version, we can work-around it by hard-coding the NDK version ourselves in gradle like the below, but this has its own issues too.
The above will only download the NDK if no other NDK versions are installed. If you have one or more NDK versions installed that don't match the requested versions, then Google's gradle tool will *NOT* download the requested version and will trigger a build failure.
PR (master): https://github.com/appcelerator/titanium_mobile/pull/11613 PR (9.0.x): https://github.com/appcelerator/titanium_mobile/pull/11620
FR Passed. 1. With no NDK on the system, the module build installs side-by-side NDK 2. When side-by-side NDK (any other version) is already installed the module build does not install the NDK 3. When side-by-side NDK is not installed but another NDK is on the system. "appc ti config" does not have flag for android.ndkPath set then the build for module installs side-by-side NDK. 4. When side-by-side NDK is not installed but another NDK is on the system. "appc ti config" flag for android.ndkPath is set to the NDK on the system then the module build does not install side-by-side NDK.
Waiting on Jenkins build
merged to 9_0_X for 9.0.2 target and master for 9.1.0 target.
Side-by-side NDK installed when building a module. Also the titanium app and module builds successfully when no NDK is installed previously and also when side-by-side NDK of another version is already installed. Verified on: Mac OS: 10.15.4 SDK: 9.1.0.v20200505112143, 9.0.2.v20200505111803 Appc CLI: 8.0.0 JDK: 11.0.6 Node: 10.17.0