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.67k stars 465 forks source link

build error in the my react-native app after supporting kotlin file #1128

Closed wood1986 closed 1 month ago

wood1986 commented 1 month ago

What happened?

When I try to configure the my react-native app to support koltin file, this library gives these errors

image

Then I try the example of this library and set AsyncStorage_useNextStorage=false, it also gives me the same errors

image

Version

1.15.19

What platforms are you seeing this issue on?

System Information

info Fetching system and libraries information...
System:
  OS: macOS 14.5
  CPU: (10) arm64 Apple M1 Max
  Memory: 77.56 MB / 32.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.20.2
    path: ~/.nvm/versions/node/v18.20.2/bin/node
  Yarn:
    version: 4.2.2
    path: ~/.nvm/versions/node/v18.20.2/bin/yarn
  npm:
    version: 10.5.0
    path: ~/.nvm/versions/node/v18.20.2/bin/npm
  Watchman:
    version: 2024.07.15.00
    path: /usr/local/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.2
    path: /Users/wood/.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.2
      - iOS 17.2
      - macOS 14.2
      - tvOS 17.2
      - visionOS 1.0
      - watchOS 10.2
  Android SDK: Not Found
IDEs:
  Android Studio: 2024.1 AI-241.18034.62.2411.12071903
  Xcode:
    version: 15.2/15C500b
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.11
    path: /usr/bin/javac
  Ruby:
    version: 3.2.2
    path: /Users/wood/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react: Not Found
  react-native: Not Found
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: Not found
  newArchEnabled: Not found
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found

Steps to Reproduce

  1. try example in this project
  2. AsyncStorage_useNextStorage=false in gradle.properties
  3. open StorageModule.kt
  4. configure kotlin support image image
  5. build it
tido64 commented 1 month ago

I am unable repro this:

% ./gradlew assembleDebug

> Configure project :
[AsyncStorage] Using Next storage: false

> Configure project :app
WARNING: The option setting 'android.jetifier.ignorelist=hermes-android' is experimental.

> Task :react-native-async-storage_async-storage:processDebugManifest
> Task :app:processDebugMainManifest
> Task :react-native-async-storage_async-storage:compileDebugJavaWithJavac

BUILD SUCCESSFUL in 1m 26s
109 actionable tasks: 104 executed, 5 up-to-date

Have you tried using the latest version?

wood1986 commented 1 month ago

Hey @tido64 and @krizzu

If you just set AsyncStorage_useNextStorage=false, and yes you can build without any issue. Having this AsyncStorage_useNextStorage=false is not enough

Did you have the follow configuration in the app/build.gradle in the example? I need to have the follow config in order to consume kotlin file.

image

krizzu commented 1 month ago

It seems that your version is too old and requires extra setup to add kotlin (it used to be like that, not anymore since RN ships with Kotlin plugin). I recommend upgrading or applying kotlin plugin in your app's build.gradle

wood1986 commented 1 month ago

At the very beginning, this change is placed in the my own react-native app. When I build, the compiler complains this library. You can see my repo branch, I have been putting this configuration in the app/build.gradle

image

your version is too old

If you mean this lib, then I have been using the latest main branch to configure in my repo branch

If you mean RN version, then as on my side, it is a enterprise app, lots of teams share the same codebase, I cannot update it directly.

wood1986 commented 1 month ago

Hey @tido64 and @krizzu

I have already put a fix #1127. I have already moved the file to a different location to exclude "next" code.

Currently, when you have AsyncStorage_useNextStorage=false, the current build setting does not build kotlin file. That's why you wont see this issue

After enabling supporting kotlin file, all kotlin files inside next folder will get included

krizzu commented 1 month ago

I mean to update both (lib and RN). If you cannot update RN, try getting latest lib. Digging out old documentation, here's the setup guide for next storage from version 1.16.0 that should work for you

wood1986 commented 1 month ago

Here is the limitation on my side

The documentation you mentioned is asking me to use next. But I do not need and am not allow to use next.

May I ask you if you really check out my repro branch to see the actual issue?

wood1986 commented 1 month ago

OK. my question why it build the file inside next folder when AsyncStorage_useNextStorage=false after supporting kotlin file in the consumer app

krizzu commented 1 month ago

Currently, when you have AsyncStorage_useNextStorage=false, the current build setting does not build kotlin file. That's why you wont see this issue

That's intended - next is not included in build with flag off.

OK. my question why it build the file inside next folder when AsyncStorage_useNextStorage=false after supporting kotlin file in the consumer app

When u press "configure kotlin" in android studio, kotlin plugin that's currently applied conditionally (based on useNextStorage flag) is now applied directly, so it automatically consumes next storage.

wood1986 commented 1 month ago

And I am telling you the fact. This is what it behaves currently. I know what you are talking about conditional flag. But this is not what you have believed

Is it possible to clone my fork and checkout branch to see how I can get rid of the room error?

https://github.com/wood1986/async-storage. 'repo/build-error'

krizzu commented 1 month ago

Is it possible to clone my fork and checkout branch to see how I can get rid of the room error?

https://github.com/wood1986/async-storage. 'repo/build-error'

Yes, remove this line here

I either don't understand what the issue is or there are some bits that you're missing from my explanation.

The kotlin plugin (org.jetbrains.kotlin.android) is applied only when useNextStorage is true. Same goes for dependencies, such as Room or Coroutines.

In your repo, you have flag set to off, while you explicitly apply Kotlin plugin. In that case, dependencies are not included, but Kotlin plugin is looking for source files in default locations, such as src/java/src/kotlin, hence it compiles it, but then reports the issue with missing dependencies.

wood1986 commented 1 month ago

I am sorry for the false alarm. When I configure to support kotlin, I change the build.gradle for all modules. It includes this library. I should configure to the single app module only not all modules