无法在Android设备上运行React Native应用程序

问题描述 投票:0回答:1

我正在使用MacBook Pro。我是React Native的新手。.创建项目后,我在iOS设备上运行。正在运行。.同时在Android设备上运行,这意味着我正在收到此错误。.任何人请帮助我解决此错误。.Im将Visual Studio Code IDE用于React Native Application

预先感谢。.

错误详细信息:

[Info] local.properties file doesn't exist. Using Android SDK location from PATH.

[Info] Starting React Native Packager.

info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 864 file(s) to forward-jetify. Using 8 workers...
/bin/sh: adb: command not found
info Launching emulator...

error Failed to launch emulator. Reason: No emulators found as an output of `emulator -list-avds`.
warn Please launch an emulator manually or connect a device. Otherwise app may fail to launch.
info Installing the app...

FAILURE: Build failed with an exception.

* Where:
Settings file '/Users/manikandan/AwesomeProject/android/settings.gradle'

* What went wrong:
Could not compile settings file '/Users/manikandan/AwesomeProject/android/settings.gradle'.
startup failed:
  General error during semantic analysis: Unsupported class file major version 57
android ios react-native androidx mobile-application
1个回答
1
投票

所以您有两个错误要在此处作为错误日志进行修复

  1. local.properties文件不存在。
  2. 无法启动模拟器

local.properties文件问题修复

  1. 使用Android Studio打开您的react native项目android文件夹。
  2. 等待gradle同步并清理项目并使用Android Studio重建它

enter image description here

  • 之后请确保已在Android文件夹中创建了local.properties文件

  • 如果不尝试这些步骤,请手动制作local.properties文件

右键单击项目的顶层并创建新文件'local.properties',然后添加:sdk.dir=/Users/<YourUsername>/Library/Android/sdk

清理并构建

在android上运行react native项目之前,请确保已通过Android Studio中的AVD Manager打开了Android Emulator。>

enter image description here

[如果您尚未创建任何仿真器,请尝试此链接-我已发布有关如何制作Android仿真器的完整答案-

React native failed to launch emulator

编辑:

对于adb错误,您需要在Mac上安装adb驱动程序

请遵循以下步骤

  • 首先使用此命令安装Homebrew
  • /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

或此命令

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

之后使用自制软件安装adb

brew cask install android-platform-tools

尝试重新运行

© www.soinside.com 2019 - 2024. All rights reserved.