I want to cache the Android NDK in my Github Actions workflow. The reason is that I require a specific version of the NDK and CMake which aren't pre-installed on MacOS runners.
I tried to use the following workflow job to achieve this:
jobs:
build:
runs-on: macos-latest
steps:
- name: Cache NDK
id: cache-primes
uses: actions/cache@v1
with:
path: ${{ env.ANDROID_NDK_HOME }}
key: ${{ runner.os }}-ndk-${{ hashFiles(env.ANDROID_NDK_HOME) }}
- name: Install NDK
run: echo "y" | $ANDROID_HOME/tools/bin/sdkmanager "ndk;21.0.6113669" "cmake;3.10.2.4988404"
The problem with this is that the env
context doesn't contain the ANDROID_NDK_HOME
variable. So this means build.steps.with.path
evaluates empty.
The regular environment variable is present and prints the correct path if I debug using the following step:
jobs:
build:
steps:
- name: Debug print ANDROID_NDK_HOME
run: echo $ANDROID_NDK_HOME
But the regular environment variable can only be used in shell scripts and not in build.steps.with
as far as I understand.
Open your Android Studio Preference (or "File->Settings") > Appearance & Behavior > System Settings > Android SDK. You can find the path to your SDK and NDK, which is in the same directory.
NDK (Side by side) is irrelevant for Android Gradle Plugin earlier than 3.5. However, the components available for download by SDK manager aren't customizable based on Android Gradle Plugin version so the side by side NDKs will appear. The non side by side NDK has been marked as obsolete.
To help speed up the time it takes to recreate these files, GitHub can cache dependencies you frequently use in workflows. To cache dependencies for a job, you'll need to use GitHub's cache action. The action retrieves a cache identified by a unique key. For more information, see actions/cache.
While bitoiu's answer is correct that there's no explicit caching feature in GitHub Actions today, you do get implicit caching across steps in a workflow within a given workflow run. This happens because GitHub volume mounts your repo into Docker for each step.
This action sets up an Android NDK environment by downloading and caching a version of the NDK and adding it to the PATH steps : - uses: actions/checkout@v2 - uses: nttld/setup-ndk@v1 with : ndk-version: r21e - runs: ndk-build NDK_PROJECT_PATH=.
CI/CD are core practices in modern software development and there are many platforms/tools that can be used for Android projects. Github Actions is one of them. It’s a platform that enables you to automate development workflows directly in your Github repository, and they can run automatically, triggered by certain events.
- name: Prepare NDK dir for caching ( workaround for https://github.com/actions/virtual-environments/issues/1337 )
run: |
sudo mkdir -p /usr/local/lib/android/sdk/ndk
sudo chmod -R 777 /usr/local/lib/android/sdk/ndk
sudo chown -R $USER:$USER /usr/local/lib/android/sdk/ndk
- name: NDK Cache
id: ndk-cache
uses: actions/cache@v2
with:
path: /usr/local/lib/android/sdk/ndk
key: ndk-cache-21.0.6113669-v2
- name: Install NDK
if: steps.ndk-cache.outputs.cache-hit != 'true'
run: echo "y" | sudo /usr/local/lib/android/sdk/tools/bin/sdkmanager --install "ndk;21.0.6113669"
Here is a config I use in my project.
Couple of note:
id
(ndk-cache in example above) in if statement so
you can actually use cacheYou can easily specify the NDK installation directory to be cached.
- name: Cache (NDK)
uses: actions/cache@v2
with:
path: ${ANDROID_HOME}/ndk/21.0.6113669
key: ndk-cache
- name: Install NDK
run: echo "y" | sudo ${ANDROID_HOME}/tools/bin/sdkmanager --install 'ndk;21.0.6113669'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With