> ## 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.

# Core setup

> Initialize FileKit Core on each platform, choose app directories, and add ProGuard rules

[See the platform support matrix](https://filekit.mintlify.site/platform-support.md#filekit-core)

`filekit-core` works without setup on most targets. JVM desktop, Linux native, and Windows native need an application ID so FileKit can resolve `FileKit.filesDir`, `FileKit.cacheDir`, and `FileKit.databasesDir`. Add the dependency first: see [Installation](https://filekit.mintlify.site/installation.md).

## Initialize FileKit

> [tab] Android
>
> Nothing to do. FileKit Core initializes itself with [App Startup](https://developer.android.com/topic/libraries/app-startup).
>
> | Directory | Location |
> | - | - |
> | `filesDir` | `Context.filesDir` (app-private internal storage) |
> | `cacheDir` | `Context.cacheDir` |
> | `databasesDir` | The parent of `Context.getDatabasePath(...)` (`databases/`) |
>
> These directories can't be changed. If you disable App Startup in your app, initialize FileKit Core yourself before using it:
>
> ```kotlin MainActivity.kt theme={null}
> class MainActivity : ComponentActivity() {
>     override fun onCreate(savedInstanceState: Bundle?) {
>         super.onCreate(savedInstanceState)
>         FileKit.manualFileKitCoreInitialization(this)
>     }
> }
> ```
>
> Dialogs need their own registration when you use `filekit-dialogs` without Compose. See [Dialogs setup](https://filekit.mintlify.site/dialogs/setup.md).

> [tab] JVM desktop
>
> Call `FileKit.init` once at startup, before you read any app directory:
>
> ```kotlin main.kt theme={null}
> fun main() {
>     FileKit.init(appId = "com.example.myapp")
>
>     application {
>         Window(onCloseRequest = ::exitApplication) { App() }
>     }
> }
> ```
>
> | Directory | Windows | macOS | Linux |
> | - | - | - | - |
> | `filesDir` | `%APPDATA%\<appId>` | `~/Library/Application Support/<appId>` | `$XDG_DATA_HOME/<appId>`, or `~/.local/share/<appId>` |
> | `cacheDir` | `%LOCALAPPDATA%\<appId>\Cache` | `~/Library/Caches/<appId>` | `$XDG_CACHE_HOME/<appId>`, or `~/.cache/<appId>` |
> | `databasesDir` | `filesDir/databases` | `filesDir/databases` | `filesDir/databases` |
>
> To use your own locations (for a portable app, for example), pass `java.io.File` values. A directory you leave out keeps its default:
>
> ```kotlin main.kt theme={null}
> val appDir = File(System.getProperty("user.home"), ".myapp")
> FileKit.init(
>     appId = "com.example.myapp",
>     filesDir = File(appDir, "data"),
>     cacheDir = File(appDir, "cache"),
> )
> ```
>
> `FileKit.init(filesDir = ..., cacheDir = ...)` without an `appId` also works when you set both directories.

> [tab] Linux native
>
> For `linuxX64` and `linuxArm64`, call `FileKit.init` once at startup:
>
> ```kotlin main.kt theme={null}
> fun main() {
>     FileKit.init(appId = "com.example.myapp")
> }
> ```
>
> | Directory | Location |
> | - | - |
> | `filesDir` | `$XDG_DATA_HOME/<appId>`, or `~/.local/share/<appId>` |
> | `cacheDir` | `$XDG_CACHE_HOME/<appId>`, or `~/.cache/<appId>` |
> | `databasesDir` | `filesDir/databases` |
>
> A relative `XDG_*` value is ignored, as the XDG spec requires. When `HOME` is unset, FileKit reads the home directory from the passwd database.
>
> To use your own locations, pass `PlatformFile` values:
>
> ```kotlin main.kt theme={null}
> FileKit.init(
>     appId = "com.example.myapp",
>     filesDir = PlatformFile("/opt/myapp/data"),
>     cacheDir = PlatformFile("/opt/myapp/cache"),
> )
> ```

> [tab] Windows native
>
> For `mingwX64`, call `FileKit.init` once at startup:
>
> ```kotlin main.kt theme={null}
> fun main() {
>     FileKit.init(appId = "com.example.myapp")
> }
> ```
>
> | Directory | Location |
> | - | - |
> | `filesDir` | `%APPDATA%\<appId>` |
> | `cacheDir` | `%LOCALAPPDATA%\<appId>\Cache` |
> | `databasesDir` | `filesDir\databases` |
>
> To use your own locations, pass `PlatformFile` values:
>
> ```kotlin main.kt theme={null}
> FileKit.init(
>     appId = "com.example.myapp",
>     filesDir = PlatformFile("C:\\MyApp\\data"),
>     cacheDir = PlatformFile("C:\\MyApp\\cache"),
> )
> ```

> [tab] iOS, macOS, watchOS, web
>
> Nothing to do. Directories follow the platform conventions and can't be changed.
>
> | Platform | `filesDir` | `cacheDir` |
> | - | - | - |
> | iOS, watchOS | The app's `Documents` directory | The app's `Caches` directory |
> | macOS | `~/Library/Application Support/<bundle id>` | `~/Library/Caches` (the container's `Caches` when sandboxed) |
>
> `databasesDir` is `filesDir/databases` on Apple platforms. On macOS, `filesDir` uses the app bundle identifier and throws if the executable has none.
>
> Browsers have no app directories. To store files on the web, use the [origin private file system](https://filekit.mintlify.site/core/web.md#store-files-in-the-origin-private-file-system).

> [!NOTE]
>
> On JVM, Linux native, and Windows native, reading `FileKit.filesDir`, `cacheDir`, or `databasesDir` before `FileKit.init` throws. FileKit creates `filesDir` and `cacheDir` the first time you read them.

## ProGuard

If you shrink or obfuscate a JVM desktop app, add these rules to your `proguard-rules.pro`:

```proguard proguard-rules.pro 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
```

## Related

* [App directories](https://filekit.mintlify.site/core/file-utils.md): app directories and user folders such as Downloads.
* [Dialogs setup](https://filekit.mintlify.site/dialogs/setup.md): Android activity registration and Linux packaging.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.