React Native 无法从存储库在另一台本地计算机上构建项目-无法安装应用程序,请确保您拥有Android开发环境

gjmwrych  于 2023-02-16  发布在  React
关注(0)|答案(1)|浏览(108)

我有一个react-native项目,它在本地机器上运行良好,我把这个项目推到仓库,但是在另一台机器上构建失败。
所以我从另一台机器上的存储库中克隆了这个项目:
做了npm-install
然后我尝试了X1 M1 N1 X,但它缺少4个“打开Android应用程序”的选择,相反,它只显示两个(没有iOS和Android),所以我尝试了X1 M2 N1 X,但它失败了

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.bat app:installDebug -PreactNativeDevServerPort=8081

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':app:debugCompileClasspath'.
   > Could not find com.facebook.react:react-android:.
     Required by:
         project :app
   > Could not find com.facebook.react:hermes-android:.
     Required by:
         project :app

如果我删除node_modules(Git忽略了它)文件夹,并从第一台本地计算机复制node_modules,那么它可以正常工作,npx react-native start检测ios和Android应用程序可以编译它们。

perk_sample.json的内容:

{
  "name": "nameofapp",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint ."
  },
  "dependencies": {
    "prop-types": "^15.8.1",
    "react": "18.1.0",
    "react-native": "0.70.2"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9",
    "@babel/runtime": "^7.19.0",
    "@react-native-community/eslint-config": "^2.0.0",
    "babel-jest": "^26.6.3",
    "eslint": "^7.32.0",
    "jest": "^26.6.3",
    "metro-react-native-babel-preset": "0.72.3",
    "react-test-renderer": "18.1.0"
  },
  "jest": {
    "preset": "react-native"
  }
}

请问我到添加任何其他信息如果需要

yh2wf1be

yh2wf1be1#

我根据https://stackoverflow.com/a/74436820/7767664中的信息使用npx react-native upgrade升级了RN
现在是

"react": "18.2.0",
"react-native": "0.71.2"

现在npx react-native start工作正常,我可以看到4个选择,它的建设以及(虽然不是从第一次尝试后,所有的操纵,重新运行帮助,但再次尝试清洁建设和工程从第一次尝试)
很高兴我是一个本地开发人员,这只是一个临时项目:)
还有一个问题是,我排除了gradle-wrapper.jar(已添加到gitignore),react-native无法使用gradle自行下载(尽管Android Studio不需要存储库中的此文件,但它可以使用gradle基于gradle-wrapper.properties的URL自行下载):

info Installing the app...
Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain
Caused by: java.lang.ClassNotFoundException: org.gradle.wrapper.GradleWrapperMain

相关问题