记录一下 React Native 项目 Android NDK 配置。
今天又是折腾开发环境的一天呢。
放假了开开心心的回到公司上班的第一天,拉一下项目先看看小伙伴们最近玩了啥,听说弄了一套 breeze 架构贼拉香。然后当我一套猛如虎的操作下来之后没跑起来,好家伙。刚开始嘛报错说我 Java 环境不行,于是乎我想到几个星期前整 QQ 机器人我好像是搞了一下 JAVA_HOME 环境变量而且还装了一个 openjdk 11,好嘛先整回来。
然后还遇到一些小问题就不说了,记录一下我运行 Android 的时候遇到的 NDK 没有的问题吧。
报错如下:
> Task :app:stripDebugDebugSymbols FAILED
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.7/userguide/command_line_interface.html#sec:command_line_warnings
884 actionable tasks: 5 executed, 879 up-to-date
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:stripDebugDebugSymbols'.
> NDK at /Android/sdk/ndk-bundle did not have a source.properties file
* Try:
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.
* Get more help at https://help.gradle.org
BUILD FAILED in 9s
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:stripDebugDebugSymbols'.
> NDK at /Android/sdk/ndk-bundle did not have a source.properties file
* Try:
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.
* Get more help at https://help.gradle.org
BUILD FAILED in 9s
从上面的输出中能看的到没有 ndk,我心想这不简简单单我用 Android Studio 下载一个不就好了?于是乎
打开 Android Studio 设置页面搜索 SDK,点击 SDK Tools,选中 NDK(Side by side)点击 Apply 就开始下载了(我这里贴的是下载好的图…)
下载好之后还是找不到呐?我们给这里下载之后路径是在你配置的 Android SDk Location 路径下面的 ndk 文件夹中
好了,我们得到这个路径之后就将它设置到项目的 local.properties 文件中的 ndk.dir 上
是不是觉得简简单单,然而它又给我报了个错
> Task :app:stripDebugDebugSymbols FAILED
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.7/userguide/command_line_interface.html#sec:command_line_warnings
884 actionable tasks: 5 executed, 879 up-to-date
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:stripDebugDebugSymbols'.
> NDK from ndk.dir at /Volumes/tzmaxData/Android/sdk/ndk/22.1.7171670 had version [22.1.7171670] which disagrees with android.ndkVersion [20.1.5948944]
* Try:
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.
* Get more help at https://help.gradle.org
BUILD FAILED in 9s
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:stripDebugDebugSymbols'.
> NDK from ndk.dir at /Volumes/tzmaxData/Android/sdk/ndk/22.1.7171670 had version [22.1.7171670] which disagrees with android.ndkVersion [20.1.5948944]
* Try:
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.
* Get more help at https://help.gradle.org
BUILD FAILED in 9s
什么玩意?版本不行?我突然发现事情好像没有这么简单,当我看到 build.gradle 中的 ndkVersion 我好像明白了什么…
要不直接改成我下载好的版本?不过这个项目也不是我一个人写,其他人到时候整崩了…所以嘛我下载一个旧版本吧,那么问题来了,怎么下载 NDK 旧版本呢?我在官网找了半天没找到下载链接,于是我又回到了 Android Studio SDK 下载页面,当我点开 Show Package Details 之后发现了不一样的世界,好家伙居然藏在这里了,每个 Android Studio 都有一个默认下载 NDK 版本
选中想要的版本点击 Apply 下载就好了。
最后改一下 local.properties 文件中 ndk 的路径上的版本号就好了
然后重新 run 一下就成功跑起来啦。