相关疑难解决方法(0)

在Android Gradle项目中复制APK文件

我正在尝试将自定义任务添加到我的Android项目中,build.gradle以将最终的APK和Proguard复制mapping.txt到另一个目录中.我的任务取决于assembleDevDebug任务:

task publish(dependsOn: 'assembleDevDebug') << {
    description 'Copies the final APK to the release directory.'

    ...
}
Run Code Online (Sandbox Code Playgroud)

Copy根据文档,我可以看到如何使用标准任务类型执行文件复制:

task(copy, type: Copy) {
    from(file('srcDir'))
    into(buildDir)
}
Run Code Online (Sandbox Code Playgroud)

但这假设您知道要复制的文件的名称和位置.

如何找到作为assembleDevDebug任务一部分构建的APK文件的确切名称和位置?这可以作为财产吗?感觉好像我应该能够将文件声明为我的任务的输入,并将它们声明为assemble任务的输出,但我的Gradle-fu不够强大.

我有一些自定义逻辑将版本号注入APK文件名,所以我的publish任务不能只假设默认名称和位置.

android gradle android-gradle-plugin

43
推荐指数
4
解决办法
1万
查看次数

Gradle警告:不推荐使用variant.getOutputFile()和variant.setOutputFile()

我在Android应用程序项目中使用以下简化配置.

android {
    compileSdkVersion 20
    buildToolsVersion "20.0.0"

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 20
        versionCode 1
        versionName "1.0.0"

        applicationVariants.all { variant ->
            def file = variant.outputFile
            def fileName = file.name.replace(".apk", "-" + versionName + ".apk")
            variant.outputFile = new File(file.parent, fileName)
        }
    }    
}
Run Code Online (Sandbox Code Playgroud)

现在我将Gradle插件更新到v.0.13.0并将Gradle更新到v.2.1.出现以下警告:

WARNING [Project: :MyApp] variant.getOutputFile() is deprecated. 
    Call it on one of variant.getOutputs() instead.
WARNING [Project: :MyApp] variant.setOutputFile() is deprecated. 
    Call it on one of variant.getOutputs() instead.
WARNING [Project: :MyApp] variant.getOutputFile() is deprecated. 
    Call it on one of …
Run Code Online (Sandbox Code Playgroud)

android gradle build.gradle deprecation-warning

33
推荐指数
3
解决办法
1万
查看次数