【问题标题】:Can't able to run react native application on android device无法在 Android 设备上运行本机应用程序
【发布时间】:2020-03-13 06:09:42
【问题描述】:

我正在使用 MacBook Pro.. 我是 React Native 的新手.. 创建项目后我在 iOS 设备上运行它正在运行.. 同时当我在 Android 设备上运行时意味着我收到此错误.. 任何一个请帮我解决这个错误。我使用 Visual Studio Code IDE 来处理本机应用程序

提前致谢..

错误详情:

[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

【问题讨论】:

  • 您在这里错过了 local.properties 文件。从 android studio 打开项目并清理并构建

标签: android ios react-native androidx mobile-application


【解决方案1】:

所以你有两个错误需要在这里作为你的错误日志来修复

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

local.properties 文件问题修复

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

  • 然后确保您在 android 文件夹中创建了 local.properties 文件

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

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

清理和构建

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

如果你还没有创建任何模拟器,那么试试这个链接 - 我已经发布了关于如何制作 Android 模拟器的完整答案 -

React native failed to launch emulator

编辑:

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

按照这些步骤操作

/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

尝试重新运行

【讨论】:

  • [错误] 无法在 Android 中运行应用程序(错误代码 104)堆栈:错误:无法在 Android 中运行应用程序(错误代码 104):执行命令“adb devices”时出错:命令失败: adb devices /bin/sh: adb: command not found
  • 您需要安装 adb devices ... 查看我的更新答案
  • [错误] 无法在 Android 中运行应用程序(错误代码 104) 堆栈:错误:无法在 Android 中运行应用程序(错误代码 104):未知错误:并非所有成功模式都匹配。这意味着“react-native run-android”命令失败。请检查 View -> Toggle Output -> React Native,View -> Toggle Output -> React Native:运行 android 输出窗口。 (错误代码 712)
  • 当我通过 Android Studio 应用程序运行时正在运行.. 但是当我通过 Visual Studio 代码运行时,我现在遇到了上述错误..
猜你喜欢
  • 1970-01-01
  • 2020-07-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-28
  • 2015-05-23
相关资源
最近更新 更多