Android NDK编译错误解决

0x01 问题描述

现象: 将ndk版本升级到 17.0.4754217编译报错

1
2
3
4
5
6
* What went wrong:
Execution failed for task ':app+stub:transformNativeLibsWithStripDebugSymbolForRelease'.
> A problem occurred starting process 'command '/Users/Ivonhoe/Library/Android/sdk/ndk-bundle/toolchains/mips64el-linux-android-4.9/prebuilt/darwin-x86_64/bin/mips64el-linux-android-strip''

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
1
2
3
4
5
6
Caused by: java.io.IOException: Cannot run program "/Users/Ivonhoe/Library/Android/sdk/ndk-bundle/toolchains/mips64el-linux-android-4.9/prebuilt/darwin-x86_64/bin/mips64el-linux-android-strip" (in directory "/Users/Ivonhoe/Workspace/keyaccount-repo/app+stub"): error=2, No such file or directory
at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:25)
... 4 more
Caused by: java.io.IOException: error=2, No such file or directory
... 5 more

原因:

升级android ndk版本到17时未同时升级gradle编译工具到3.0.0以上,低版本的编译工具会执行mips64的脚本。而mips64的脚本在ndk17上已经被删除了!

1
2
3
This mipsel-linux-android-4.9 directory exists to make the NDK compatible with the Android
SDK's Gradle plugin, version 3.0.1 and earlier, which expects the NDK
to have a MIPS toolchain directory.

解决方案:
一种解决办法是同时升级gradle编译工具的版本。但是因为项目的原因,无法使用最新版本的gradle编译工具,只能使用2.3.0版本的编译工具,所以使用一个绕过问题的方法,
/Users/Ivonhoe/Library/Android/sdk/ndk-bundle/toolchains/mips64el-linux-android-4.9/prebuilt/darwin-x86_64/bin/目录创建一个mips64el-linux-android-strip的空文件。记得使用chmod 命令修改空文件的执行权限。

0x03 参考文档:

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

转载请标明出处病已blog https://ivonhoe.github.io/