|
| 1 | +# Getting started |
| 2 | + |
| 3 | +## What is StringCare |
| 4 | + |
| 5 | +StringCare Android obfuscates string resources and asset files at **build time** (via a Gradle plugin) and reveals them at **runtime** in your app (via a small library). Sensitive strings never appear in plain text in your APK; the library uses the app signing certificate to derive a key and decrypt them. You add the plugin and library to your project, mark which strings and assets to obfuscate, and call `SC.reveal()` (or use `SCTextView`) where you need the plain value. |
| 6 | + |
| 7 | +## Prerequisites |
| 8 | + |
| 9 | +- **Gradle** 8.11 or later |
| 10 | +- **Android Gradle Plugin (AGP)** 8.7 or later |
| 11 | +- **Kotlin** 2.0 or later (or compatible Java) |
| 12 | +- **minSdk** 21 (Android 5.0) or higher |
| 13 | +- **targetSdk** 35 recommended |
| 14 | + |
| 15 | +## Add the library |
| 16 | + |
| 17 | +In your app module `build.gradle.kts`, add the runtime dependency: |
| 18 | + |
| 19 | +```kotlin |
| 20 | +dependencies { |
| 21 | + implementation("dev.vyp.stringcare:library:5.0.0") |
| 22 | +} |
| 23 | +``` |
| 24 | + |
| 25 | +Use the same version as the plugin (see below). For other build systems see [Installation](installation.md). |
| 26 | + |
| 27 | +## Apply the plugin |
| 28 | + |
| 29 | +In your **project** `settings.gradle.kts`, ensure plugin repositories are available: |
| 30 | + |
| 31 | +```kotlin |
| 32 | +pluginManagement { |
| 33 | + repositories { |
| 34 | + gradlePluginPortal() |
| 35 | + mavenCentral() |
| 36 | + google() |
| 37 | + } |
| 38 | +} |
| 39 | +``` |
| 40 | + |
| 41 | +In your **app** module `build.gradle.kts`, apply the plugin and add a minimal `stringcare` block: |
| 42 | + |
| 43 | +```kotlin |
| 44 | +plugins { |
| 45 | + id("com.android.application") |
| 46 | + id("org.jetbrains.kotlin.android") |
| 47 | + id("dev.vyp.stringcare.plugin") |
| 48 | +} |
| 49 | + |
| 50 | +stringcare { |
| 51 | + debug = false |
| 52 | + skip = false |
| 53 | + stringFiles = mutableListOf("strings.xml") |
| 54 | + srcFolders = mutableListOf("src/main") |
| 55 | + assetsFiles = mutableListOf() // add e.g. "*.json" if you obfuscate assets |
| 56 | +} |
| 57 | +``` |
| 58 | + |
| 59 | +## Obfuscate a string |
| 60 | + |
| 61 | +1. In `res/values/strings.xml` (or a file matched by `stringFiles`), add a string and mark it for obfuscation with `hidden="true"`: |
| 62 | + |
| 63 | +```xml |
| 64 | +<resources> |
| 65 | + <string name="api_key" hidden="true">my-secret-api-key</string> |
| 66 | +</resources> |
| 67 | +``` |
| 68 | + |
| 69 | +2. In your code, initialize StringCare with the application context (e.g. in `Application.onCreate()` or before first use): |
| 70 | + |
| 71 | +```kotlin |
| 72 | +import dev.vyp.stringcare.library.SC |
| 73 | + |
| 74 | +// In Application or Activity: |
| 75 | +SC.init(applicationContext) |
| 76 | +``` |
| 77 | + |
| 78 | +3. Reveal the string by resource ID or by value: |
| 79 | + |
| 80 | +```kotlin |
| 81 | +// By resource ID (typical for strings.xml) |
| 82 | +val apiKey = SC.reveal(R.string.api_key) |
| 83 | + |
| 84 | +// Or if you have the obfuscated value (e.g. from another source) |
| 85 | +val plain = SC.reveal(obfuscatedValue) |
| 86 | +``` |
| 87 | + |
| 88 | +The plugin will replace the plain text in `strings.xml` during the build with an obfuscated form; the library decrypts it at runtime using the app signing certificate. |
| 89 | + |
| 90 | +## Run the app |
| 91 | + |
| 92 | +Build and run your app as usual (`./gradlew assembleDebug` or Run from Android Studio). The first time you call `SC.reveal()`, the library uses the signing key (or the debug key when debugging) to reveal the string. Ensure you have called `SC.init(context)` before any `SC.reveal()` or `SCTextView` usage. |
| 93 | + |
| 94 | +For more options (assets, `SCTextView`, versions, and full configuration), see [Configuration](configuration.md) and [Library API](library-api.md). For detailed installation variants (Groovy, local build), see [Installation](installation.md). |
0 commit comments