react-native-async-storage / async-storage

An asynchronous, persistent, key-value storage system for React Native.
https://react-native-async-storage.github.io/async-storage/
MIT License
4.7k stars 466 forks source link

[Android] NativeModule: AsyncStorage is null when try autolinking. #197

Closed azamiya closed 5 years ago

azamiya commented 5 years ago

Current behavior

yarn add @react-native-community/async-storage and react-native run-andoid

and this error is shown.

Screenshot_20190826-102504

Hint

When I link it manually, https://github.com/react-native-community/async-storage/blob/LEGACY/docs/Linking.md#android

it works fine.

but this error is shown on the console.

error React Native CLI uses autolinking for native dependencies, but the following modules are linked manually:
  - @react-native-community/async-storage (to unlink run: "react-native unlink @react-native-community/async-storage")
This is likely happening when upgrading React Native from below 0.60 to 0.60 or above. Going forward, you can unlink this dependency via "react-native unlink <dependency>" and it will be included in your app automatically. If a library isn't compatible with autolinking, disregard this message and notify the library maintainers.
Read more about autolinking: https://github.com/react-native-community/cli/blob/master/docs/autolinking.md
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.

Expected behavior

autolinking works.

Repro steps

  1. yarn add @react-native-community/async-storage
  2. react-native run-andoid

Environment

krizzu commented 5 years ago

You can read me about autolinking here.

Did you update from the previous version of RN or is it a new project?

Jakuubzmeko commented 5 years ago

I have this problem as well, I hav ethis problem since RN 0.59, so I upgraded to 0.60 thinking it would solve the problem, but didn't.

I tried to remove build, clean project and caches, but still nothing.

krizzu commented 5 years ago

Autolinking works on Android by changing the way it's requiring the Native packages. Have a look at RN 0.60 MainApplication.java.

@jakuubzmeko Any more details? 0.59 do have autolinking feature - you have to do it through CLI or manually.

Jakuubzmeko commented 5 years ago

@Krizzu I have RN 0.65,

I don't know whether I should see these packages in android studio, should I ?

image

Jakuubzmeko commented 5 years ago

I linked the libraries manualy, async-storage, gesture-handler and google-sign-in, and it works fine. Either they dont support autolinking, or autolinking doesn't work at my project

royhanrahim commented 5 years ago

Do you have to be linked to run this library ?? isn't it for react-native@0.60.5 no need to link ?? if I error in IOS

krizzu commented 5 years ago

@Jakuubzmeko What's the content of your MainApplication.java?

Jakuubzmeko commented 5 years ago

@Krizzu It was the same, so I wanted to show you, so I unlinked them again, and edited the MainApplication.java then I ran it and it works just fine. What I think happend, that i did not unlink them properly before by react-native unlink, but just removed references from build.gradle and MainApplication.java. So maybe linking and unlinking helped. Still wandering what happened.

ianmcgregor commented 5 years ago

Got the same error. Doing a cd android/ && ./gradlew clean before run-android fixed autolinking for me.

trungnguyencmu commented 4 years ago

Show add new AsyncStoragePackage()); in MainApplication.java https://github.com/react-native-community/async-storage/blob/LEGACY/docs/Linking.md#android