Arun VS
Arun VS

Reputation: 51

Android studio gradle custom task with shell script is not working at build time

I have encrypted a file(API key,passwords etc), added in codebase. I need to add a custom task(task encIt) to decrypt the file(will call decrypt.sh to decrypt).This task is added in build.gradle file.

I have tested this by calling "gradle encIt" from terminal and it works fine(decrypting the file as expected), But I need this to be happened every time I build the gradle; how to do that?

This is the task:

     task encIt(type:Exec) {
       println("WORKING")
       commandLine "./decrypt.sh"
       println("WORKING")
     }

This is the script file :

   #!/usr/bin/env sh
   echo "inside working"
   openssl enc -aes-256-cbc -d  -in ../encrypted.key   -out  key.txt                     -pass pass:Abcdk5551
  echo "inside working"

I have tested this

senario 1:gradle encIt

 result : WORKING
          inside working
          inside working
          WORKING
   The file is decrypted

senario 1:gradle/gradlew (no arguments)

 result : WORKING
          WORKING
   The file is not getting decrypted

please help!

using gradle version 5.4.1 macbook pro android studio 3.4.1

Upvotes: 2

Views: 314

Answers (1)

andforce
andforce

Reputation: 145

editapp/build.gradle,add below code

task encIt(type:Exec) {
    println("WORKING")
    commandLine "./decrypt.sh"
    println("WORKING")
}

afterEvaluate {
    assembleDebug.dependsOn encIt
    assembleRelease.dependsOn encIt
}

It's worked with:

  1. click run button which on Android Studio
  2. run ./gradlew build
  3. run ./gradlew assemble
  4. run ./gradlew assembleDebug
  5. run ./gradlew assembleRelease

Upvotes: 2

Related Questions