build.gradle 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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://cemakj.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. buildConfigField("String", "VERSION_REALM", "\""+rootProject.ext.android.versionRealm+"\"")
  69. manifestPlaceholders = [
  70. app_name:"返修易",
  71. icon:"@mipmap/ic_launcher",
  72. round_icon:"@mipmap/ic_launcher_round"
  73. ]
  74. proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
  75. }
  76. debug {
  77. multiDexEnabled true
  78. debuggable true
  79. zipAlignEnabled false
  80. shrinkResources false
  81. minifyEnabled false
  82. versionNameSuffix "_debug"
  83. applicationIdSuffix '.eac.fxy.debug'
  84. signingConfig signingConfigs.debug
  85. manifestPlaceholders = [
  86. app_name:"UAT-返修易",
  87. icon:"@mipmap/ic_launcher",
  88. round_icon:"@mipmap/ic_launcher_round"
  89. ]
  90. buildConfigField("String", "OSS_HOST", "\"https://cemakj.oss-cn-shenzhen.aliyuncs.com\"")
  91. buildConfigField("String", "RESOURCE_TYPE", "\"aliyun\"")
  92. buildConfigField("String", "RESOURCE_PREFIX", "\"uat/fxy\"")//只是默认值
  93. buildConfigField("String", "WELCOME_TITLE", "\"UAT-返修易\"")
  94. buildConfigField("String", "VERSION_API", "\"" + rootProject.ext.android.versionApi + "\"")
  95. buildConfigField("String", "VERSION_NUM", "\""+rootProject.ext.android.versionName+"\"")
  96. buildConfigField("String", "VERSION_REALM", "\""+rootProject.ext.android.versionRealm+"\"")
  97. proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
  98. }
  99. //需要在 baselibrary也配置一下
  100. }
  101. android.applicationVariants.all { variant ->
  102. variant.outputs.all {
  103. outputFileName = "fxy-pda-${variant.buildType.name}_v${defaultConfig.versionName}_${releaseTime()}.apk"
  104. }
  105. }
  106. /* // 输出文件配置
  107. applicationVariants.all { variant ->
  108. variant.outputs.each { output ->
  109. def outputFile = output.outputFile
  110. if (outputFile != null && outputFile.name.endsWith('.apk')) {
  111. def dirName = outputFile.parent // 输出文件夹所在的位置
  112. // 文件名修改
  113. def fileName = "app-${output.processResources.variantName}-${defaultConfig.versionName}-${variant.flavorName}.apk"
  114. // 比如不想这么麻烦,直接在后面加上版本号也行:
  115. // def fileName = outputFile.name.replace(".apk", "-${defaultConfig.versionName}.apk")
  116. output.outputFile = new File(dirName, fileName)
  117. }
  118. }
  119. }*/
  120. aaptOptions {
  121. cruncherEnabled = false
  122. useNewCruncher = false
  123. }
  124. sourceSets {
  125. main {
  126. jniLibs.srcDirs = ['libs']
  127. }
  128. }
  129. packagingOptions {
  130. exclude 'META-INF/rxjava.properties'
  131. }
  132. }
  133. dependencies {
  134. implementation fileTree(include: ['*.jar'], dir: 'libs')
  135. // androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
  136. // exclude group: 'com.android.support', module: 'support-annotations'
  137. // })
  138. // butterknife
  139. implementation rootProject.ext.dependencies.butterknife
  140. annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
  141. implementation 'com.luozm.captcha:captcha:1.1.2'
  142. implementation rootProject.ext.dependencies.multidex
  143. implementation rootProject.ext.dependencies.Spinner
  144. // implementation rootProject.ext.dependencies.litepal
  145. testImplementation 'junit:junit:4.12'
  146. compile 'com.android.support:multidex:1.0.2'
  147. compile project(':baselibrary')
  148. implementation 'com.aliyun.dpa:oss-android-sdk:2.9.13'
  149. implementation 'com.github.bingoogolapple.BGAQRCode-Android:zbar:1.3.8'
  150. // 自定义构建类型依赖
  151. // raedebugCompile project(path: ':sdk', configuration: 'zj_release')
  152. }
  153. //解决控件台中文乱码问题
  154. tasks.withType(JavaCompile) {
  155. options.encoding = "UTF-8"
  156. }
  157. def releaseTime() {
  158. return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("GMT+8:00"))
  159. }
  160. /**
  161. * @param filename 要打开的文件名字
  162. * @param propName 文件里面的键名字
  163. * @param isRootProject 是否用rootProject 文件打开,true 的话,在编译时候可以得到值,打包时候无法得到值。false的话在打包时候可以得到值,编译时候 无法得到值
  164. * @return 所选择的文件里面的propName对应的值
  165. */
  166. def getProperty(String filename, String propName,boolean isRootProject) {
  167. //在这里 必须是在rootProject.file 如果 file的话 ,编译时候会出错
  168. def propsFile
  169. def versionCode = 2
  170. if (isRootProject) {
  171. propsFile = rootProject.file(filename)
  172. }else {
  173. propsFile = file(filename)
  174. }
  175. if (propsFile.exists()) {
  176. def props = new Properties()
  177. props.load(new FileInputStream(propsFile))
  178. if (props[propName] != null) {
  179. //下面这个输出在android studio3.1里面 在Build窗口 右边一个锤子下面 toggle哪里,就是原来的message哪里
  180. print("versionCode "+props[propName])
  181. def code = (props[propName]).toInteger() //转成Integer
  182. props[propName] = (++code).toString() //自增 且转成String
  183. versionCode = code
  184. } else {
  185. print("No such property " + propName + " in file " + filename)
  186. }
  187. //在这里提交 对version.properties的更改
  188. props.store(propsFile.newWriter(),null)
  189. } else {
  190. print(filename + " does not exist!")
  191. }
  192. return versionCode
  193. }