Use different VersionCode for Debug/Release android gradle build

前端 未结 6 1680
感动是毒
感动是毒 2020-12-15 07:30

I\'d like to apply different VersionCode to make apk file. For debug only fix it to 1, and for release whatever number specified in defaultConf

6条回答
  •  庸人自扰
    2020-12-15 08:01

    So recently I had to deal with the same scenario and all the examples I could find use the applicationVariants property which is ill-documented imo.

    So after some digging through the source code a bit, I realized that in the end versionCode and versionName properties from ProductFlavor get merged into the AndroidManifest which got me thinking: couldn't we just inject them by ourselves, cause we have manifestPlaceholders property on ProductFlavor AND on BuildType DSL objects, so I came up with this -- don't hesitate to give feedback and tell me why it's wrong

    In build.gradle(app)

    android {
        ...
        buildTypes {
            debug {
                manifestPlaceholder = [versionCode: X, versionName: "X.Y.Z"]
            }
            release {
                manifestPlaceholder = [versionCode: A, versionName: "A.B.C"]
            }
        }
        ...
    }
    

    In AndroidManifest.xml

    
        ...
    
    

提交回复
热议问题