build.gradle 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. apply plugin: 'com.android.application'
  2. apply plugin: 'com.jakewharton.butterknife'
  3. apply plugin: 'realm-android'
  4. android {
  5. compileSdkVersion rootProject.ext.android.compileSdkVersion
  6. defaultConfig {
  7. applicationId rootProject.ext.android.applicationId
  8. minSdkVersion rootProject.ext.android.minSdkVersion
  9. targetSdkVersion rootProject.ext.android.targetSdkVersion
  10. // versionCode rootProject.ext.android.versionCode
  11. versionCode getProperty("version.properties","versionCode",true)
  12. versionName rootProject.ext.android.versionName
  13. testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
  14. javaCompileOptions {
  15. annotationProcessorOptions {
  16. includeCompileClasspath = true
  17. }
  18. }
  19. multiDexEnabled true
  20. }
  21. lintOptions {
  22. checkReleaseBuilds false
  23. abortOnError false
  24. }
  25. signingConfigs {
  26. release {
  27. try {
  28. storeFile file("fxy.jks")
  29. storePassword KEYSTORE_PASSWORD
  30. keyAlias "fxy"
  31. keyPassword KEY_PASSWORD
  32. } catch (ex) {
  33. throw new ExceptionInInitializerError("You should define KEYSTORE_PASSWORD and KEY_PASSWORD in gradle.properties.")
  34. }
  35. }
  36. debug {
  37. try {
  38. storeFile file("fxy.jks")
  39. storePassword KEYSTORE_PASSWORD
  40. keyAlias "fxy"
  41. keyPassword KEY_PASSWORD
  42. } catch (ex) {
  43. throw new ExceptionInInitializerError("You should define KEYSTORE_PASSWORD and KEY_PASSWORD in gradle.properties.")
  44. }
  45. }
  46. }
  47. buildTypes {
  48. release {
  49. // 开启混淆
  50. minifyEnabled false
  51. // 对齐zip
  52. zipAlignEnabled true
  53. // 删除无用资源
  54. shrinkResources false
  55. // 是否debug
  56. debuggable false
  57. // 命名后缀
  58. //versionNameSuffix "_release"
  59. applicationIdSuffix '.eac.fxy'
  60. // 签名
  61. signingConfig signingConfigs.release
  62. buildConfigField("String", "OSS_HOST", "\"https://fhdr.oss-cn-shenzhen.aliyuncs.com\"")
  63. buildConfigField("String", "RESOURCE_TYPE", "\"aliyun\"")
  64. buildConfigField("String", "RESOURCE_PREFIX", "\"prod/fxy\"")//只是默认值
  65. buildConfigField("String", "WELCOME_TITLE", "\"FXY\"")
  66. buildConfigField("String", "VERSION_API", "\"" + rootProject.ext.android.versionApi + "\"")
  67. buildConfigField("String", "VERSION_NUM", "\""+rootProject.ext.android.versionName+"\"")
  68. manifestPlaceholders = [
  69. app_name:"返修易",
  70. icon:"@mipmap/ic_launcher",
  71. round_icon:"@mipmap/ic_launcher_round"
  72. ]
  73. proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
  74. }
  75. debug {
  76. multiDexEnabled true
  77. debuggable true
  78. zipAlignEnabled false
  79. shrinkResources false
  80. minifyEnabled false
  81. versionNameSuffix "_debug"
  82. applicationIdSuffix '.eac.fxy.debug'
  83. signingConfig signingConfigs.debug
  84. manifestPlaceholders = [
  85. app_name:"UAT-返修易",
  86. icon:"@mipmap/ic_launcher",
  87. round_icon:"@mipmap/ic_launcher_round"
  88. ]
  89. buildConfigField("String", "OSS_HOST", "\"https://fhdr.oss-cn-shenzhen.aliyuncs.com\"")
  90. buildConfigField("String", "RESOURCE_TYPE", "\"aliyun\"")
  91. buildConfigField("String", "RESOURCE_PREFIX", "\"uat/fxy\"")//只是默认值
  92. buildConfigField("String", "WELCOME_TITLE", "\"UAT-返修易\"")
  93. buildConfigField("String", "VERSION_API", "\"" + rootProject.ext.android.versionApi + "\"")
  94. buildConfigField("String", "VERSION_NUM", "\""+rootProject.ext.android.versionName+"\"")
  95. proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
  96. }
  97. //需要在 baselibrary也配置一下
  98. }
  99. android.applicationVariants.all { variant ->
  100. variant.outputs.all {
  101. outputFileName = "fxy-pda-${variant.buildType.name}_v${defaultConfig.versionName}_${releaseTime()}.apk"
  102. }
  103. }
  104. /* // 输出文件配置
  105. applicationVariants.all { variant ->
  106. variant.outputs.each { output ->
  107. def outputFile = output.outputFile
  108. if (outputFile != null && outputFile.name.endsWith('.apk')) {
  109. def dirName = outputFile.parent // 输出文件夹所在的位置
  110. // 文件名修改
  111. def fileName = "app-${output.processResources.variantName}-${defaultConfig.versionName}-${variant.flavorName}.apk"
  112. // 比如不想这么麻烦,直接在后面加上版本号也行:
  113. // def fileName = outputFile.name.replace(".apk", "-${defaultConfig.versionName}.apk")
  114. output.outputFile = new File(dirName, fileName)
  115. }
  116. }
  117. }*/
  118. aaptOptions {
  119. cruncherEnabled = false
  120. useNewCruncher = false
  121. }
  122. sourceSets {
  123. main {
  124. jniLibs.srcDirs = ['libs']
  125. }
  126. }
  127. packagingOptions {
  128. exclude 'META-INF/rxjava.properties'
  129. }
  130. }
  131. dependencies {
  132. implementation fileTree(include: ['*.jar'], dir: 'libs')
  133. // androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
  134. // exclude group: 'com.android.support', module: 'support-annotations'
  135. // })
  136. // butterknife
  137. implementation rootProject.ext.dependencies.butterknife
  138. annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
  139. implementation 'com.luozm.captcha:captcha:1.1.2'
  140. implementation rootProject.ext.dependencies.multidex
  141. implementation rootProject.ext.dependencies.Spinner
  142. // implementation rootProject.ext.dependencies.litepal
  143. testImplementation 'junit:junit:4.12'
  144. compile 'com.android.support:multidex:1.0.2'
  145. compile project(':baselibrary')
  146. implementation 'com.github.bingoogolapple.BGAQRCode-Android:zbar:1.3.8'
  147. // 自定义构建类型依赖
  148. // raedebugCompile project(path: ':sdk', configuration: 'zj_release')
  149. }
  150. //解决控件台中文乱码问题
  151. tasks.withType(JavaCompile) {
  152. options.encoding = "UTF-8"
  153. }
  154. def releaseTime() {
  155. return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("GMT+8:00"))
  156. }
  157. /**
  158. * @param filename 要打开的文件名字
  159. * @param propName 文件里面的键名字
  160. * @param isRootProject 是否用rootProject 文件打开,true 的话,在编译时候可以得到值,打包时候无法得到值。false的话在打包时候可以得到值,编译时候 无法得到值
  161. * @return 所选择的文件里面的propName对应的值
  162. */
  163. def getProperty(String filename, String propName,boolean isRootProject) {
  164. //在这里 必须是在rootProject.file 如果 file的话 ,编译时候会出错
  165. def propsFile
  166. def versionCode = 2
  167. if (isRootProject) {
  168. propsFile = rootProject.file(filename)
  169. }else {
  170. propsFile = file(filename)
  171. }
  172. if (propsFile.exists()) {
  173. def props = new Properties()
  174. props.load(new FileInputStream(propsFile))
  175. if (props[propName] != null) {
  176. //下面这个输出在android studio3.1里面 在Build窗口 右边一个锤子下面 toggle哪里,就是原来的message哪里
  177. print("versionCode "+props[propName])
  178. def code = (props[propName]).toInteger() //转成Integer
  179. props[propName] = (++code).toString() //自增 且转成String
  180. versionCode = code
  181. } else {
  182. print("No such property " + propName + " in file " + filename)
  183. }
  184. //在这里提交 对version.properties的更改
  185. props.store(propsFile.newWriter(),null)
  186. } else {
  187. print(filename + " does not exist!")
  188. }
  189. return versionCode
  190. }