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

Created on 9 Oct 2020  ·  9Comments  ·  Source: react-native-async-storage/async-storage

Current behavior

Find the below logs found when the app launches

2020-10-09 15:39:08.434 14910-14976/? E/ReactNativeJS: Error: [@RNC/AsyncStorage]: NativeModule: AsyncStorage is null.

To fix this issue try these steps:

  • Run `react-native link @react-native-community/async-storage` in the project root.

  • Rebuild and restart the app.

  • Run the packager with `--reset-cache` flag.

  • If you are using CocoaPods on iOS, run `pod install` in the `ios` directory and then rebuild and re-run the app.

  • If this happens while testing with Jest, check out docs how to integrate AsyncStorage with it: https://react-native-community.github.io/async-storage/docs/advanced/jest

If none of these fix the issue, please open an issue on the Github repository: https://github.com/react-native-community/react-native-async-storage/issues

2020-10-09 15:39:08.460 14910-14976/? I/ReactNativeJS: Running "main" with {"initialProps":{"exp":{"lastErrors":[{"isFatal":true,"errorMessage":"Error: [@RNC/AsyncStorage]: NativeModule: AsyncStorage is null.\n\nTo fix this issue try these steps:\n\n • Run react-native link @react-native-community/async-storage in the project root.\n\n • Rebuild and restart the app.\n\n • Run the packager with --reset-cache flag.\n\n • If you are using CocoaPo","exceptionId":-322460846}],"initialUri":"https://expo.io:443/@swap4949/ShorelineCloudV2","manifest":{"isVerified":true,"version":"0.0.1","id":"@swap4949/ShorelineCloudV2","bundledAssets":["asset_516c07e9f2447fd9ae12b7aafb2abb0b.png","asset_12300732a817be0846b361b9b27a731b.png","asset_f4c4699a7807b76fb02760b0d13ee9a9.png","asset_f528602e0642d8224e1b68e630747a95.png","asset_b5f611f7f153660b49774e1225af9284.png","asset_20395fb867add3018b063d31972db21d.png","asset_9b81a625bcf4c426a6ce6d6c557d4f8f.png","asset_c2efb40bcd46493e8a5ff2ddb0449435.png","asset_41e8dead03fb979ecc23b8dfb0fef627.ttf","asset_342ba3d8ac29ac8c38d7cef8efbf2dc9.ttf"],"android":{"versionCode":1,"package":"com.shoreline.shorelinecloud"},"bundleUrl":"https://d1wp6m56sqw74a.cloudfront.net/%40swap4949%2FShorelineCloudV2%2F0.0.1%2F23d514928554c5d64b8ba61d7965279c-38.0.0-android.js","revisionId":"0.0.1-r.LQspceznY","sdkVersion":"38.0.0","platforms":["ios","android","web"],"releaseChannel":"default","hostUri":"exp.host/@swap4949/ShorelineCloudV2","commitTime":"2020-10-09T09:18:20.237Z","dependencies":["@react-native-community/async-storage","@slcloud/constants","@slcloud/locale","@slcloud/models","@slcloud/shared","amazon-cognito-identity-js","aws-amplify","aws-amplify-react-native","expo","expo-splash-screen","expo-status-bar","expo-updates","native-base","react","react-dom","react-native","react-native-gesture-handler","react-native-loading-spinner-overlay","react-native-material-dropdown","react-native-reanimated","react-native-screens","react-native-toast-message","react-native-unimodules","react-native-web","react-redux","redux","redux-logger","redux-saga","redux-saga-effects","redux-thunk"],"locales":{},"releaseId":"be49b3c1-a9b4-492e-a1e9-5ad8343ef497","slug":"ShorelineCloudV2","name":"ShorelineCloudV2","ios":{"buildNumber":"0.0.1","bundleIdentifier":"com.shoreline.shorelinecloud"},"loadedFromCache":false,"publishedTime":"2020-10-09T09:18:20.149Z"},"shell":true}},"rootTag":1}
2020-10-09 15:39:08.461 14910-14910/? D/AndroidRuntime: Shutting down VM
2020-10-09 15:39:08.462 14910-14910/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.shoreline.shorelinecloud, PID: 14910
java.lang.RuntimeException: Expo encountered a fatal error: Error: [@RNC/AsyncStorage]: NativeModule: AsyncStorage is null.

To fix this issue try these steps:

  • Run `react-native link @react-native-community/async-storage` in the project root.

  • Rebuild and restart the app.

  • Run the packager with `--reset-cache` flag.

  • If you are using CocoaPo
    at host.exp.exponent.experience.f.o(BaseExperienceActivity.java:7)
    at host.exp.exponent.experience.a.run(lambda)
    at android.os.Handler.handleCallback(Handler.java:754)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:165)
    at android.app.ActivityThread.main(ActivityThread.java:6375)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:802)

Expected behavior

Repro steps

  1. Created project using expo bare workflow
  2. Web and Mobile project using yarn workspaces
  3. When I use apk using scanning code from expo server then AsyncStorage work successfully (expo start cmd use for running APK)
  4. If I use expo:build android -t apk then expo create apk on their platform
  5. Download that APK from the expo server
  6. If I install that downloaded APK, and start using it, on app lunch it crashed and give me the above error log

  7. If I remove AsyncStorage lib, and follow the above steps then app works fine, but I need this lib in my app.

Environment

  • Async Storage version:1.12.0
  • React-Native version: 0.63.0
  • Platform tested: Android
  • Logs/Error that is relevant: If we scan the app from expo client then it works fine, but if I tried to create APK using expo:build android -t apk then it crashed on app launch.
    -**"expo": "~38.0.9",
Android question

Most helpful comment

when you run expo build:android -t apk you will see this:

╰─$ expo build:android -t apk
⚠️  expo build:android currently only supports managed workflow apps.
If you proceed with this command, we can run the build for you but it will not include any custom native modules or changes that you have made to your local native projects.
Unless you are sure that you know what you are doing, we recommend aborting the build and doing a native release build through Android Studio.
? Would you like to proceed? › (Y/n)

i guess you proceeded anyways. you shouldn't :P the build service currently only supports managed apps. feel free to dm me on twitter @notbrent and i can help you try out a preview of our new build service that supports bare react-native apps too.

@Krizzu - feel free to close this issue

All 9 comments

That worked for me:

Look at https://react-native-community.github.io/async-storage/docs/install :

"Note: For Windows the manual linking is currently the only linking option."
You may need to close visual studio or reload the solution/project.

@SwapnilShoreline: Did you eject to ExpoKit? If not, did you look at the Expo documentation? Can you also please fill out the "Repro steps" section? Without knowing how to reproduce this bug, we cannot help you.

@tido64 will do and let you know, also for your information we are using yarn workspaces to share code between web and mobile platform.

@tido64 updated bug added repro steps. Please take a look into this

@SwapnilShoreline: It doesn't look like you've ejected. Is that correct? I'm not familiar with how unejected Expo apps work. Have you looked at the Expo docs? Maybe @Krizzu knows more about this.

I'm not familiar with it build process either. What Expo version you use?
We have support for it since version v1.11.0. Maybe @brentvatne might have an idea?

@Krizzu Expo version is 3.21.13

Hi @Krizzu @brentvatne , take a look into this

when you run expo build:android -t apk you will see this:

╰─$ expo build:android -t apk
⚠️  expo build:android currently only supports managed workflow apps.
If you proceed with this command, we can run the build for you but it will not include any custom native modules or changes that you have made to your local native projects.
Unless you are sure that you know what you are doing, we recommend aborting the build and doing a native release build through Android Studio.
? Would you like to proceed? › (Y/n)

i guess you proceeded anyways. you shouldn't :P the build service currently only supports managed apps. feel free to dm me on twitter @notbrent and i can help you try out a preview of our new build service that supports bare react-native apps too.

@Krizzu - feel free to close this issue

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mxmzb picture mxmzb  ·  19Comments

michaelsinatra picture michaelsinatra  ·  24Comments

muhammadn picture muhammadn  ·  58Comments

rogueturnip picture rogueturnip  ·  27Comments

while-it picture while-it  ·  51Comments