|
| 1 | +# Using FileLogger locally in another Android app |
| 2 | + |
| 3 | +This repo is **not published to Maven (local or remote) or JitPack**. The two ways to consume it from another local Android project on the same machine are below. Pick one. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## Option A — Gradle composite build (recommended for development) |
| 8 | + |
| 9 | +Best when you want to iterate on FileLogger and the consumer app together: changes in this repo show up in the consumer immediately, no rebuild step in the middle. |
| 10 | + |
| 11 | +In the **consumer app's** `settings.gradle` (or `settings.gradle.kts`), add `includeBuild`: |
| 12 | + |
| 13 | +```gradle |
| 14 | +pluginManagement { |
| 15 | + repositories { |
| 16 | + google() |
| 17 | + mavenCentral() |
| 18 | + gradlePluginPortal() |
| 19 | + } |
| 20 | +} |
| 21 | +dependencyResolutionManagement { |
| 22 | + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) |
| 23 | + repositories { |
| 24 | + google() |
| 25 | + mavenCentral() |
| 26 | + } |
| 27 | +} |
| 28 | +includeBuild('/home/abolfazl/code/FileLogger') { |
| 29 | + dependencySubstitution { |
| 30 | + substitute module('com.github.aabolfazl:filelogger') using project(':filelogger') |
| 31 | + substitute module('com.github.aabolfazl:filelogger-okhttp') using project(':filelogger-okhttp') |
| 32 | + } |
| 33 | +} |
| 34 | +rootProject.name = "your-consumer-app" |
| 35 | +include ':app' |
| 36 | +``` |
| 37 | + |
| 38 | +In the consumer's `app/build.gradle`: |
| 39 | + |
| 40 | +```gradle |
| 41 | +dependencies { |
| 42 | + implementation 'com.github.aabolfazl:filelogger:2.0.0' |
| 43 | + // optional: |
| 44 | + implementation 'com.github.aabolfazl:filelogger-okhttp:2.0.0' |
| 45 | +} |
| 46 | +``` |
| 47 | + |
| 48 | +Sync the consumer project. Gradle resolves the substitutions to the local sources. Edit FileLogger code → rebuild the consumer → changes flow through. |
| 49 | + |
| 50 | +**Caveats:** |
| 51 | +- Both projects must use compatible AGP/Kotlin versions. FileLogger is on **AGP 9.2.0 / Kotlin 2.2.10 / Gradle 9.4.1**. |
| 52 | +- Consumer's `compileSdk` ≥ 36 (FileLogger's compile SDK). |
| 53 | +- Consumer's `minSdk` ≥ 26 (FileLogger uses `java.time` natively — no `coreLibraryDesugaring` needed). |
| 54 | +- Consumer's `JavaVersion.targetCompatibility` ≥ 11 (FileLogger emits JVM 11 bytecode). |
| 55 | + |
| 56 | +--- |
| 57 | + |
| 58 | +## Option B — Drop the AAR into the consumer's `libs/` folder |
| 59 | + |
| 60 | +Best when you want a frozen snapshot of FileLogger and don't plan to edit it. |
| 61 | + |
| 62 | +### Build the AAR |
| 63 | + |
| 64 | +In this repo: |
| 65 | + |
| 66 | +```bash |
| 67 | +./gradlew :filelogger:assembleRelease |
| 68 | +./gradlew :filelogger-okhttp:assembleRelease # optional |
| 69 | +``` |
| 70 | + |
| 71 | +The artifacts land at: |
| 72 | + |
| 73 | +- `filelogger/build/outputs/aar/filelogger-release.aar` |
| 74 | +- `filelogger-okhttp/build/outputs/aar/filelogger-okhttp-release.aar` |
| 75 | + |
| 76 | +### Wire into the consumer |
| 77 | + |
| 78 | +Copy the AAR(s) into `app/libs/` of the consumer project. Then in the consumer's `app/build.gradle`: |
| 79 | + |
| 80 | +```gradle |
| 81 | +android { |
| 82 | + // ... |
| 83 | + compileSdk 36 |
| 84 | + defaultConfig { minSdk 26 } |
| 85 | + compileOptions { |
| 86 | + sourceCompatibility JavaVersion.VERSION_11 |
| 87 | + targetCompatibility JavaVersion.VERSION_11 |
| 88 | + } |
| 89 | +} |
| 90 | +
|
| 91 | +dependencies { |
| 92 | + implementation files('libs/filelogger-release.aar') |
| 93 | + implementation files('libs/filelogger-okhttp-release.aar') // optional |
| 94 | +
|
| 95 | + // FileLogger's runtime dependencies must be declared here too — |
| 96 | + // AAR consumers don't get transitive dependencies via flat-file deps. |
| 97 | + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.1' |
| 98 | + implementation 'androidx.startup:startup-runtime:1.1.1' |
| 99 | + implementation 'androidx.lifecycle:lifecycle-process:2.8.7' |
| 100 | + implementation 'androidx.core:core-ktx:1.13.1' |
| 101 | +
|
| 102 | + // Required if you use :filelogger-okhttp: |
| 103 | + implementation 'com.squareup.okhttp3:okhttp:4.12.0' |
| 104 | +} |
| 105 | +``` |
| 106 | + |
| 107 | +**Caveats:** |
| 108 | +- The consumer must declare every runtime transitive dep manually (the AAR-via-`files()` route doesn't carry POM metadata). |
| 109 | +- Updates to FileLogger require rebuilding the AAR and re-copying. |
| 110 | +- `consumer-rules.pro` from the AAR is honored — your release build's R8/ProGuard will still see the library's keep rules. |
| 111 | + |
| 112 | +--- |
| 113 | + |
| 114 | +## Verifying the wire-up |
| 115 | + |
| 116 | +In the consumer's `Application.onCreate` (or anywhere on the main thread): |
| 117 | + |
| 118 | +```kotlin |
| 119 | +val config = fileLogger(applicationContext.filesDir.absolutePath) { |
| 120 | + defaultTag = "Consumer" |
| 121 | + minLevel = LogLevel.Debug |
| 122 | +} |
| 123 | +FileLogger.init(applicationContext, config) |
| 124 | +FileLogger.i(message = "FileLogger wired up") |
| 125 | +``` |
| 126 | + |
| 127 | +Run the app, then on the device: |
| 128 | + |
| 129 | +```bash |
| 130 | +adb shell run-as <your.consumer.package> ls files/fileLogs/ |
| 131 | +adb shell run-as <your.consumer.package> cat files/fileLogs/$(adb shell run-as <your.consumer.package> ls files/fileLogs/ | head -1) |
| 132 | +``` |
| 133 | + |
| 134 | +You should see a log file with the `FileLogger wired up` line. |
0 commit comments