Reputation: 14862
I've created a React-Native project with the following command :
react-native init samplerouting
Then I enabled navigation with the following steps(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-Add the following two lines to dependencies
section in android/app/build.gradle
implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha02'
4-I Modified the MainActivity.java
as below
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-Then add the following at the top of my entry file (index.js)
import 'react-native-gesture-handler';
Finish, I want to run my project only on android device, That's why I reject the following steps:
cd ios
pod install
cd ..
Now, When I run my project
react-native start
react-native run-android
I get the following error
Task :react-native-screens:javaPreCompileDebug FAILED
Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0. Use '--warning-mode all' to show the individual deprecation warnings.
NOTE:I tried the following command but it does not work
cd android && gradlew clean
my 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"
}
}
Upvotes: 1
Views: 5298
Reputation: 14862
This error is related to Gradle
.
That's why I updated my SDK
, so It worked perfectly.
Needless to say :
In Environment-variable
We have to add the following 3 variables :
1- ANDROID_HOME :(Your SDK path) J:\ReactNative\AndroidSDK\Android\Sdk
2- JAVA_HOME :(Your JDK path) C:\Program Files\Java\jdk1.8.0_231
3- platform-tools :(Your PLATFORM-TOOLS path) J:\ReactNative\AndroidSDK\Android\Sdk\platform-tools
NOTE: The path above is on my computer, provide your own path
Upvotes: 2