Getting the error while starting react-native project

2.9k Views Asked by At

I am beginner in react-native. While building my app for android, I am getting this error

Task :react-native-community_toolbar-android:compileDebugJavaWithJavac FAILED

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.2/userguide/command_line_interface.html#sec:command_line_warnings
39 actionable tasks: 39 executed
Note: /home/kanhaiya/testapp/node_modules/@react-native-community/async-storage/android/src/main/java/com/reactnativecommunity/asyncstorage/AsyncStorageModule.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
/home/kanhaiya/testapp/node_modules/@react-native-community/toolbar-android/android/src/main/java/com/reactnativecommunity/toolbarandroid/ReactToolbar.java:107: error: IconImageInfo is not abstract and does not override abstract method getExtras() in HasImageMetadata
  private static class IconImageInfo implements ImageInfo {
                 ^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':react-native-community_toolbar-android:compileDebugJavaWithJavac'.

Compilation failed; see the compiler error output for details.

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 25s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
Note: /home/kanhaiya/testapp/node_modules/@react-native-community/async-storage/android/src/main/java/com/reactnativecommunity/asyncstorage/AsyncStorageModule.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
/home/kanhaiya/testapp/node_modules/@react-native-community/toolbar-android/android/src/main/java/com/reactnativecommunity/toolbarandroid/ReactToolbar.java:107: error: IconImageInfo is not abstract and does not override abstract method getExtras() in HasImageMetadata
  private static class IconImageInfo implements ImageInfo {
                 ^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':react-native-community_toolbar-android:compileDebugJavaWithJavac'.

Compilation failed; see the compiler error output for details.

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 25s

at makeError (/home/kanhaiya/testapp/node_modules/execa/index.js:174:9)
at /home/kanhaiya/testapp/node_modules/execa/index.js:278:16
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async runOnAllDevices (/home/kanhaiya/testapp/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:109:5)
at async Command.handleAction (/home/kanhaiya/testapp/node_modules/react-native/node_modules/@react-native-community/cli/build/index.js:192:9)

I have already linked react-native-community/toolbar-android in my project using react-native link @react-native-community/toolbar-android. Still it is giving error.

2

There are 2 best solutions below

1
On

after running yarn upgrade @react-native-community/toolbar-android@^0.2.1, the problem is gone.If you are using npm then update the package to the latest.Happy Coding :)

1
On

There are few steps, you can follow up, and see if things are working.

FIRST WAY:

cd Android && cd ./gradlew clean

Please note: ./gradlew <follow_by_script_command> for MacOS. For Windows, just do gradlew <follow_by_script_command>.

If you want to generate a bundle, then do this after the above commands:

./gradlew :app:bundleRelease

SECOND WAY:

Possible reason of this error is your RN version might be different from Android's build.gradle version which android/app/build.gradle. When you create a react-native app probably it create android app like:

implementation "com.facebook.react:react-native:+"

Try inspecting your node_modules folder, look for react-native folder and look for a folder with a number, that numbers are react-native version. For me it's 0.66.4 then update android/app/build.gradle:

implementation "com.facebook.react:react-native:0.66.4"