【问题标题】:ReactNative can't locate Android SDKReactNative 找不到 Android SDK
【发布时间】:2020-10-29 00:12:12
【问题描述】:

我已按照官方网站上的 ReactNative 安装说明进行操作,但无法在任何设备上构建和安装我的项目。问题似乎是 ReactNative 似乎无法找到我的 Android SDK。

如果我在 Android Studio 中打开项目的 Android 特定部分,我可以启动应用程序,因此 SDK 已正确安装。也许相关的还有我正在同时开发一个 Flutter 应用程序,而 Flutter 在定位 Android SDK 时没有问题。

运行nix react-native doctor 给了我以下信息:

Common
 ✓ Node.js
 ✓ yarn
 ✓ Watchman - Used for watching changes in the filesystem when in development mode

Android
 ✓ JDK
 ✓ Android Studio - Required for building and installing your app on Android
 ✖ Android SDK - Required for building and installing your app on Android
   - Versions found: N/A
   - Version supported: 29.0.2
 ✓ ANDROID_HOME

iOS
 ✓ Xcode - Required for building and installing your app on iOS
 ✓ CocoaPods - Required for installing iOS dependencies
 ✓ ios-deploy - Required for installing your app on a physical device with the CLI

Errors:   1
Warnings: 0

Attempting to fix 1 issue...

Android
 ✖ Android SDK
   Read more about how to download Android SDK at https://reactnative.dev/docs/getting-started

但是,尝试“修复”该问题只会将我带到入门页面,正如我之前提到的,我已经完全按照描述完成了安装。我什至尝试从我的计算机中删除所有与 Android 相关的内容,然后从头开始重新安装。

Runnit nix react-native info 给了我以下信息:

info Fetching system and libraries information...
System:
    OS: macOS 10.15.4
    CPU: (8) x64 Intel(R) Core(TM) i7-3720QM CPU @ 2.60GHz
    Memory: 1.97 GB / 16.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 12.16.3 - /usr/local/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 6.14.4 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.9.3 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 13.5, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
    Android SDK: Not Found
  IDEs:
    Android Studio: 4.0 AI-193.6911.18.40.6514223
    Xcode: 11.5/11E608c - /usr/bin/xcodebuild
  Languages:
    Java: 14.0.1 - /usr/bin/javac
    Python: 2.7.16 - /usr/bin/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.11.0 => 16.11.0
    react-native: 0.62.2 => 0.62.2
  npmGlobalPackages:
    *react-native*: Not Found

这进一步“证明”了 ReactNative 找不到 Android SDK。

到目前为止我所做的尝试:

在内容中添加local.properties

sdk.dir=/Users/[username]/Library/Android/sdk

(是的,该文件夹存在且正确,与 Android Studio 中的设置相同)

.zshrc 更新为:

export ANDROID_HOME=$HOME/Library/Android/sdk
export ANDROID_SDK_ROOT=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools

在那个 sdk 文件夹(在平台中)我有 android-28android-29android-30。 我也(当然)在这里查看了有相同问题的人的一些帖子,但这两个修复中的一个几乎总是可以解决问题,但它对我不起作用。还有什么要测试的?

更新: 我还可以在运行npx react-native run-android 时添加它并得到错误:Task 'installDebug' not found in project ':app'.。不过这个问题也应该用properties.local解决,对我不起作用。

【问题讨论】:

  • 你找到解决办法了吗?
  • 嗨@Sebastian,你有没有找到任何称呼,我遇到了同样的错误,请帮忙。

标签: android react-native


【解决方案1】:

我发现在 Android Studio 中安装“Android SDK 命令行工具”插件可以让医生识别更新的 android sdk 实例!

但它与 react-native 不兼容,我们需要 29.0.2 的,所以请务必检查“显示包详细信息”并在下载之前选择正确的版本。

之后我的npx react-native doctor 输出:

michel@michel-ubuntu:~/development/projects/Project$ rn doctor
Common
 ✓ Node.js
 ✓ npm

Android
 ✓ JDK
 ✓ Android Studio - Required for building and installing your app on Android
 ✓ Android SDK - Required for building and installing your app on Android
 ✓ ANDROID_HOME

Errors:   0
Warnings: 0
Common
 ✓ Node.js
 ✓ npm

Android
 ✓ JDK
 ✓ Android Studio - Required for building and installing your app on Android
 ✓ Android SDK - Required for building and installing your app on Android
 ✓ ANDROID_HOME

Errors:   0
Warnings: 0

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-16
    • 2023-03-31
    • 2019-09-15
    • 2021-10-06
    • 2011-08-20
    相关资源
    最近更新 更多