itinance / react-native-fs

Native filesystem access for react-native
MIT License
4.89k stars 954 forks source link

How integrate with react-native use Kotlin (RN: 0.73.0) instead of Java for Android? #1214

Open huynhttdev opened 5 months ago

huynhttdev commented 5 months ago

I can integrate react-native-fs with react-native project because my project uses Kotlin instead of Java. I can not find any guide for this.

bosz commented 5 months ago

I'm facing the same issue. Is there a solution for this?

vikaskumar122232 commented 5 months ago

I'm also. facing the same issue

birdofpreyru commented 5 months ago

#1197 — The Future of react-native-fs

nvacheishvili commented 3 months ago
package com.mobileapp

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.rnfs.RNFSPackage

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());
          //ADD THE FOLLOWING LINES 
          val packages = PackageList(this).packages
          // Manually add packages that cannot be autolinked
          packages.add(RNFSPackage()) // Corrected instantiation of RNFSPackage
          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)
  }
}
birdofpreyru commented 3 months ago

:beer::rofl::popcorn: