简体   繁体   English

在android / gradle projects项目root build.gradle中指定versionCode

[英]Specify versionCode in android/gradle projects project root build.gradle

I recently switched from Eclipse to Android Studio (for test purposes) with an production project and it feel really great. 我最近使用生产项目从Eclipse切换到Android Studio(用于测试目的),感觉非常棒。 I like the gradle way very much. 我非常喜欢gradle方式。

In Android Studio the project structure looks (simplified) something like this 在Android Studio中,项目结构看起来(简化)类似于此

+RandomProject
|-+Random
| |- build.gradle (lets call it build2)
| |- [...]
|- build.gradle (lets call it build1)
|- [..]

The build1 file has the following content by default: build1文件默认具有以下内容:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

I wonder if its possible/a good practice to specify the versionName and versionCode in that ( build1 ) file, so that it is going to be "inherited" to the build2 file. 我想知道在( build1 )文件中指定versionName和versionCode是否可能/一个好的做法,以便它将“继承”到build2文件。 (and if so, how?) (如果是的话,怎么样?)

Thanks for the input. 感谢您的投入。

You can do it with ExtraPropertiesExtension . 您可以使用ExtraPropertiesExtension来完成

RandomProject\\build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.
ext.compileSdkVersion=19
ext.buildToolsVersion="19"
ext.versionName="1.0.7"
ext.versionCode=7

RandomProject\\Random\\build.gradle

android {

    compileSdkVersion rootProject.compileSdkVersion
    buildToolsVersion rootProject.buildToolsVersion

    defaultConfig {
        versionName rootProject.versionName
        versionCode rootProject.versionCode
    }
}

The New Build System site now has a tip about this. New Build System网站现在有一个关于此的提示。 It's similar to Sergii's answer, but subtly different: 它类似于Sergii的答案,但略有不同:

In the root project's build.gradle: 在根项目的build.gradle中:

ext {
  compileSdkVersion = 19
  buildToolsVersion = "19.0.1"
}

in all the android modules: 在所有的android模块中:

android {
  compileSdkVersion rootProject.ext.compileSdkVersion
  buildToolsVersion rootProject.ext.buildToolsVersion
}

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

相关问题 更改Android versionCode会导致build.gradle错误 - Changing Android versionCode causes build.gradle error 错误:build.gradle.kts 中的“未解决的参考:versionCode” - Error: "Unresolved reference: versionCode" in build.gradle.kts Cordova Android构建版本与Gradle的代码 - Cordova Android build versionCode with Gradle Android gradle:多项目构建,顶级build.gradle - Android gradle: Multi project build, top level build.gradle 如何为所有新项目配置项目级别的 build.gradle? - How to configure the project level build.gradle for all new projects? 从Module中的build.gradle中删除项目根目录中的文件夹 - Delete a folder in project root from build.gradle in Module 为什么在build.gradle中有针对Android项目的自定义“干净”任务? - Why is there a custom 'clean' task in build.gradle for Android projects? Android studio Bumblebee build.gradle根项目无法添加classpath依赖 - Android studio Bumblebee build.gradle root project can't add classpath dependencies 如何在build.gradle中为Android应用程序指定支持的体系结构? - How to specify supported architectures for android app in build.gradle? 在build.gradle文件android studio中指定.so文件 - specify .so files in build.gradle file android studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM