2

Android release apk is created in

...\Foo\Foo\build\outputs\apk\release\foo.apk

how can I change this path?

I want to save my apk for some projects in specific path.

Is this possible ?

Umar Hussain
  • 3,461
  • 1
  • 16
  • 38
Arda Kaplan
  • 1,720
  • 1
  • 15
  • 23

1 Answers1

0

Yes this is possible. you can set where your apk is to be generated, in your Project level build.gradle add the path you need inside allprojects :

allprojects {
    buildDir = "/D:/Foo/Bar/Android/Build/"
    ...
}

This will create your apk alongwith the generated, intermediates, temp etc. folders inside the Build folder in the specified path. If you wish to have it generated in a folder with the Project Name etc use:

buildDir = "/D:/Foo/Bar/Android/Build/${rootProject.name}/${project.name}"

For more reference you can check this answer.

UPDATE: I couldn't find any way to directly generate the release apk into some specific folder, But if its ok to save a copy of this apk into another folder you can achieve this using gradle's Copy task. In your APP level gradle you can try the below code I tested out.

afterEvaluate {
    // to execute the copy task every time a release build is generated
    packageRelease.finalizedBy(copyRelease)
}

task copyRelease(type: Copy) {
    // set your paths here
    def sourcePath = file ("/release/app-release.apk").absolutePath
    def destinationPath = "/D:/Foo/Bar/Android/Build/"
    // set a name for your build if you are going to rename it
    def releaseName = "${rootProject.name}.apk"

    from "$sourcePath"
    into "$destinationPath"
    //use the below line if you wish to rename the apk
    rename { releaseName }
}

Even though it suggested to add this inside android {...} block simply adding it outside seems to work. So even though apk doesn't get directly generated to your folder the task does copy the same to save it into the folder of your choice.

Incase you need it for debug builds, use packageDebug instead and change your paths accordingly.

Hope this is what you were looking for.

ljk
  • 1,496
  • 1
  • 11
  • 14
  • This will create all folders like you said ( generated, intermediates, temp etc. folders). I have tried this solution but i want to only apk file. – Arda Kaplan Feb 26 '20 at 06:10
  • Have updated my answer with a method to save a copy of release apk into some folder. See if it works for you. @Umar's comment with the [gist link](https://gist.github.com/shakalaca/6422811) seems a bit outdated but does point in the right direction – ljk Feb 27 '20 at 10:20