I am looking to generate a second debug.apk in a different file location within the project path. Is it possible to create a second file path location for the .apk build within gradle?
The current build path is:
C:\..\app\build\outputs\apk\debug\debug.apk
I would like to create a second apk location after the build, for example:
C:\..\app\debug_apk\debug.apk
I am currently changing the names of the output files in gradle with:
applicationVariants.all { variant ->
variant.outputs.all { output ->
def appVersionName = "company_name_${versionName}"
switch (buildType.name) {
case "debug": {
outputFileName = "${appVersionName}_debug.apk"
break
}
case "release": {
outputFileName = "${appVersionName}_release.apk"
break
}
}
}
}
CodePudding user response:
apply plugin: 'android'
def outputPathName = "D:\build.apk"
def secondDir= "D:\backup\build.apk"
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
def publish = project.tasks.create("publishAll")
android.applicationVariants.all { variant ->
variant.outputFile = file(outputPathName)
def task = project.tasks.create("publish${variant.name}Apk", Copy)
task.from(variant.outputFile)
task.into(secondDir)
task.dependsOn variant.assemble
publish.dependsOn task
}
}
dependencies {
compile 'com.android.support:appcompat-v7:19. '
compile fileTree(dir: 'libs', include: ['*.jar'])
}
task cleanExtra(type: Delete) {
delete outputPathName
}
clean.dependsOn(cleanExtra)
This code is combination from this resource and this answer
CodePudding user response:
Try This Solution :
I am able to do it by running copy
script in gradle file
like this :
android.applicationVariants.all { variant ->
variant.outputs.all {
copy {
from file("${project.buildDir}/outputs/apk/" variant.name "/release/${outputFileName}")
into file("${project.buildDir}/outputs/apk/")
}
// i don't want apk on this location so after successful copy i am deleting it
delete file("${project.buildDir}/outputs/apk/" variant.name)
}
}