Search code examples
androidandroid-ndkndk-buildbitbucket-pipelines

Android NDK CI using Bitbucket Pipelines


I am trying to build an NDK Android project using Bitbucket Pipelines continuous integration using ndk-build (not the newer CMAKE). But I am getting the following error when calling ./gradlew assembleDebug:

/opt/android-sdk-linux/ndk-bundle/build/ndk-build: 144: /opt/android-sdk-linux/ndk-bundle/build/ndk-build: file: not found
:sensorylib:ndkBuild
make: Entering directory '/opt/atlassian/pipelines/agent/build/sensorylib/src/main'
/bin/sh: 1: file: not found
make: execvp: /opt/android-sdk-linux/ndk-bundle/build/extract_manifest.py: Permission denied
make: execvp: /opt/android-sdk-linux/ndk-bundle/build/extract_manifest.py: Permission denied
[armeabi] Install        : libSensoryVoiceJNI.so => libs/armeabi/libSensoryVoiceJNI.so
/opt/android-sdk-linux/ndk-bundle/build/core/build-binary.mk:797: recipe for target 'libs/armeabi/libSensoryVoiceJNI.so' failed
make: Leaving directory '/opt/atlassian/pipelines/agent/build/sensorylib/src/main'
make: /opt/android-sdk-linux/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86/bin/arm-linux-androideabi-strip: Command not found
make: *** [libs/armeabi/libSensoryVoiceJNI.so] Error 127
make: *** Deleting file 'libs/armeabi/libSensoryVoiceJNI.so'
:sensorylib:ndkBuild FAILED

20 actionable tasks: 20 executed
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':sensorylib:ndkBuild'.
> Process 'command '/opt/android-sdk-linux/ndk-bundle/ndk-build'' finished with non-zero exit value 2

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED in 45s

bitbucket-pipelines.yml

image: java:8

pipelines:
  default:
    - step:
        caches:
          - gradle
        script:
          # dependencies
          - apt-get update
          - apt-get -y install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev ccache libgl1-mesa-dev libxml2-utils xsltproc unzip
          # environment vars
          - export SDK_URL="https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip"
          - export ANDROID_HOME="/opt/android-sdk-linux"
          - export ANDROID_NDK_HOME="$ANDROID_HOME/ndk-bundle"
          - export PATH="$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_NDK_HOME:$PATH"
          # download and unzip sdk
          - wget -q $SDK_URL -O android-sdk.zip
          - unzip android-sdk.zip -d $ANDROID_HOME && rm -f android-sdk.zip
          # accept all licences http://stackoverflow.com/questions/38096225/automatically-accept-all-sdk-licences
          - mkdir -p "$ANDROID_HOME/licenses"
          - echo -e "8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_HOME/licenses/android-sdk-license"
          - echo -e "84831b9409646a918e30573bab4c9c91346d8abd" > "$ANDROID_HOME/licenses/android-sdk-preview-license"
          # download ndk
          - sdkmanager "ndk-bundle"
          # build
          - chmod +x gradlew
          - ./gradlew assembleDebug

The ANDROID_NDK_HOME path seems correct as I can ls the folder and it looks correct. The permission on ndk-build also looks correctly set...


Solution

  • The error was that I was missing file in the apt-get install dependencies.

    Here is the working bitbucket-pipelines.yml.

    (I also managed to reduce the overall apt-get dependencies)

    image: java:8
    
    pipelines:
      default:
        - step:
            caches:
              - gradle
            script:
              # dependencies
              - apt-get update && apt-get -y install file build-essential
              # environment vars
              - export SDK_URL="https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip"
              - export ANDROID_HOME="/opt/android-sdk-linux"
              - export ANDROID_NDK_HOME="$ANDROID_HOME/ndk-bundle"
              - export PATH="$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_NDK_HOME:$PATH"
              # download and unzip sdk
              - wget -q $SDK_URL -O android-sdk.zip && unzip android-sdk.zip -d $ANDROID_HOME && rm -f android-sdk.zip
              # accept all licences http://stackoverflow.com/questions/38096225/automatically-accept-all-sdk-licences
              - mkdir -p "$ANDROID_HOME/licenses"
              - echo -e "8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_HOME/licenses/android-sdk-license"
              - echo -e "84831b9409646a918e30573bab4c9c91346d8abd" > "$ANDROID_HOME/licenses/android-sdk-preview-license"
              # download ndk
              - sdkmanager "ndk-bundle"
              # build
              - chmod +x gradlew
              - ./gradlew assembleDebug