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.61k stars 459 forks source link

build faild in react native 73 #1047

Closed YOEL311 closed 6 months ago

YOEL311 commented 6 months ago

What happened?

I use react native async storage on react side it works fine but when I try to access data from Android native this way

https://react-native-async-storage.github.io/async-storage/docs/advanced/brownfield

with this code

suspend fun readValue(ctx: Context, keys: List<String>) {
    // get instance of the Storage by providing context object
    val asyncStorage = StorageModule.getStorageInstance(ctx)

    val entries: List<Entry> = asyncStorage.getValues(keys)
    doSomethingWithValues(entries)
}

my build failed


BUILD FAILED in 10s
error Failed to install the app. Command failed with exit code 1: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /********node_modules/@react-native-async-storage/async-storage/android/src/javaPackage/java/com/reactnativecommunity/asyncstorage/AsyncStoragePackage.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
e: *******/test73/test73/android/app/src/main/java/com/test73/MainApplication.kt:14:46 Unresolved reference: next
e: file:///*************/android/app/src/main/java/com/test73/MainApplication.kt:48:28 Unresolved reference: StorageModule FAILURE: Build failed with an exception. * What went wrong:
Execution failed for task ':app:compileDebugKotlin'.

this is my file that broken

package com.test73

import android.app.Application
import com.facebook.react.PackageList
import com.facebook.react.ReactApplication
import com.facebook.react.ReactHost
import com.facebook.react.ReactNativeHost
import com.facebook.react.ReactPackage
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
import com.facebook.react.defaults.DefaultReactNativeHost
import com.facebook.react.flipper.ReactNativeFlipper
import com.facebook.soloader.SoLoader
import com.reactnativecommunity.asyncstorage.next.StorageModule

class MainApplication : Application(), ReactApplication {

  override val reactNativeHost: ReactNativeHost =
      object : DefaultReactNativeHost(this) {
        override fun getPackages(): List<ReactPackage> {
          // Packages that cannot be autolinked yet can be added manually here, for example:
          // packages.add(new MyReactNativePackage());
          return PackageList(this).packages
        }

          override fun getJSMainModuleName(): String = "index"

          override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG

        override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
        override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
      }

  override val reactHost: ReactHost
    get() = getDefaultReactHost(this.applicationContext, reactNativeHost)

  override fun onCreate() {
    super.onCreate()
    SoLoader.init(this, false)
    if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
      // If you opted-in for the New Architecture, we load the native entry point for this app.
      load()
    }
    ReactNativeFlipper.initializeFlipper(this, reactNativeHost.reactInstanceManager)
  }
    suspend fun readValue( keys: List<String>) {
        // get instance of the Storage by providing context object
        val asyncStorage = StorageModule.getStorageInstance(this)

//        val entries: List<Entry> = asyncStorage.getValues(keys)
//        doSomethingWithValues(entries)
    }
}

I

Version

1.21.0

What platforms are you seeing this issue on?

System Information

info Fetching system and libraries information...
System:
  OS: macOS 13.4.1
  CPU: (10) arm64 Apple M2 Pro
  Memory: 101.14 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.16.1
    path: /usr/local/bin/node
  Yarn:
    version: 1.22.19
    path: /usr/local/bin/yarn
  npm:
    version: 9.5.1
    path: /usr/local/bin/npm
  Watchman:
    version: 2023.09.25.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.12.1
    path: /opt/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 22.2
      - iOS 16.2
      - macOS 13.1
      - tvOS 16.1
      - watchOS 9.1
  Android SDK:
    API Levels:
      - "23"
      - "26"
      - "28"
      - "29"
      - "30"
      - "31"
      - "33"
      - "34"
    Build Tools:
      - 30.0.2
      - 30.0.3
      - 33.0.0
      - 33.0.1
      - 34.0.0
    System Images:
      - android-34 | Google APIs ARM 64 v8a
    Android NDK: 22.1.7171670
IDEs:
  Android Studio: 2023.1 AI-231.9392.1.2311.11076708
  Xcode:
    version: 14.2/14C18
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 11.0.19
    path: /usr/bin/javac
  Ruby:
    version: 3.2.2
    path: /opt/homebrew/opt/ruby/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.73.0
    wanted: 0.73.0
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: Not found
  newArchEnabled: false

Steps to Reproduce

you can see in this repo

https://github.com/YOEL311/reproduce-async-storage-react-native-73

init commit is for npx react-native init

https://github.com/YOEL311/reproduce-async-storage-react-native-73/commit/ab78f42daccdf72b44238884ac8b3c231ec1faf0

the second commit is to reproduce the problem

https://github.com/YOEL311/reproduce-async-storage-react-native-73/commit/d3eaf47b53e01067893adc35f1fb04f8380d92aa

YOEL311 commented 6 months ago

I caught the problem I was missing to add AsyncStorage_useNextStorage=true in gradle.properties

but in my real app when I added it my app broke because the code push and firebase also use async-storage

VMBindraban commented 6 months ago

I caught the problem I was missing to add AsyncStorage_useNextStorage=true in gradle.properties

but in my real app when I added it my app broke because the code push and firebase also use async-storage

This should be added to the docs. @krizzu