简体   繁体   English

Android Gradle - 是否仅在发布时使用拆分?

[英]Android Gradle - is use splits only for release possible?

I want use "splits" by "abi", but only for release build. 我希望“abi”使用“splits”,但仅限于发布版本。 Is this possible? 这可能吗? I try use ext variable and variable by "def" also which is set to false by default. 我尝试使用ext变量和变量“def”也默认设置为false。 This variable is set to true in buildTypes for releaseWithLog (and release). 对于releaseWithLog(和release),此变量在buildTypes中设置为true。

But I don't know how Gradle work, because when I add writeln() with test message to "debug", "releaseWithLog" and "release" and run build, all messages are in output, so this confirms me that variable "splitsEnabled" is set to true though I build for debug - and I expect value "false" for debug (and not using splits for debug therefore). 但是我不知道Gradle是如何工作的,因为当我将带有测试消息的writeln()添加到“debug”,“releaseWithLog”和“release”并运行build时,所有消息都在输出中,所以这确认了变量“splitsEnabled” “虽然我为调试构建了,但是设置为true - 我希望调试的值为”false“(因此不使用拆分进行调试)。

apply plugin: 'com.android.application'

android {
    compileSdkVersion 19
    buildToolsVersion '20.0.0'
    ext {
        splitsEnabled = false
    }
    defaultConfig {
    ...
    }
    buildTypes {
        debug {
            ...
        }
        releaseWithLog {
            ...
            splitsEnabled = true
        }
        release.initWith(releaseWithLog)
        release {
            ...
        }
    }
    ...
    splits {
        abi {
            println(splitsEnabled)
            enable splitsEnabled
            reset()
            include 'x86', 'armeabi-v7a', 'armeabi'
            exclude 'x86_64', 'mips64', 'arm64-v8a', 'mips'
            universalApk true
        }
    }
    ... 

You can solve this easily with a command line argument to Gradle, or the "Script parameters:" field for a Gradle task in Android Studio. 您可以使用Gradle的命令行参数或Android Studio中Gradle任务的“脚本参数:”字段轻松解决此问题。 I used -P to define 'dbgBld' symbol and used it for debug builds, eg: 我使用-P来定义'dbgBld'符号并将其用于调试构建,例如:

gradle -PdbgBld installDebug

My build.gradle file has the following splits command: 我的build.gradle文件有以下splits命令:

splits {
    abi {
        enable !project.hasProperty('dbgBld')
        reset()
        include 'armeabi', 'armeabi-v7a', 'x86', 'mips'
        universalApk true
    }
}

Now to build release I use: 现在构建版本我使用:

gradle assembleRelease

The 'dbgBld' symbol is not defined, so the splits enable field resolves to true and I get 5 APK files. 'dbgBld'符号未定义,因此splits enable字段解析为true,我得到5个APK文件。 When building for debugging, the -PdbgBld is already saved in my Android Studio configuration and I get only one "fat" APK for debugging, which results in much faster debug builds. 在构建调试时,-PdbgBld已经保存在我的Android Studio配置中,并且我只获得一个“胖”APK用于调试,这导致更快的调试构建。

Greg 格雷格

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM