我用以下命令创建了一个React-Native项目:
react-native init samplerouting
然后我通过以下步骤启用了导航(based on its documentation):
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失败
此构建中使用了不推荐使用的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-Native项目:react-native init samplerouting然后,我按照以下步骤启用了导航(基于其文档):1- npm install @ ...
此错误与Gradle
有关。