AndroidRuntime: java.lang.RuntimeException: Expo encountered a fatal error: Error: [@RNC/AsyncStorage]: NativeModule: AsyncStorage is null.

02-11 17:45:29.421 16524 16524 E AndroidRuntime: java.lang.RuntimeException: Expo encountered a fatal error: Error: [@RNC/AsyncStorage]: NativeModule: AsyncStorage is null.
02-11 17:45:29.421 16524 16524 E AndroidRuntime:
02-11 17:45:29.421 16524 16524 E AndroidRuntime: To fix this issue try these steps:
02-11 17:45:29.421 16524 16524 E AndroidRuntime:
02-11 17:45:29.421 16524 16524 E AndroidRuntime: • Run react-native link @react-native-async-storage/async-storage in the project root.
02-11 17:45:29.421 16524 16524 E AndroidRuntime:
02-11 17:45:29.421 16524 16524 E AndroidRuntime: • Rebuild and restart the app.
02-11 17:45:29.421 16524 16524 E AndroidRuntime:
02-11 17:45:29.421 16524 16524 E AndroidRuntime: • Run the packager with --reset-cache flag.
02-11 17:45:29.421 16524 16524 E AndroidRuntime:
02-11 17:45:29.421 16524 16524 E AndroidRuntime: • If you are using Coc
02-11 17:45:29.421 16524 16524 E AndroidRuntime: at host.exp.exponent.experience.q.E(BaseExperienceActivity.java:7)
02-11 17:45:29.421 16524 16524 E AndroidRuntime: at host.exp.exponent.experience.a.run(Unknown Source:2)
02-11 17:45:29.421 16524 16524 E AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:938)
02-11 17:45:29.421 16524 16524 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:99)
02-11 17:45:29.421 16524 16524 E AndroidRuntime: at android.os.Looper.loop(Looper.java:223)
02-11 17:45:29.421 16524 16524 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:7656)
02-11 17:45:29.421 16524 16524 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
02-11 17:45:29.421 16524 16524 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)

you probably have a custom metro.config.js. be sure to follow this doc Customizing Metro - Expo Documentation

Sorry i am confused I am following this doc AsyncStorage - Expo Documentation

I learned from this post Migration from SDK 37 to 40 · Issue #11314 · expo/expo · GitHub
So I have change metro config like this is this below is this correct ? @notbrent

const { getDefaultConfig } = require("@expo/metro-config");

const defaultConfig = getDefaultConfig(__dirname);

module.exports = {
  transformer: {
    assetPlugins: ["expo-asset/tools/hashAssetFiles"],
  },
  resolver: {
    assetExts: [...defaultConfig.resolver.assetExts, "db"],
  },
};

Can you please be clear thanks for the help !!

well it depends - what does your current metro.config.js contain?

This is my current metro.config.js


const { getDefaultConfig } = require("@expo/metro-config");

const defaultConfig = getDefaultConfig(__dirname);

module.exports = {
  transformer: {
    assetPlugins: ["expo-asset/tools/hashAssetFiles"],
  },
  resolver: {
    assetExts: [...defaultConfig.resolver.assetExts, "db"],
  },
};

It works fine when i do expo start and run it on expo client

But when i build using expo build:android i am trying to use my apk generated it is giving me Asyncstorage null error and and app crashes

oh ok. then my guess is that you have an android or ios directory, or react-native-unimodules in your package.json - perhaps you tried ejecting before and then changed your mind. if you run expo diagnostics in your project you will find it will say you have a “bare” project. so remove the android and ios directories and remove the react-native-unimodules package from your project if you have it

ya it is a bare project

Should i delete the android and ios directory and run expo build:android try that apk ?

this my expo diagnostics

Expo CLI 4.0.17 environment info:
    System:
      OS: macOS 10.15.7
      Shell: 5.7.1 - /bin/zsh
    Binaries:
      Node: 10.15.3 - ~/.nvm/versions/node/v10.15.3/bin/node
      npm: 6.14.5 - ~/.nvm/versions/node/v10.15.3/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    Managers:
      CocoaPods: 1.10.0 - /usr/local/bin/pod
    SDKs:
      Android SDK:
        API Levels: 30
        Build Tools: 30.0.3
        System Images: android-30 | Google APIs Intel x86 Atom
    IDEs:
      Android Studio: 4.1 AI-201.8743.12.41.6953283
      Xcode: /undefined - /usr/bin/xcodebuild
    npmPackages:
      expo: ~40.0.0 => 40.0.0 
      react: 16.13.1 => 16.13.1 
      react-dom: 16.13.1 => 16.13.1 
      react-native: ^0.63.4 => 0.63.4 
      react-native-web: ~0.13.12 => 0.13.18 
    npmGlobalPackages:
      expo-cli: 4.0.17
    Expo Workflow: bare

And try Managed build

yes. when you run expo build:android it will tell that you cannot use that for building bare apps. we launched a preview of the next generation of our build service that you could try if you want to use a build service w/ your bare app - https://blog.expo.io/expo-application-services-eas-build-and-submit-fc1d1476aa2e

otherwise if you’re using expo build:android you need to do what i said above to turn it back to managed

1 Like