Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native - Async Storage error when run react-native run-android

I'm trying to run react-native run-android but receive the following error:

Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
D:\Work\CS\Wms-Mobile\CS-WmsMobile\node_modules\@react-native-community\async-storage\android\src\main\java\com\reactnativecommunity\asyncstorage\AsyncStorageModule.java:26: error: package com.facebook.react.module.annotations does not exist
import com.facebook.react.module.annotations.ReactModule;
                                            ^
D:\Work\CS\Wms-Mobile\CS-WmsMobile\node_modules\@react-native-community\async-storage\android\src\main\java\com\reactnativecommunity\asyncstorage\AsyncStorageModule.java:34: error: cannot find symbol     
@ReactModule(name = AsyncStorageModule.NAME)
 ^
  symbol: class ReactModule
2 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-community_async-storage: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 1m 16s

    at checkExecSyncError (child_process.js:621:11)
    at execFileSync (child_process.js:639:15)
    at runOnAllDevices (D:\Work\CS\Wms-Mobile\CS-WmsMobile\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:94:39)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

Things I've tried:

  • Reinstall node_modules
  • cd ./android and then ./gradlew clean

But none of them seems to work. I am glad to hear your suggestion, thank you in advance!

My version:

react-native-cli: 2.0.1

react-native: 0.61.4

android gradle plugin: 3.5.3

gradle: 5.4.1

like image 540
hrtlkr29 Avatar asked Mar 03 '20 15:03

hrtlkr29


People also ask

What can I use instead of async storage React Native?

React Native AsyncStorage is a simple, unencrypted, asynchronous, persistent, storage system which stores the data globally in the app. It store data in the form of a key-value pair. React Native recommended to use abstraction on top of AsyncStorage instead of AsyncStorage directly as it operates globally.

Is React Native async storage deprecated?

Deprecated. Use one of the community packages instead. AsyncStorage is an unencrypted, asynchronous, persistent, key-value storage system that is global to the app. It should be used instead of LocalStorage.

How do I link React Native to async storage?

Project linking​Right click on the Libraries folder and select Add files to "yourProjectName" . Add RNCAsyncStorage. xcodeproj (located at node_modules/@react-native-async-storage/async-storage/ios ) to your project Libraries. Go to Build Phases -> Link Binary with Libraries and add: libRNCAsyncStorage.

How do I get async storage value in React Native?

Open the App. js file and start by importing the following components. import React, {useState, useEffect} from 'react'; import { StyleSheet, View, Text, TextInput, TouchableOpacity, } from 'react-native'; import AsyncStorage from '@react-native-community/async-storage'; Next, define a variable name STORAGE_KEY .


2 Answers

Try with below command

react-native link @react-native-community/async-storage

feel free for doubts

like image 86
SRanuluge Avatar answered Oct 03 '22 08:10

SRanuluge


Try the following solutions.

  1. Uninstall Node Modules
  2. Clean Gradle (cd android && gradlew clean)
  3. now install back your modules (yarn install)

if this does not help try upgrading your packages.

yarn upgrade --pattern react-native

like image 40
Kashan Haider Avatar answered Oct 03 '22 08:10

Kashan Haider