Different Release & Debug Config files depending on BuildType in Android Gradle

495 views Asked by At

I have an Android app which uses two different pairs of config files for release and debug build types. I am keeping all 4 files in app/extras directory as shown here:

/app/extras
  |- X-release
     X-debug
     Y-release
     Y-debug

Depending on which build type is selected, I want the corresponding X and Y files to be copied to /app and /app/src/main/assets directories respectively. For instance, if a release APK is being built, I want X-release to be copied under /app (and renamed to X), and Y-release to be copied under /app/src/main/assets (and renamed to Y).

I have been reading about the copy-file task in gradle, and I tried several different options, but none of my tasks seemed to do the job. Can you please tell me how I can write such tasks? I will also need to know where in the gradle file to place such tasks and where to call/use them (e.g. inside android {...}). Any help is greatly appreciated.

Keep in mind, doing this using gradle tasks is just my idea. I am not committed to this approach, and I am open to any alternative solution as long as X and Y files are copied under the right directories (I believe one solution for Y may be to place them under /app/src/main/debug/assets and /app/src/main/release/assets, but I doubt this will work for the X file).

0

There are 0 answers