android - 调试时 Gradle Android studio 输出文件夹

标签 android android-gradle-plugin build.gradle run-configuration

我正在尝试根据调试或 Release模式设置目标文件夹。但我并没有真正成功。对于调试和发布,它总是转到调试文件夹。如果我删除调试配置,那么它会转到发布文件夹,但它们都是(发布和调试)。

我想我必须修改运行配置,但我不确定该怎么做。

有什么帮助吗?

渐变文件:

android {
    compileSdkVersion 19
    buildToolsVersion "19.1.0"

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 19
        versionCode 18
        versionName "0.70"
    }
    signingConfigs {
        release {
            storeFile file("xxxx")
            storePassword "xxxx"
            keyAlias "xxx"
            keyPassword "xxxx"
        }
    }
    buildTypes {
        release {
            signingConfig signingConfigs.release
            applicationVariants.all { variant ->
                def file = variant.outputFile
                variant.outputFile = new File("C:\\PATH_TO_FOLDER\\release", "name" + defaultConfig.versionName + ".apk")
            }
        }
        debug {
            applicationVariants.all { variant ->
                def file = variant.outputFile
                variant.outputFile = new File("C:\\PATH_TO_FOLDER\\debug", "name_DEBUG_" + defaultConfig.versionName + ".apk")
            }
        }

    }

}

最佳答案

好吧……我想通了。

不确定这是否是最佳解决方案,但我检查了构建类型的名称,然后根据它设置了输出文件夹。

buildTypes {
        release {
            signingConfig signingConfigs.release

        }
        applicationVariants.all { variant ->
            def file = variant.outputFile
            println "Build info: $variant.buildType"
            if (variant.buildType.name=="release") {
                println "Release mode"
                variant.outputFile = new File("C:\\PATH_TO_FOLDER\\verify", "app" + defaultConfig.versionName + ".apk")
            } else {
                variant.outputFile = new File("C:\\PATH_TO_FOLDER\\debug", "app_DEBUG_" + defaultConfig.versionName + ".apk")
            }
        }

    }

关于android - 调试时 Gradle Android studio 输出文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24363850/

相关文章:

Android:没有匹配的 ABI

android - Gradle 升级 - 创建 apk 时缺少 base.apk 代码

android - Gradle Sync失败:没有这样的属性:Gradle版本对于类:JetGradlePlugin

Android Studio Gradle 构建 "apply plugin: ' com.android.library'": aar missing files

android - 组织.gradle.api.tasks.TaskExecutionException : Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'

android - 如何撤消 Android 开关中的点击?

android - RecyclerView 不会立即显示任何内容

android - 从应用程序 android 打开当前正在进行的通话

android - 如何将pdf转换为图像?

android - 将依赖项添加到模块 - 外部库错误