android studio模塊化之一:版本管理

項目模塊多了,andoid sdk版本以及各類以來包的版本若是都放在各自的模塊中,維護很麻煩,並且容易形成不一致,因此須要統必定義,各個模塊只須要引用便可。 有三種地方能夠定義:java

1、項目根目錄下的gradle.properties中定義,參考Android-ScalableVideoViewandroid

VERSION_NAME=1.0.0
VERSION_CODE=1
GROUP=com.yqritc
ARTIFACT_ID=android-scalablevideoview

COMPILE_SDK_VERSION=23.0.1
BUILD_TOOLS_VERSION=23.0.1
TARGET_SDK_VERSION=23.0.1
MIN_SDK_VERSION=14

POM_DESCRIPTION=Android texture video view having a variety of scale types
POM_URL=https://github.com/yqritc/Android-ScalableVideoView
POM_SCM_URL=git@github.com:yqritc/Android-ScalableVideoView.git
POM_SCM_CONNECTION=scm:git@github.com:yqritc/Android-ScalableVideoView.git
POM_SCM_DEV_CONNECTION=scm:git@github.com:yqritc/Android-ScalableVideoView.git
POM_LICENCE_NAME=The Apache Software License, Version 2.0
POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
POM_LICENCE_DIST=repo
POM_DEVELOPER_ID=yqritc
POM_DEVELOPER_NAME=yqritc
POM_DEVELOPER_EMAIL=yqritc@gmail.com
ISSUE_URL=https://github.com/yqritc/Android-ScalableVideoView/issues

引用方式git

android {
    compileSdkVersion COMPILE_SDK_VERSION as int
    buildToolsVersion BUILD_TOOLS_VERSION

    defaultConfig {
        minSdkVersion MIN_SDK_VERSION as int
        targetSdkVersion TARGET_SDK_VERSION as int
        versionCode VERSION_CODE as int
        versionName VERSION_NAME
    }
}

2、在根目錄的build.gradle中定義,參考mvp-mosbygithub

ext {
  minSdk = 14
  targetSdk = 23
  buildToolsVersion = '23.0.1'
  compileSdkVersion = 23

  javaSourceCompatibility = JavaVersion.VERSION_1_7
  javaTargetCompatibility = JavaVersion.VERSION_1_7

  // Libraries
  appcompat7Version = '23.1.1'
  supportAnnotations = '23.1.1'
  recyclerviewVersion = '23.1.1'

  // Libraries for samples
  fragmentargsVersion = '2.1.0'
  butterknifeVersion = '7.0.1'
  icepickVersion = '3.0.2'
  retrofitVersion = '1.9.0'
  picassoVersion = '2.5.2'
  okhttpVersion ='2.3.0'
  parcelablepleaseVersion = '1.0.1'
  annotatedadapterVersion = '1.1.1.1-SNAPSHOT'
  rxjavaVersion = '1.0.16'
  rxandroidVersion = '1.0.1'
  dagger2Version = '2.0'

  // Test Libs
  robolectricVersion = '3.0'
  junitVersion = '4.12'
  mockitoVersion = '2.0.5-beta'
  powermockVersion = '1.6.2'
  leakcanaryVersion = '1.3.1'
}

引用方式apache

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

  compileOptions {
    sourceCompatibility rootProject.ext.javaSourceCompatibility
    targetCompatibility rootProject.ext.javaTargetCompatibility
  }

  defaultConfig {
    applicationId "com.hannesdorfmann.mosby.sample"
    minSdkVersion rootProject.ext.minSdk
    targetSdkVersion rootProject.ext.targetSdk
    versionName project.VERSION_NAME
    versionCode Integer.parseInt(project.VERSION_CODE)
  }
  buildTypes {
    release {
      minifyEnabled false
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
  }
}

dependencies {
  compile 'com.android.support:design:'+ rootProject.ext.appcompat7Version
  compile 'com.android.support:recyclerview-v7:'+               rootProject.ext.recyclerviewVersion
  compile 'com.android.support:appcompat-v7:' + rootProject.ext.appcompat7Version
}

3、GRADLE依賴的統一管理app

相關文章
相關標籤/搜索