How to specify output .apk file path when using fastlane gradle?
Asked Answered
H

4

6

I have different product flavors of my app and I build them with fastlane. This is my fastfile:

default_platform(:android)

platform :android do

  desc "Release apk with different urls"
  lane :release do
    gradle(
      task: "assemble",
      build_type: "release",
      flavor: "flavorname",
      print_command: true,
      properties: {
        "android.injected.signing.store.file" => "Key.jks",
        "android.injected.signing.store.password" => "KeyPass",
        "android.injected.signing.key.alias" => "KeyAlias",
        "android.injected.signing.key.password" => "KeyPass"
      }
    )

  end

end

The problem is apk files are created in project directory.

(projectname/app/build/outputs/apk/flavorname/release/app-flavorname-release.apk)

How to move this apk files to my Desktop automatically?

Hayseed answered 19/11, 2018 at 14:29 Comment(0)
C
4

It doesn't seem that gradle has an option to specify the output. What I suggest you is to add a command line just after the gradle is done to move this .apk to the Desktop or wherever you want.

sh "mv ../app/build/outputs/apk/release/app-release.apk path/to/Desktop"
Crepe answered 19/11, 2018 at 15:5 Comment(1)
Note that you can also get the path of the generated APK automatically with the environment variable / shared value GRADLE_APK_OUTPUT_PATH. Then you don't even have to hardcode the apk path (and filename).Culosio
S
12

I use the following under my gradle call:

lane :release do        
    gradle(...)

    APK_LOCATION = "#{lane_context[SharedValues::GRADLE_APK_OUTPUT_PATH]}"        
    sh("mv #{APK_LOCATION} ~/Desktop/")
end

The advantage of using the variable is that you will be able to use the same code for release and debug apk.

Cheers.

Selfrevealing answered 14/1, 2019 at 17:45 Comment(1)
For me the GRADLE_ALL_APK_OUTPUT_PATHS is always emptyNegrophobe
C
4

It doesn't seem that gradle has an option to specify the output. What I suggest you is to add a command line just after the gradle is done to move this .apk to the Desktop or wherever you want.

sh "mv ../app/build/outputs/apk/release/app-release.apk path/to/Desktop"
Crepe answered 19/11, 2018 at 15:5 Comment(1)
Note that you can also get the path of the generated APK automatically with the environment variable / shared value GRADLE_APK_OUTPUT_PATH. Then you don't even have to hardcode the apk path (and filename).Culosio
B
3

You can also use fastlane action copy_artifacts instead of mv

lane :release do
  gradle(...)

  copy_artifacts(
    artifacts: ['*/build/outputs/apk/**/*.apk'],
    target_path: '~/Desktop/'
  )
end

Wilcard */build/outputs/apk/**/*.apk will work with any build types, flavors app module name.

Or as said @janpio above, you can use variable GRADLE_APK_OUTPUT_PATH:

lane :release do
  gradle(...)

  copy_artifacts(
    artifacts: [lane_context[SharedValues::GRADLE_APK_OUTPUT_PATH]],
    target_path: '~/Desktop/'
  )
end
Blither answered 18/6, 2019 at 13:30 Comment(0)
A
0

You can add like archivesBaseName in properties. And output is app-release.apk

lane :release do
      build_android_app(
        task: "assemble",
        build_type: "Release",
        print_command: false,
        properties: {
          "android.injected.signing.store.file" => "Key.jks",
        "android.injected.signing.store.password" => "KeyPass",
        "android.injected.signing.key.alias" => "KeyAlias",
        "android.injected.signing.key.password" => "KeyPass",
         "archivesBaseName" => "app",

        }
      )
Aalto answered 18/12, 2023 at 4:33 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.