> ## Documentation Index
> Fetch the complete documentation index at: https://filekit.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Setup

> Setup FileKit Core in your Kotlin Multiplatform project

## Installation

FileKit provides a platform-agnostic file abstraction called `PlatformFile`. It allows you to work with files in a platform-agnostic way. You can create, read, write, and delete files using the `PlatformFile` API.

You can use `PlatformFile` in your project by adding the following dependency:

<CodeGroup>
  ```kotlin build.gradle.kts theme={null}
  implementation("io.github.vinceglb:filekit-core:0.14.2")
  ```

  ```toml libs.versions.toml theme={null}
  [versions]
  filekit = "0.14.2"

  [libraries]
  filekit-core = { module = "io.github.vinceglb:filekit-core", version.ref = "filekit" }
  ```
</CodeGroup>

FileKit Core provides the fundamental file operations for your Kotlin Multiplatform project. It's designed to work across all supported platforms with a unified API.

## Platform-specific setup

FileKit Core is designed to work out of the box for most platforms, but some targets require additional setup.

### Android setup

FileKit Core is **automatically initialized** in Android applications. It uses [App Startup](https://developer.android.com/topic/libraries/app-startup) to initialize the library, ensuring that it is ready to use when your app starts.

If for some reason you want to disable App Startup in your app, you can initialize FileKit manually by calling `FileKit.manualFileKitCoreInitialization(context)` in your `MainActivity` or `Application` class.

```kotlin theme={null}
class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        // Initialize FileKit
        FileKit.manualFileKitCoreInitialization(this)
    }
}
```

### JVM setup

FileKit needs to have your application id to handle the app directory. Your application id is generally the package name or the name of your application. FileKit will use this `appId` as app directory.

We recommend you to initialize FileKit in your `main.kt` file:

```kotlin main.kt theme={null}
fun main() {
  // Initialize FileKit
  FileKit.init(appId = "MyApplication")

  // Start your application
  application {
      Window(onCloseRequest = ::exitApplication) {
          // ...
      }
  }
}
```

The application ID is used to create user-specific directories on different operating systems:

* Windows: `%APPDATA%\your.application.id\`
* macOS: `~/Library/Application Support/your.application.id/`
* Linux: `~/.local/share/your.application.id/`

#### Custom Cache and Data Directories

For applications that need custom directory paths (e.g., portable applications or specific deployment scenarios), you can specify custom cache and data directories:

```kotlin main.kt theme={null}
fun main() {
  val appDir = File(System.getProperty("user.home"), ".myapp")
  FileKit.init(
      appId = "MyApplication",
      filesDir = File(appDir, "data"),
      cacheDir = File(appDir, "cache")
  )

  // ...
}
```

#### ProGuard Configuration

If you're using ProGuard or code obfuscation on JVM platforms, add the relevant rules to your `proguard-rules.pro`:

```proguard theme={null}
# Required on JVM for JNA-based integrations.
-keep class com.sun.jna.** { *; }
-keep class * implements com.sun.jna.** { *; }

# Required when using FileKit Dialogs on Linux (XDG Desktop Portal / DBus).
-keep class org.freedesktop.dbus.** { *; }
-keep class io.github.vinceglb.filekit.dialogs.platform.xdg.** { *; }
-keepattributes Signature,InnerClasses,RuntimeVisibleAnnotations
```

### iOS, macOS, JS, WASM setup

No additional setup is needed for iOS, macOS, JS, and WASM targets. FileKit Core works out of the box on these platforms.
