将APK文件从build位置复制到gradle中的其他位置4.4 [英] Copy APK file from build location to some other location in gradle 4.4

查看:621
本文介绍了将APK文件从build位置复制到gradle中的其他位置4.4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

gradle 4.4 无法更改APK输出文件的路径,因此我们无法使用现在从docs获取apk输出的绝对路径 - 在构建时修改变体输出可能无法正常工作 ,所以我在SO上搜索并找到一个解决方案,我们可以将 apk 复制到我们的所需的位置后,它建立,但我没有太多的想法gradle脚本,我无法调用复制任务。谁能帮我。



代码来自我的gradle:

  android {
................
android.applicationVariants.all {variant - >
variant.outputs.all {
if(variant.name.contains(Release)){
outputFileName =$ {variant.name} - $ {variant.versionName} .apk
}
}
assembleRelease {
dependsOn copyDocs
}
} // end of android brace

任务copyApk(类型:复制){
from outputFileName
into file($ {project.buildDir} / outputs / apk)
}
}


$ b

从这种方式我得到错误:


无法获取未知属性'outputFileName'任务


任何想法如何将apk文件复制到另一个路径?感谢。

解决方案

  android.applicationVariants.all {variant  - > 
variant.outputs.all {
println variant.name
if(variant.name.contains(release)){
outputFileName = new File(../ ,$ {variant.name} - $ {variant.versionName} .apk)
println outputFileName
}
}
}

并删除

 任务copyApk 


As in gradle 4.4 it is not possible to change path of APK output file and we can't use absolute path for the apk's output now from the docs - Modifying variant outputs at build time may not work so I searched on SO and found a solution that we can copy apk to our desired location after it gets build but I don't have much idea on gradle scripting and i am not able to call copy task. Can anyone help me.

code from my gradle :

    android {
    ................
    android.applicationVariants.all { variant ->
    variant.outputs.all {
        if (variant.name.contains("Release")) {
             outputFileName = "${variant.name}-${variant.versionName}.apk"
        }
     }
     assembleRelease {
        dependsOn copyDocs
    }
    }// end of android brace

    task copyApk(type: Copy) {
    from outputFileName
    into file("${project.buildDir}/outputs/apk")
   }
  }

From this way i am getting error :

Could not get unknown property 'outputFileName' for task

Any idea how to copy apk file to another path? Thanks.

解决方案

android.applicationVariants.all { variant ->
    variant.outputs.all {
        println variant.name
        if (variant.name.contains("release")) {
            outputFileName = new File("../", "${variant.name}-${variant.versionName}.apk")
            println outputFileName
        }
    }
}

and remove

task copyApk

这篇关于将APK文件从build位置复制到gradle中的其他位置4.4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆