christopherney / Enigma

Gradle Plugin - Obfuscator String Encryption (Android/Java)
MIT License
159 stars 25 forks source link

Plugin not applying to modules except app even if the build.gradle of the module has plugin entry #10

Open deshant opened 3 years ago

deshant commented 3 years ago

I have added this plugin to a project which has 2 modules, one app and another library type.

The plugin is only accessing app module, and not the library module, even though the plugin was added to library's build.gradle by specifying: apply plugin: 'com.chrisney.enigma' and enigma.enabled = true .

Project level build.gradle:

buildscript {

    repositories {
        google()
        jcenter()
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.3'

        classpath 'com.google.gms:google-services:4.3.3'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files

        classpath 'gradle.plugin.chrisney:enigma:1.0.0.8'
    }
}

library's module level build.gradle:

apply plugin: 'com.android.library'
apply plugin: 'com.chrisney.enigma'

enigma.enabled = true

android {
    compileSdkVersion 29

    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 6
        versionName "3.3"

//        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    def room_version = "2.2.5"

    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation "androidx.work:work-runtime:2.4.0"
    implementation "com.google.code.gson:gson:2.8.6"

    //room
    implementation "android.arch.persistence.room:runtime:$room_version"
    annotationProcessor "android.arch.persistence.room:compiler:$room_version"
    testImplementation "android.arch.persistence.room:testing:$room_version"

    testImplementation 'junit:junit:4.13.1'
//    androidTestImplementation 'androidx.test:runner:1.3.0-rc01'
//    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0-rc01'
}

app module's build.gradle was not changed.

When running assemble, I can see the app's java files getting encrypted but not the module's:

11:57:12: Executing task 'assemble'...

Executing tasks: [assemble] in project E:\xxxxxxx\xxxxxxxxx\xxxxx   // masking personal info here

> Task :app:preBuild UP-TO-DATE
> Task :app:preDebugBuild UP-TO-DATE

> Task :<library module's name here>:backup                                  // masking personal info here
? Backup: \app\src\main\java\xxx\xxx\xxx\MainActivity.java
? Backup: \app\src\main\java\xxx\xxx\xxx\MyFirebaseMessagingService.java

> Task :<library module's name here>:encrypt
? MainActivity.java encrypted
? MyFirebaseMessagingService.java encrypted

> Task :<library module's name here>:injectCode
?? Add Enigma code

> Task :<library module's name here>:preBuild
> Task :<library module's name here>:extractProguardFiles UP-TO-DATE
> Task :<library module's name here>:preDebugBuild
.
. // skipping generic tasks
.
> Task :<library module's name here>:verifyReleaseResources UP-TO-DATE
> Task :<library module's name here>:assembleRelease UP-TO-DATE

> Task :<library module's name here>:restore
?? Restore: \app\src\main\java\xxx\xxx\xxx\MainActivity.java
?? Restore: \app\src\main\java\xxx\xxx\xxx\MyFirebaseMessagingService.java
? Remove Enigma code: E:\xxxxxxxxxx\xxxxxxxx\xxxxxxxx\app\src\main\java\com\chrisney\enigma

> Task :<library module's name here>:assemble UP-TO-DATE
> Task :app:mergeReleaseJavaResource
> Task :app:transformClassesAndResourcesWithR8ForRelease
> Task :app:packageRelease
> Task :app:assembleRelease
> Task :app:assemble

Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.4.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 1m 19s
115 actionable tasks: 61 executed, 54 up-to-date
11:58:32: Task execution finished 'assemble'.

project's settings.gradle:

include ':app', ':<library module name here>'

Can you check if this plugin can only support app module and not additional modules in same project?

deshant commented 3 years ago

Found the way to handle this, but I would call it a workaround for now as a multi-module app will have multiple src folders.

To apply the plugin to another module instead of app specify enigma.srcJava = "/<module>/src/main/java/" in build.gradle next to enigma.enabled = true.

Will leave this issue open for now till the developer provides a better way to specify multiple modules within same project.

SummerMineJack commented 3 years ago

Is it added in build.gradle in the library? I did it to no avail