Solvedndk React Native apps fail to build since NDK update to r17 (due to missing mipsel-linux-android-4.9 toolchain files)

Description

Android React Native apps have not been able to successfully build since we updated NDK to r17. The build error shows this:

> A problem occurred starting process 'command '/Users/myuser/Library/Android/sdk/ndk-bundle/toolchains/mipsel-linux-android-4.9/prebuilt/darwin-x86_64/bin/mipsel-linux-android-strip''

To work around this, our team had to manually replace the bare NDK r17 ~/Library/Android/sdk/ndk-bundle/toolchains/mips64el-linux-android-4.9/ and ~/Library/Android/sdk/ndk-bundle/toolchains/mipsel-linux-android-4.9/ directories with those of the old NDK r16. Almost all files that were once in these 2 directories bacvk in NDK r16 are completely gone in the new NDK r17.

Steps to reproduce:

  1. Create a new React Native app called TestApp using the following commands on macOS:
brew install node
brew install watchman
npm install -g react-native-cli
react-native init TestApp

(Use this link if issues arise with Android dev environment: https://facebook.github.io/react-native/docs/getting-started.html)
2. Open an Android emulator and build the Android app using react-native run-android
3. Observe the following build error:

:app:transformNative_libsWithStripDebugSymbolForDebug FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformNative_libsWithStripDebugSymbolForDebug'.
> A problem occurred starting process 'command '/Users/myuser/Library/Android/sdk/ndk-bundle/toolchains/mipsel-linux-android-4.9/prebuilt/darwin-x86_64/bin/mipsel-linux-android-strip''

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

BUILD FAILED

Total time: 15.318 secs
22 Answers

✔️Accepted Answer

The problem is that a given gradle plugin does not support every version of the NDK and the NDK is being updated without the gradle plugin. Studio absolutely needs to do a better job of helping users not point the gun at their foot, but fundamentally the configuration causing this bug needs to be avoided.

I've summarized @alexcohn's comments above into a couple of bugs for Studio:

http://b/80431718 Studio pins gradle plugin revisions but not NDK revisions, even though they are related
http://b/80431288 Studio does not warn users when their NDK version is incompatible with their gradle plugin

It sounds like these two issues are at the crux of the problem. Migrating to newer build tools during a project's development is hard, and Studio/gradle are making it hard to avoid that process.

All that said, the 3.1 build tools are now in the stable channel and do not have this problem, so the fix for this is to update to the latest version of the build tools. If it's not a good time to do that for your project, you have two options:

The first option is to apply this workaround from Stack Overflow:

// In build.gradle
packagingOptions{
    doNotStrip '*/mips/*.so'
    doNotStrip '*/mips64/*.so'
}

The second is to continue using NDK r16b with the 3.0 build tools. Download the previous version of the NDK from https://developer.android.com/ndk/downloads/, extract it somewhere, and change the ndk.dir variable in local.properties file to point there rather than into the SDK install path.

Other Answers:

Very crude quick-fix

mkdir ~/Library/Android/sdk/ndk-bundle/toolchains/mips64el-linux-android-4.9/prebuilt/darwin-x86_64/bin
touch ~/Library/Android/sdk/ndk-bundle/toolchains/mips64el-linux-android-4.9/prebuilt/darwin-x86_64/bin/mips64el-linux-android-strip

I can reproduce a problem with Studio 3.0.1 and NDK r17:

  • Create a new Android project.
  • Add this line to app's dependencies: implementation 'com.github.barteksc:pdfium-android:1.8.2' [Link]. The https://github.com/wonday/react-native-pdf project indirectly uses pdfium-android, and pdfium-android-1.8.2.aar has solibs for armeabi and mips.)

gradlew assembleDebug fails with:

* What went wrong:
Execution failed for task ':app:transformNativeLibsWithStripDebugSymbolForDebug'.
> A problem occurred starting process 'command '/usr/local/google/home/rprichard/studio-3.0/android-sdk/ndk-bundle/toolchains/mips64el-linux-android-4.9/prebuilt/linux-x86_64/bin/mips64el-linux-android-strip''

Notes:

  • abiFilters doesn't matter.
  • If I uninstall the NDK, the build quietly succeeds (with plugin 3.0.1 or plugin 3.1.2).
  • With plugin version 3.1.2, if NDK r17 is installed, then the build succeeds with warnings:
    > Task :app:transformNativeLibsWithStripDebugSymbolForDebug 
    Unable to strip library '/usr/local/google/home/rprichard/PdfTestApp/app/build/intermediates/transforms/mergeJniLibs/debug/0/lib/armeabi/libjniPdfium.so' due to missing strip tool for ABI 'ARMEABI'. Packaging it as is.
    Unable to strip library '/usr/local/google/home/rprichard/PdfTestApp/app/build/intermediates/transforms/mergeJniLibs/debug/0/lib/armeabi/libmodpdfium.so' due to missing strip tool for ABI 'ARMEABI'. Packaging it as is.
    Unable to strip library '/usr/local/google/home/rprichard/PdfTestApp/app/build/intermediates/transforms/mergeJniLibs/debug/0/lib/armeabi/libmodpng.so' due to missing strip tool for ABI 'ARMEABI'. Packaging it as is.
    Unable to strip library '/usr/local/google/home/rprichard/PdfTestApp/app/build/intermediates/transforms/mergeJniLibs/debug/0/lib/armeabi/libmodft2.so' due to missing strip tool for ABI 'ARMEABI'. Packaging it as is.
    Unable to strip library '/usr/local/google/home/rprichard/PdfTestApp/app/build/intermediates/transforms/mergeJniLibs/debug/0/lib/mips/libjniPdfium.so' due to missing strip tool for ABI 'MIPS'. Packaging it as is.
    Unable to strip library '/usr/local/google/home/rprichard/PdfTestApp/app/build/intermediates/transforms/mergeJniLibs/debug/0/lib/mips/libmodpdfium.so' due to missing strip tool for ABI 'MIPS'. Packaging it as is.
    Unable to strip library '/usr/local/google/home/rprichard/PdfTestApp/app/build/intermediates/transforms/mergeJniLibs/debug/0/lib/mips/libmodpng.so' due to missing strip tool for ABI 'MIPS'. Packaging it as is.
    Unable to strip library '/usr/local/google/home/rprichard/PdfTestApp/app/build/intermediates/transforms/mergeJniLibs/debug/0/lib/mips/libmodft2.so' due to missing strip tool for ABI 'MIPS'. Packaging it as is.
    
    
    BUILD SUCCESSFUL in 5s