Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-27798] Android: Module build should auto-download NDK if not installed

GitHub Issuen/a
TypeImprovement
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2020-05-05T23:25:09.000+0000
Affected Version/sn/a
Fix Version/sRelease 9.0.2
ComponentsAndroid
Labelsandroid, build, gradle, module, ndk
ReporterJoshua Quick
AssigneeJoshua Quick
Created2020-03-10T18:42:35.000+0000
Updated2020-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.

Comments

  1. Joshua Quick 2020-03-11

    PR (master): https://github.com/appcelerator/titanium_mobile/pull/11531 PR (9.0.x): https://github.com/appcelerator/titanium_mobile/pull/11532
  2. Sohail Saddique 2020-03-19

    *FR Passed* NDK auto installs if it isn't already installed. Verified with the test case listed on the PR. Waiting to merge PR.
  3. Sohail Saddique 2020-03-20

    PR's merged.
  4. Samir Mohammed 2020-04-02

    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.

  5. Satyam Sekhri 2020-04-08

    The builds fails if NDK not installed
       [INFO]  [GRADLE] WARNING: Compatible side by side NDK version was not found. Default is 20.0.5594570.
       [INFO]  [GRADLE] Compatible side by side NDK version was not found. Default is 20.0.5594570.
       [ERROR] [GRADLE] 
       [ERROR] [GRADLE] FAILURE: Build failed with an exception.
       [ERROR] [GRADLE] 
       [ERROR] [GRADLE] * What went wrong:
       [ERROR] [GRADLE] A problem occurred configuring project ':module'.
       [ERROR] [GRADLE] > Failed to notify project evaluation listener.
       [ERROR] [GRADLE]    > NDK not configured. Download it with SDK manager. Preferred NDK version is '20.0.5594570'. Log: /Users/satyamsekhri/Documents/GitRepos/ti.imagefactory-stable/android/build/module/.cxx/ndk_locator_record.json
       [ERROR] [GRADLE]    > Could not get unknown property 'externalNativeBuildDebug' for project ':module' of type org.gradle.api.Project.
       [ERROR] [GRADLE] 
       [ERROR] [GRADLE] * Try:
       [ERROR] [GRADLE] Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
       [ERROR] [GRADLE] 
       [ERROR] [GRADLE] * Get more help at https://help.gradle.org
       [ERROR] [GRADLE] 
       [ERROR] [GRADLE] BUILD FAILED in 897ms
       [ERROR] "gradlew" tool returned exit code: 1
       [ERROR] An error occurred during build after 2s 441ms
       [ERROR] "gradlew" tool returned exit code: 1
       
    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
  6. Joshua Quick 2020-04-08

    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 tool 3.6.0, 3.6.1, and 3.6.2. If an ndk.dir is not provided via a "local.properties" file, then the Android gradle tool defaults to NDK version 20.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.
  7. Joshua Quick 2020-04-09

    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.
       android {
       	ndkVersion '21.0.6113669'
       }
       
    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.
  8. Joshua Quick 2020-04-09

    PR (master): https://github.com/appcelerator/titanium_mobile/pull/11613 PR (9.0.x): https://github.com/appcelerator/titanium_mobile/pull/11620
  9. Satyam Sekhri 2020-04-30

    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.
  10. Satyam Sekhri 2020-04-30

    Waiting on Jenkins build
  11. Christopher Williams 2020-04-30

    merged to 9_0_X for 9.0.2 target and master for 9.1.0 target.
  12. Satyam Sekhri 2020-05-05

    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

JSON Source