首页 > 解决方案 > React Navigation 5.x 中的任务:react-native-screens:javaPreCompileDebug 错误

问题描述

我使用以下命令创建了一个 React-Native 项目:

react-native init samplerouting

然后我通过以下步骤启用导航(基于其文档):

1-

npm install @react-navigation/native

2-

npm install 
react-native-reanimated 
react-native-gesture-handler 
react-native-screens 
react-native-safe-area-context 
@react-native-community/masked-view

3-将以下两行添加到dependencies部分android/app/build.gradle

implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha02'

4-I 修改MainActivity.java如下

package com.samplerouting;

import com.facebook.react.ReactActivity;
import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.ReactRootView;
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;

public class MainActivity extends ReactActivity {

  /**
   * Returns the name of the main component registered from JavaScript. This is used to schedule
   * rendering of the component.
   */
  @Override
  protected String getMainComponentName() {
    return "samplerouting";
  }

  @Override
  protected ReactActivityDelegate createReactActivityDelegate() {
    return new ReactActivityDelegate(this, getMainComponentName()) {
      @Override
      protected ReactRootView createRootView() {
        return new RNGestureHandlerEnabledRootView(MainActivity.this);
      }
    };
  }

}

5-然后在我的入口文件(index.js)的顶部添加以下内容

import 'react-native-gesture-handler';

完成,我只想在 android 设备上运行我的项目,这就是我拒绝以下步骤的原因:

cd ios
pod install
cd ..

现在,当我运行我的项目时

react-native start
react-native run-android 

我收到以下错误

任务:react-native-screens:javaPreCompileDebug FAILED

此版本中使用了已弃用的 Gradle 功能,使其与 Gradle 6.0 不兼容。使用“--warning-mode all”显示各个弃用警告。

注意:我尝试了以下命令,但它不起作用

cd android && gradlew clean

我的 package.json:

{
  "name": "samplerouting",
  "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": {
    "@react-native-community/masked-view": "^0.1.6",
    "@react-navigation/native": "^5.0.0",
    "react": "16.9.0",
    "react-native": "0.61.5",
    "react-native-gesture-handler": "^1.5.6",
    "react-native-reanimated": "^1.7.0",
    "react-native-safe-area-context": "^0.7.2",
    "react-native-screens": "^2.0.0-beta.2"
  },
  "devDependencies": {
    "@babel/core": "7.8.4",
    "@babel/runtime": "7.8.4",
    "@react-native-community/eslint-config": "0.0.5",
    "babel-jest": "24.9.0",
    "eslint": "6.8.0",
    "jest": "24.9.0",
    "metro-react-native-babel-preset": "0.56.4",
    "react-test-renderer": "16.9.0"
  },
  "jest": {
    "preset": "react-native"
  }
}

标签: react-nativereact-native-androidreact-navigationreact-native-navigation

解决方案


此错误与Gradle.

这就是为什么我更新了我的SDK,所以它工作得很好。

不用说 :

Environment-variable我们必须添加以下 3 个变量:

1- ANDROID_HOME :(你的 SDK 路径) J:\ReactNative\AndroidSDK\Android\Sdk

2- JAVA_HOME :(您的 JDK 路径) C:\Program Files\Java\jdk1.8.0_231

3-平台工具:(您的平台工具路径)J:\ReactNative\AndroidSDK\Android\Sdk\platform-tools

注意: 以上路径在我的电脑上,请提供您自己的路径


推荐阅读