[英]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.