简体   繁体   中英

Warning after installing react-navigation in a react native project

I'm new to React Native. I'm learning navigation, so I started with a brand new react native project and followed the steps on the React Navigation website ( 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) Modify the MainActivity.java as the website says for Android

Then, when I run the command react-native run-android , I see the app in my phone as expected but the following message appears:

Configure project :app WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'. It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html

Task :react-native-gesture-handler:compileDebugJavaWithJavac Note: /home/ana/code/react native/seeCompileError/node_modules/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerButtonViewManager.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: Some input files use unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details.

I'm on Linux Mint 19 running the code on my physical Android phone.

My build.gradle file:

// 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")
}

My package.json file:

{
  "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"
  }
}

I would appreciate any hint or help, thank you.

Compile vs Implementation

When you use react-native link it adds the dependency to your build.gradle file; depending on how the dependency has been setup it adds it with compile or implementation . It's easy for you to fix, you can just manually change it to implementation

So in your build.gradle (Module: app) you can change

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

to

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

You can read more about the differences between Compile and Implementation here: What's the difference between implementation and compile in Gradle?


react-native-gesture-handler

If react-native-gesture-handler is using or overriding deprecated APIs you could flag an issue on their repo, or fix it yourself by making a pull request.

Deprecated apis could be removed without warning making the dependency unusable/unstable. The deprecated apis could also have flaws in them, hence the reason they are deprecated, and these may cause you issues in the future.

But as you are require to use react-native-gesture-handler when using react-navigation you are a bit limited in what you can do.

As I have already said there are several options: flag the issue, fix it yourself with a pull-request, don't use it react-navigation until react-native-gesture-handler is fixed, or you can use it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM