【问题标题】:Warning after installing react-navigation in a react native project在 react native 项目中安装 react-navigation 后的警告
【发布时间】:2018-12-28 20:48:23
【问题描述】:

我是 React Native 的新手。我正在学习导航,所以我从一个全新的 React Native 项目开始,并按照 React Navigation 网站 (react navigation doc) 上的步骤操作:

1) npm install --save react-navigation

2)npm install --save react-native-gesture-handler (not using expo)

3)react-native link react-native-gesture-handler

4) 修改MainActivity.java,如网站所说的Android

然后,当我运行命令react-native run-android 时,我在手机中看到了预期的应用程序,但出现以下消息:

配置项目:app 警告:配置“编译”已过时,已替换为“实施”和“API”。 它将在 2018 年底被删除。更多信息请参阅:http://d.android.com/r/tools/update-dependency-configurations.html

任务:react-native-gesture-handler:compileDebugJavaWithJavac 注意:/home/ana/code/react native/seeCompileError/node_modules/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerButtonViewManager.java 使用或覆盖已弃用的 API。 注意:使用 -Xlint:deprecation 重新编译以获取详细信息。 注意:某些输入文件使用未经检查或不安全的操作。 注意:重新编译时使用 -Xlint:unchecked for details。

我在 Linux Mint 19 上运行我的物理 Android 手机上的代码。

我的 build.gradle 文件:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "27.0.3"
        minSdkVersion = 16
        compileSdkVersion = 27
        targetSdkVersion = 26
        supportLibVersion = "27.1.1"
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.4'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        google()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
    }
}


task wrapper(type: Wrapper) {
    gradleVersion = '4.4'
    distributionUrl = distributionUrl.replace("bin", "all")
}

我的 package.json 文件:

{
  "name": "seeCompileError",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "jwt-decode": "^2.2.0",
    "react": "16.6.3",
    "react-native": "0.57.8",
    "react-native-gesture-handler": "^1.0.12",
    "react-navigation": "^3.0.9",
    "react-redux": "^6.0.0",
    "redux": "^4.0.1",
    "redux-persist": "^5.10.0",
    "redux-thunk": "^2.3.0"
  },
  "devDependencies": {
    "babel-jest": "23.6.0",
    "jest": "23.6.0",
    "metro-react-native-babel-preset": "0.51.1",
    "react-test-renderer": "16.6.3"
  },
  "jest": {
    "preset": "react-native"
  }
}

如果有任何提示或帮助,我将不胜感激,谢谢。

【问题讨论】:

    标签: android react-native react-navigation


    【解决方案1】:

    编译与实现

    当您使用react-native link 时,它会将依赖项添加到您的build.gradle 文件中;根据依赖项的设置方式,它会使用compileimplementation 添加它。修复很简单,手动改成implementation

    所以在你的build.gradle(Module: app) 你可以改变

    compile project(':react-native-gesture-handler')

    implementation project(':react-native-gesture-handler')

    您可以在此处阅读有关编译和实现之间差异的更多信息:What's the difference between implementation and compile in Gradle?


    react-native-gesture-handler

    如果react-native-gesture-handler 正在使用或覆盖已弃用的 API,您可以在其存储库中标记问题,或通过发出拉取请求自行修复。

    可以在不发出警告的情况下删除不推荐使用的 api,从而使依赖项不可用/不稳定。不推荐使用的 api 也可能存在缺陷,因此不推荐使用它们的原因,这些可能会在将来给您带来问题。

    但是由于您在使用react-navigation 时需要使用react-native-gesture-handler,所以您可以做的有点有限。

    正如我已经说过的,有几种选择:标记问题,通过拉取请求自行修复,在修复react-native-gesture-handler 之前不要使用它react-navigation,或者你可以使用它。

    【讨论】:

    • 谢谢!我从“编译”更改为“实现”,现在警告消失了。
    猜你喜欢
    • 2023-04-03
    • 2022-12-22
    • 2023-03-21
    • 1970-01-01
    • 1970-01-01
    • 2018-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多