![](/img/trans.png)
[英]React Native Failed to build after Installing react-navigation and react-native-gesture-handler
[英]Warning after installing react-navigation in a react native project
我是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警告:配置'compile'已過時,已被'implementation'和'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重新編譯以獲取詳細信息。
我在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"
}
}
任何提示或幫助,我將不勝感激,謝謝。
當您使用react-native link
,它將依賴項添加到build.gradle
文件中。 根據依賴關系的建立方式,它通過compile
或implementation
來添加它。 修復起來很容易,您可以手動將其更改為implementation
因此,您可以在build.gradle
(模塊:app)中進行更改
compile project(':react-native-gesture-handler')
至
implementation project(':react-native-gesture-handler')
您可以在此處詳細了解編譯和實現之間的區別: Gradle中實現和編譯之間有什么區別?
如果react-native-gesture-handler
正在使用或覆蓋已棄用的API,則可以在其回購中標記問題,或者自己通過發出拉取請求來解決。
可以刪除不推薦使用的api,而不會發出警告,導致依賴項無法使用/不穩定。 不推薦使用的api也可能存在缺陷,因此不推薦使用它們,這可能會在將來給您帶來問題。
但是由於在使用react-navigation
時需要使用react-native-gesture-handler
,因此您的工作能力有限。
正如我已經說過的,有幾種選擇:標記問題,使用pull-request自己解決它,在react-native-gesture-handler
被修復或可以使用之前,不要使用它進行react-navigation
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.