2

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

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.