Async-storage: E/ReactNativeJS: Error: [@RNC/AsyncStorage]: NativeModule: AsyncStorage is null.

Created on 3 Jan 2020  路  18Comments  路  Source: react-native-async-storage/async-storage

Current behavior

IOS is correctly working but android is not working

Environment

  • Async Storage version: "@react-native-community/async-storage": "^1.7.1",

  • React-Native version: "react-native": "0.61.5",

  • Platform tested: Android

Most helpful comment

+1 Except iOS is failing, have not tried Android yet.

All 18 comments

+1 Except iOS is failing, have not tried Android yet.

+1 Android.

AsyncStorage 1.7,1
ReactNative 0.61.4

I'd need more details - what's not working?

When starting the application the error E / ReactNativeJS: Error: [@ RNC / AsyncStorage]: NativeModule: AsyncStorage is null.

@diegoaraujolima This error comes from the not properly installed native module. RN 60+ is using autolinking, so you don't have to do nothing more, but follow the Autolinking setup. Otherwise, you need to use react-native link to install it.

My version is 0.61.4 and I didn't use the link and the problem occurs. Then I tried to rotate the link, but the error still remains. Then I tried to do the operations manually (change MainApplication, dependencies and etc) and the error keeps occurring.

But I am not migrating from version. I just installed the latest version.

I also encountered this problem

I met the same issue

IOS is correctly working but android is not working

  • Async Storage version: "@react-native-community/async-storage": "^1.7.1",

  • React-Native version: "react-native": "0.57.8",

  • Platform tested: Android

If you upgraded from < 0.60 version, you need to unlink all your dependencies and then relay just on cli feature. Please read the docs to get more info.

If you started with version 0.60+, then autolinking should kick in. no react-native link is required. You just need to make sure that the setup you have follows the proper setup. Again, here are the docs for autolinking.

If you're below version 0.60, then you have to install the dependency manually or through react-native link name-of-the-library. We have guides for manual linking here

I had the same problem, looks like auto-linking is broken on android:

Environment

  • Async Storage version: "@react-native-community/async-storage": "^1.7.1",
  • React-Native version: "react-native": "0.61.5",
  • Platform tested: Android

Fix

In order to fix it I had to manually modify my Applications.kt file. Add the below import:

              import com.reactnativecommunity.asyncstorage.AsyncStoragePackage

Then make sure you add the packages to the getPackages() return list:

              override fun getPackages(): List<ReactPackage> =
                           listOf(
                                      MainReactPackage(),
                                      ....
                                      AsyncStoragePackage()
                           )

The fix should be similar if you are using java instead of kotlin.

@StoyanD AFAIK, auto-linking does not work with Kotlin (yet?)
cc @thymikee

Should work just fine, if you import PackageList correctly, @dratwas did some work on that. Code from @StoyanD looks like pre-autolinking, see https://github.com/facebook/react-native/blob/0.61-stable/template/android/app/src/main/java/com/helloworld/MainApplication.java#L25 for reference.

Same issue. Latest Expo, running on Android.

Steps to Reproduce

Start with a clean blank-template project.

yarn add @react-native-community/async-storage

Add some code:

AsyncStorage = require('@react-native-community/async-storage')

Start the project with yarn start, load the project with Expo on Android.

Instant crash.

The above references to Java code are not helpful, I'm not writing any Java/Kotlin at all in this pipeline.

@jessegranger Expo does not support custom native modules, so you cannot add Async Storage to.

Thanks for your answer. I did expo eject and then react-native link ... and it worked in Android emulator.

Closing it down - for any other cases, please open new issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

muhammadn picture muhammadn  路  58Comments

Waqas-Jani picture Waqas-Jani  路  28Comments

rogueturnip picture rogueturnip  路  27Comments

josmithua picture josmithua  路  20Comments

sumanthyedoti picture sumanthyedoti  路  25Comments