快速配置Android项目里版本信息
在项目根目录创建配置文件version.gragle,加入以下内容:
def androidSupportVersion = '26.0.0' def androidConstraintLayout = '1.0.2' ext { versionCode = 1 versionName = "1.0" compileSdkVersion = 26 buildToolsVersion = "26.0.1" minSdkVersion = 16 targetSdkVersion = 26 appcompatV7 = "com.android.support:appcompat-v7:$androidSupportVersion" design = "com.android.support:design:$androidSupportVersion" constraintLayout = "com.android.support.constraint:constraint-layout:$androidConstraintLayout" } allprojects { repositories { jcenter() maven { url "https://maven.google.com"//以后的sdk都要从google自己的maven仓库中获取 } } }
在根目录的build.gradle文件中引入刚创建的配置文件,在文件顶部加入以下内容:
apply from:'version.gradle'
在具体Module的build.gradle文件中通过如下方式来使用刚定义好的版本信息:
android { compileSdkVersion getProject().compileSdkVersion buildToolsVersion getProject().buildToolsVersion defaultConfig { applicationId "com.tedxiong.android" minSdkVersion getProject().minSdkVersion targetSdkVersion getProject().targetSdkVersion versionCode getProject().versionCode versionName getProject().versionName testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" externalNativeBuild { cmake { cppFlags "-frtti -fexceptions" } } ndk { // Specifies the ABI configurations of your native // libraries Gradle should build and package with your APK. abiFilters 'armeabi-v7a' } } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } externalNativeBuild { cmake { path 'CMakeLists.txt' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile getProject().appcompatV7 compile getProject().constraintLayout compile getProject().design testCompile 'junit:junit:4.12' }
本作品由TedXiong采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可。