roboquant icon indicating copy to clipboard operation
roboquant copied to clipboard

Android implementation stuck on roboquant home directory

Open tamuseanmiller opened this issue 1 year ago • 2 comments

Currently attempting to implement a POC of this library into an Android app. Currently, it will fail when doing instrumented tests or running the app when trying to create the home directory. It seems to check for the JVM user.home directory which on Android isn't a valid write spot as app's storage are segmented from the regular phone's storage. Is there any way to pass a custom path instead? Ideally we should be able to pass a custom home directory like /data/data/<package-name>/.roboquant on Android

Here is the stack trace of the failure if it helps:

java.nio.file.FileSystemException: .roboquant: Read-only file system
at sun.nio.fs.UnixFileSystemProvider.createDirectory(UnixFileSystemProvider.java:404)
at java.nio.file.Files.createDirectory(Files.java:674)
at org.roboquant.common.Config$home$2.invoke(Config.kt:150)
at org.roboquant.common.Config$home$2.invoke(Config.kt:147)
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
at org.roboquant.common.Config.getHome(Config.kt:147)
at org.roboquant.common.Config.getEnv(Config.kt:218)
at org.roboquant.common.Config.getProperty(Config.kt:201)
at org.roboquant.common.Config.getProperty(Config.kt:173)

tamuseanmiller avatar Jun 22 '24 16:06 tamuseanmiller

I guess this is the offending code in the Config class:

val home: Path by lazy {
      val path: Path = Paths.get(System.getProperty("user.home"), ".roboquant")
      if (Files.notExists(path)) {
          Files.createDirectory(path)
          logger.trace { "Created new home directory $path" }
      }
      path
  }

One solution could be to check for another property first (like "roboquant.home") that would supersede this default implementation. Something like:

val home: Path by lazy {
      val roboquantHome = getProperty("roboquant.home")
      val path = if (roboquantHome != null) Paths.get(roboquantHome) else
          Paths.get(System.getProperty("user.home"), ".roboquant")
      if (Files.notExists(path)) {
          Files.createDirectory(path)
          logger.trace { "Created new home directory $path" }
      }
      path
}

jbaron avatar Jun 22 '24 19:06 jbaron

I guess this is the offending code in the Config class:

val home: Path by lazy {
      val path: Path = Paths.get(System.getProperty("user.home"), ".roboquant")
      if (Files.notExists(path)) {
          Files.createDirectory(path)
          logger.trace { "Created new home directory $path" }
      }
      path
  }

One solution could be to check for another property first (like "roboquant.home") that would supersede this default implementation. Something like:

val home: Path by lazy {
      val roboquantHome = getProperty("roboquant.home")
      val path = if (roboquantHome != null) Paths.get(roboquantHome) else
          Paths.get(System.getProperty("user.home"), ".roboquant")
      if (Files.notExists(path)) {
          Files.createDirectory(path)
          logger.trace { "Created new home directory $path" }
      }
      path
}

That's a great idea, would just have to update docs for this as well. Much easier than passing a path in for everything that uses the Config class haha.

tamuseanmiller avatar Jun 23 '24 15:06 tamuseanmiller