克隆并运行从GitHub反应本机项目

时间:2016-09-20 08:35:24

标签: reactjs react-native react-router

我正在尝试在手机中构建并运行本机应用程序。我尝试使用Getting Started并且工作正常。我执行以下操作

  1. cd AwesomeProject
  2. react-native start
  3. 在终端
  4. 中打开新标签页
  5. curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"

  6. react-native run-android

  7. 它在我的Android手机中运行。

    现在我正在尝试运行project from GitHub,我执行了以下操作

    1. git clone https://github.com/h87kg/NavigatorDemo.git
    2. cd NavigatorDemo
    3. react-native start
    4. 我收到Command 'start' unrecognized. Did you mean to run this inside a react-native project?错误。我该怎么做才能运行这个项目?任何帮助表示赞赏。提前谢谢。

      更新

      安装依赖项npm install后,我可以运行服务器。 现在,当我尝试运行react-native run-android时,我收到以下错误

      JS server already running.
      Building and installing the app on the device (cd android && ./gradlew installDebug)...
      Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain
      Could not install the app on the device, see the error above.
      

5 个答案:

答案 0 :(得分:8)

解决方案感觉就像一个黑客..问题是android文件夹中的 gradlew 文件不再可执行,因为你从git repo克隆了它。

基本上,当你执行react-native run-android时,它会做很多事情,包括为你运行命令,例如cd android && ./gradlew installDebug。就在那里,它试图执行gradlew,但不能,导致文件不可执行。这就是你得到那个错误的原因。

只需cd进入 android 文件夹,然后执行chmod +x gradlew。这应该修复它,而不是复制文件..

答案 1 :(得分:6)

您安装了节点模块吗?试试HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(); if (BuildConfig.DEBUG) loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS); new OkHttpClient.Builder() .connectTimeout(60, TimeUnit.SECONDS) .readTimeout(60, TimeUnit.SECONDS) .writeTimeout(60, TimeUnit.SECONDS) .addInterceptor(new CatalogInterceptor(context)) .addInterceptor(new OAuthInterceptor(context)) .authenticator(new BearerTokenAuthenticator(context)) .addInterceptor(loggingInterceptor)//at the end .build();

  1. npm install
  2. git clone https://github.com/h87kg/NavigatorDemo.git
  3. cd NavigatorDemo
  4. npm install

答案 2 :(得分:0)

我找到了解决方案,这就是我如何使其工作并与面临同样问题的其他人分享

  1. assets
  2. 中创建名为android/app/src/main/的文件夹
  3. 从我现有的工作项目gradle {/ 1}} android/内复制AwesomeProject个文件夹
  4. (cd android && ./gradlew installDebug)
  5. curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"
  6. react-native run-android
  7. 这些是我遵循的确切步骤,希望它有所帮助。

答案 3 :(得分:0)

  1. 从我现有的工作项目根目录复制android /中的gradle文件夹
  2. 转到android目录并运行以下命令:./gradlew installDebug
  3. 现在将gradle文件夹复制回原始位置。

这是对我有用的解决方案。不要忘记在此过程中关闭节点服务器。

答案 4 :(得分:0)

npm install react-native-fs --save --legacy-peer-deps

这将解决您的问题