Skip to content

Implementation

Efra Espada edited this page Apr 15, 2020 · 28 revisions

Plugin setup

The plugin looks for string resources for obfuscating at compilation time. Works globally in the project.

In the project's root-level:

buildscript {

    ext.stringcare_version = '4.0.0'

    repositories {
        jcenter()
        google()
        mavenCentral()
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }

    dependencies {
        classpath "com.stringcare:plugin:$stringcare_version"
        classpath 'com.android.tools.build:gradle:3.5.3'
    }
}

In app module:

apply plugin: 'com.android.application'
apply plugin: StringCare

// default config
stringcare {
    debug false
    assetsFiles = ["*.json"]
    stringFiles = ['strings.xml']
    srcFolders = ['src/main']
}

android {
    // any config

    compileOptions {
        sourceCompatibility 1.8
        targetCompatibility 1.8
    }
} 

dependencies {

    // The library reveals the obfuscated string resources generated
    // by the plugin and obfuscates and reveals strings at runtime:
    implementation "com.stringcare:library:$stringcare_version"
}

The plugin must work with the same version of the library.

Setup in code

The library needs the global application's context:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    SC.init(getApplicationContext());
}
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    SC.init { applicationContext }
}