Browse Source

统一管理项目的各个组件gradle配置

guiying712 9 years ago
parent
commit
0584063d8d
5 changed files with 107 additions and 24 deletions
  1. 23 8
      Common/build.gradle
  2. 35 10
      Girls/build.gradle
  3. 37 2
      build.gradle
  4. 9 1
      gradle.properties
  5. 3 3
      settings.gradle

+ 23 - 8
Common/build.gradle

@@ -1,16 +1,16 @@
 apply plugin: 'com.android.library'
 apply plugin: 'com.android.library'
 
 
 android {
 android {
-    compileSdkVersion 25
-    buildToolsVersion "25.0.2"
+    compileSdkVersion rootProject.ext.compileSdkVersion
+    buildToolsVersion rootProject.ext.buildToolsVersion
 
 
     defaultConfig {
     defaultConfig {
-        minSdkVersion 15
-        targetSdkVersion 25
-        versionCode 1
-        versionName "1.0"
-
+        minSdkVersion rootProject.ext.minSdkVersion
+        targetSdkVersion rootProject.ext.targetSdkVersion
+        versionCode rootProject.ext.versionCode
+        versionName rootProject.ext.versionName
     }
     }
+
     buildTypes {
     buildTypes {
         release {
         release {
             minifyEnabled false
             minifyEnabled false
@@ -21,5 +21,20 @@ android {
 
 
 dependencies {
 dependencies {
     compile fileTree(dir: 'libs', include: ['*.jar'])
     compile fileTree(dir: 'libs', include: ['*.jar'])
-    compile 'com.android.support:appcompat-v7:25.1.0'
+    //Android Support
+    compile "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"
+    compile "com.android.support:design:$rootProject.supportLibraryVersion"
+    compile "com.android.support:percent:$rootProject.supportLibraryVersion"
+    //网络请求相关
+    compile "com.squareup.retrofit2:retrofit:$rootProject.retrofitVersion"
+    compile "com.squareup.retrofit2:retrofit-mock:$rootProject.retrofitVersion"
+    compile "com.github.franmontiel:PersistentCookieJar:$rootProject.cookieVersion"
+    //稳定的
+    compile "com.github.bumptech.glide:glide:$rootProject.glideVersion"
+    compile "com.orhanobut:logger:$rootProject.loggerVersion"
+    compile "org.greenrobot:eventbus:$rootProject.eventbusVersion"
+    compile "com.google.code.gson:gson:$rootProject.gsonVersion"
+    //不稳定的
+    compile "com.github.mzule.activityrouter:activityrouter:$rootProject.routerVersion"
+    compile "com.jude:easyrecyclerview:$rootProject.easyRecyclerVersion"
 }
 }

+ 35 - 10
Girls/build.gradle

@@ -1,26 +1,51 @@
-apply plugin: 'com.android.application'
+println isModule.toBoolean()
+if (isModule.toBoolean()) {
+    apply plugin: 'com.android.application'
+} else {
+    apply plugin: 'com.android.library'
+}
+
+apply plugin: 'com.neenbedankt.android-apt'
 
 
 android {
 android {
-    compileSdkVersion 25
-    buildToolsVersion "25.0.2"
+    compileSdkVersion rootProject.ext.compileSdkVersion
+    buildToolsVersion rootProject.ext.buildToolsVersion
 
 
     defaultConfig {
     defaultConfig {
-        applicationId "com.guiying.girls"
-        minSdkVersion 15
-        targetSdkVersion 25
-        versionCode 1
-        versionName "1.0"
-
+        minSdkVersion rootProject.ext.minSdkVersion
+        targetSdkVersion rootProject.ext.targetSdkVersion
+        versionCode rootProject.ext.versionCode
+        versionName rootProject.ext.versionName
     }
     }
+
     buildTypes {
     buildTypes {
         release {
         release {
             minifyEnabled false
             minifyEnabled false
             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
         }
         }
     }
     }
+
+    sourceSets {
+        main {
+            if (isModule.toBoolean()) {
+                Manifest.srcFile 'src/main/debug/AndroidManifest.xml'
+            } else {
+                Manifest.srcFile 'src/main/release/AndroidManifest.xml'
+                //release模式下排除debug文件夹中的所有Java文件
+                java {
+                    exclude 'debug/**'
+                }
+            }
+        }
+    }
+    //设置了resourcePrefix值后,所有的资源名必须以指定的字符串做前缀,否则会报错。
+    //但是resourcePrefix这个值只能限定xml里面的资源,并不能限定图片资源,所有图片资源仍然需要手动去修改资源名。
+    //resourcePrefix "girls_"
 }
 }
 
 
 dependencies {
 dependencies {
     compile fileTree(dir: 'libs', include: ['*.jar'])
     compile fileTree(dir: 'libs', include: ['*.jar'])
-    compile 'com.android.support:appcompat-v7:25.1.0'
+    compile project(':common')
+    //router
+    apt "com.github.mzule.activityrouter:compiler:$rootProject.aptCompilerVersion"
 }
 }

+ 37 - 2
build.gradle

@@ -3,10 +3,12 @@
 buildscript {
 buildscript {
     repositories {
     repositories {
         jcenter()
         jcenter()
+        mavenCentral()
     }
     }
-    dependencies {
-        classpath 'com.android.tools.build:gradle:2.2.2'
 
 
+    dependencies {
+        classpath "com.android.tools.build:gradle:$localGradlePluginVersion"
+        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
         // NOTE: Do not place your application dependencies here; they belong
         // NOTE: Do not place your application dependencies here; they belong
         // in the individual module build.gradle files
         // in the individual module build.gradle files
     }
     }
@@ -15,9 +17,42 @@ buildscript {
 allprojects {
 allprojects {
     repositories {
     repositories {
         jcenter()
         jcenter()
+        mavenCentral()
+        //Add the JitPack repository
+        maven { url "https://jitpack.io" }
+        //支持arr包
+        flatDir {
+            dirs 'libs'
+        }
     }
     }
 }
 }
 
 
 task clean(type: Delete) {
 task clean(type: Delete) {
     delete rootProject.buildDir
     delete rootProject.buildDir
 }
 }
+
+// Define versions in a single place
+ext {
+    // Sdk and tools
+    buildToolsVersion = localBuildToolsVersion
+    compileSdkVersion = 25
+    minSdkVersion = 15
+    targetSdkVersion = 25
+    versionCode = 1
+    versionName = "1.0"
+    javaVersion = JavaVersion.VERSION_1_8
+
+    // App dependencies version
+    supportLibraryVersion = "25.1.0"
+    retrofitVersion = "2.1.0"
+    glideVersion = "3.7.0"
+    loggerVersion = "1.15"
+    eventbusVersion = "3.0.0"
+    gsonVersion = "2.8.0"
+
+    //不成熟开源库,需经常检查升级版本
+    aptCompilerVersion = "1.1.7"
+    routerVersion = "1.2.1"
+    easyRecyclerVersion = "4.3.4"
+    cookieVersion = "v1.0.0"
+}

+ 9 - 1
gradle.properties

@@ -14,4 +14,12 @@ org.gradle.jvmargs=-Xmx1536m
 # When configured, Gradle will run in incubating parallel mode.
 # When configured, Gradle will run in incubating parallel mode.
 # This option should only be used with decoupled projects. More details, visit
 # This option should only be used with decoupled projects. More details, visit
 # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
 # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
-# org.gradle.parallel=true
+org.gradle.daemon=true
+org.gradle.configureondemand=true
+org.gradle.parallel=true
+
+localBuildToolsVersion=25.0.1
+localGradlePluginVersion=2.2.2
+
+# 每次更改“isModule”的值后,需要Sync gradle
+isModule=false

+ 3 - 3
settings.gradle

@@ -1,4 +1,4 @@
 include ':app',
 include ':app',
-        ':Girls',
-        ':News',
-        ':Common'
+        ':girls',
+        ':news',
+        ':common'