Advertisement
Guest User

grade

a guest
May 10th, 2016
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.53 KB | None | 0 0
  1. apply plugin: 'com.android.application'
  2. apply plugin: 'io.fabric'
  3. apply plugin: 'spoon'
  4.  
  5. repositories {
  6. maven { url 'https://maven.fabric.io/public' }
  7. }
  8.  
  9. buildscript {
  10. repositories {
  11. jcenter()
  12. mavenCentral()
  13. maven { url 'https://maven.fabric.io/public' }
  14. }
  15.  
  16. dependencies {
  17. classpath 'com.android.tools.build:gradle:1.5.0'
  18. classpath 'io.fabric.tools:gradle:1.21.2'
  19. classpath('com.squareup.spoon:spoon-runner:1.2.0') {
  20. exclude module: 'guava'
  21. }
  22. classpath('com.stanfy.spoon:spoon-gradle-plugin:1.0.2') {
  23. exclude module: 'guava'
  24. }
  25. classpath 'com.google.guava:guava:17.0'
  26. }
  27. }
  28.  
  29. allprojects {
  30. repositories {
  31. jcenter()
  32. }
  33. }
  34.  
  35. /**
  36. * CODE BASE VERSION
  37. *
  38. * This is hardcoded in the source code and reflects the version number of the source code.
  39. * This MUST be updated after at the start of every sprint. If a release to the public is
  40. * done we do a major version number increase, e.g. 1.3, 1.4, 1.5. If there is no release
  41. * to the public we will increment the minor version number, e.g. 1.5.1, 1.5.2, 1.5.3 etc.
  42. */
  43. def codeBaseVersion = "1.5"
  44.  
  45. def buildConfigVersionFolder
  46.  
  47. /**
  48. * Task Name: fetchResources
  49. * Description: This task fetches the white_labelling.xml file, and app resources from version control
  50. */
  51. task fetchResources(type: Exec) {
  52. def doPull = false;
  53. def resFolder = new File("$projectDir/res-repo")
  54. if (resFolder.exists()) {
  55. doPull = true;
  56. }
  57.  
  58. def tfs = new XmlParser().parse("$projectDir/tfs.xml")
  59. def tfsUser = tfs.@tfsUser
  60. def tfsPassword = tfs.@tfsPassword
  61. def tfsUrl = tfs.@tfsUrl
  62.  
  63. def gitFetchResources = exec {
  64. ignoreExitValue = true
  65. executable 'git'
  66. if (!doPull) {
  67. println "Cloning Resources"
  68. workingDir "$projectDir"
  69. args "clone", String.valueOf("http://$tfsUser:$tfsPassword@$tfsUrl"), "res-repo"
  70. } else {
  71. println "Pulling Resources"
  72. workingDir "$projectDir/res-repo"
  73. args "pull"
  74. }
  75.  
  76. }
  77.  
  78. println "gitFetchResources: " + gitFetchResources
  79. }
  80.  
  81. /**
  82. * Task Name: updateBuildConfigVersionFolder
  83. * Description: This task determines the build config folder that should be used
  84. */
  85. task updateBuildConfigVersionFolder(type: Exec, dependsOn: 'fetchResources') {
  86. def lastFileName = codeBaseVersion
  87. new File("$projectDir/res-repo/buildConfig").eachFile() { file->
  88. if (file.isDirectory()) {
  89. lastFileName = file.getName()
  90. if (file.getName().equals(codeBaseVersion)) {
  91. buildConfigVersionFolder = file.getName()
  92. }
  93. }
  94. }
  95.  
  96. if (!buildConfigVersionFolder) {
  97. buildConfigVersionFolder = lastFileName
  98. }
  99.  
  100. println "buildConfigVersionFolder: " + buildConfigVersionFolder
  101. }
  102.  
  103. /**
  104. * Task Name: genNewKey
  105. * Description: This task creates the .properties and .jks files for each product flavor if it does not already exist.
  106. */
  107. task genNewKey(type: Exec) {
  108. // Read the configuration from the XML file
  109. def applications = new XmlParser().parse("$projectDir/res-repo/buildConfig/$buildConfigVersionFolder/white_labelling.xml")
  110. applications.application.each { app ->
  111. // Configure the Product Flavors
  112. def appFlavor = new Expando()
  113. appFlavor.appName = app.@appName
  114. appFlavor.keyPassword = app.keystore.get(0).@keyPassword
  115. appFlavor.keyAlias = app.keystore.get(0).@keyAlias
  116.  
  117. // Start the Signing Process
  118. appFlavor.keyStorePropertiesFileName = 'keystore-' << appFlavor.appName.toLowerCase() << '.properties'
  119. appFlavor.keyStoreJksFileName = 'release-' << appFlavor.appName.toLowerCase() << '.jks'
  120.  
  121. // Create the keystore-*.properties file if it does not exist
  122. def keyStorePropertiesFile = new File("$projectDir/sign", appFlavor.keyStorePropertiesFileName.toString())
  123. if (!keyStorePropertiesFile.exists()) {
  124. def propertiesBuilder = new StringBuilder("keystore=keystore/" << appFlavor.keyStoreJksFileName << "\n")
  125. propertiesBuilder.append("storePassword=" << appFlavor.keyPassword << "\n")
  126. propertiesBuilder.append("keyAlias=" << appFlavor.keyAlias << "\n")
  127. propertiesBuilder.append("keyPassword=" << appFlavor.keyPassword << "\n")
  128. keyStorePropertiesFile.withWriter { writer ->
  129. writer << propertiesBuilder.toString()
  130. }
  131. }
  132.  
  133. // Create the release-*.jks file if it does not exist
  134. def keyStoreJksFile = new File("$projectDir/keystore", appFlavor.keyStoreJksFileName.toString())
  135. if (!keyStoreJksFile.exists()) {
  136. def genKey = exec {
  137. ignoreExitValue = true
  138. executable 'keytool'
  139. args '-genkey', '-noprompt', '-alias', String.valueOf("$appFlavor.keyAlias"), '-keystore', String.valueOf("$projectDir/keystore/$appFlavor.keyStoreJksFileName"), '-storepass', "$appFlavor.keyPassword", '-dname', "CN=netstar.altech.co.za, OU=DEVELOPMENT, O=NETSTAR, L=JHB, ST=GAUTENG, C=ZA", '-keypass', String.valueOf("$appFlavor.keyPassword"), '-validity', String.valueOf(10000)
  140. }
  141. println "genNewKey: " + genKey
  142. }
  143. }
  144. }
  145.  
  146. /**
  147. * Task Name: genVersionName
  148. * Description: This task generates the version using the following format: {BASE_VERSION}.{YY}{MM}.{DD}{BUILD_NUMBER}, e.g. 1.4.1601.0402
  149. */
  150. task genVersionName(type: Exec) {
  151. def date = new Date()
  152. def buildDate = date.format("yyMM.dd")
  153. def buildNumber = 1
  154. File buildNumberFile = rootProject.file("$projectDir/build_number.properties")
  155. if (buildNumberFile.exists()) {
  156. Properties properties = new Properties()
  157. properties.load(new FileInputStream(buildNumberFile))
  158. def lastBuildDate = properties['buildDate']
  159. if (lastBuildDate.equals(buildDate)) {
  160. buildNumber = Integer.parseInt(String.valueOf(properties['buildNumber'])) + 1
  161. }
  162. properties.setProperty('buildDate', buildDate)
  163. properties.setProperty('buildNumber', String.valueOf(buildNumber))
  164. properties.store(buildNumberFile.newWriter(), null)
  165. }
  166. codeBaseVersion = "$codeBaseVersion.$buildDate" + String.format("%02d", buildNumber)
  167. println "codeBaseVersion: " + codeBaseVersion
  168. }
  169.  
  170. android {
  171. compileSdkVersion 23
  172. buildToolsVersion '23.0.2'
  173.  
  174. useLibrary 'org.apache.http.legacy'
  175.  
  176. compileOptions {
  177. encoding 'UTF-8'
  178. sourceCompatibility JavaVersion.VERSION_1_6
  179. targetCompatibility JavaVersion.VERSION_1_6
  180. }
  181.  
  182. defaultConfig {
  183. applicationId 'za.co.altech.netstar.safeandsound'
  184. minSdkVersion 17
  185. targetSdkVersion 23
  186. versionCode 9
  187. versionName codeBaseVersion
  188.  
  189. // Enable multiDex support
  190. multiDexEnabled true
  191. }
  192.  
  193. /**
  194. * Read the white labelling config from the XML file
  195. */
  196. def productFlavorMap = [:]
  197. def applications = new XmlParser().parse("$projectDir/res-repo/buildConfig/$buildConfigVersionFolder/white_labelling.xml")
  198. applications.application.each { app ->
  199. // Step 1: Configure the Product Flavor
  200. def appFlavor = new Expando()
  201. appFlavor.appName = app.@appName
  202. appFlavor.appId = app.@appId
  203. appFlavor.versionCode = app.@versionCode
  204. appFlavor.versionName = codeBaseVersion
  205. appFlavor.menuItems = app.menuItems
  206. appFlavor.map = app.map
  207. appFlavor.apiAddresses = app.apiAddresses
  208.  
  209. // Step 2: Create the res directory if it does not exist
  210. appFlavor.resFolderName = "$projectDir/src/main/res-" << appFlavor.appName.toLowerCase()
  211.  
  212. def resFolder = new File(appFlavor.resFolderName.toString())
  213. if( !resFolder.exists() ) {
  214. resFolder.mkdirs()
  215. }
  216.  
  217. // Step 3: Copy the images from the repo directory into the correct res folder
  218. def resRepoDir = "$projectDir/" << app.images.get(0).@resourceDirectory
  219. copy {
  220. from "${resRepoDir}"
  221. into "${appFlavor.resFolderName}"
  222. include 'drawable-*/**'
  223. includeEmptyDirs = false
  224. }
  225.  
  226. // Step 4: Create the values directory if it does not exist
  227. def valuesFolderName = appFlavor.resFolderName
  228. valuesFolderName = valuesFolderName << '/values'
  229. def valuesFolder = new File(valuesFolderName.toString())
  230. if( !valuesFolder.exists() ) {
  231. valuesFolder.mkdirs()
  232. }
  233.  
  234. // Step 5: Create the colors.xml file
  235. def colorsBuilder = new StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
  236. colorsBuilder.append("<resources>\n")
  237. app.colors.color.each { color ->
  238. colorsBuilder.append('\t<color name="' + color.@name.toString() + '">' + color.text().toString() + '</color>\n')
  239. }
  240. colorsBuilder.append("</resources>")
  241. new File( valuesFolder, 'colors.xml' ).withWriter { writer ->
  242. writer << colorsBuilder.toString()
  243. }
  244.  
  245. // Step 6: Create the strings.xml file
  246. def stringsBuilder = new StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
  247. stringsBuilder.append("<resources>\n")
  248. app.strings.string.each { string ->
  249. stringsBuilder.append('\t<string name="' + string.@name.toString() + '">' + string.text().toString() + '</string>\n')
  250. }
  251. stringsBuilder.append("</resources>")
  252. new File( valuesFolder, 'strings.xml' ).withWriter { writer ->
  253. writer << stringsBuilder.toString()
  254. }
  255.  
  256. // Step 7: Set the keystore-*.properties file name for the flavor
  257. appFlavor.keyStorePropertiesFileName = 'keystore-' << appFlavor.appName.toLowerCase() << '.properties'
  258.  
  259. // Step 8: Finally add the application flavor to the map
  260. productFlavorMap.put(app.@appName, appFlavor)
  261. }
  262.  
  263. // Update the source sets
  264. sourceSets {
  265. main {
  266. java.srcDirs = ['src/main/java']
  267. res.srcDirs = ['src/main/res']
  268. resources.srcDirs = ['src/main/res']
  269. }
  270.  
  271. productFlavorMap.each { flavorName, appFlavor ->
  272. "$flavorName" {
  273. res.srcDirs = ['src/main/res-' << appFlavor.appName.toLowerCase()]
  274. resources.srcDirs = ['src/main/res-' << appFlavor.appName.toLowerCase()]
  275. }
  276. }
  277. }
  278.  
  279. // Update the signing configs
  280. productFlavorMap.each { flavorName, appFlavor ->
  281. File signFile = rootProject.file("$projectDir/sign/$appFlavor.keyStorePropertiesFileName")
  282. if (signFile.exists()) {
  283. Properties properties = new Properties()
  284. properties.load(new FileInputStream(signFile))
  285. signingConfigs {
  286. "$flavorName" {
  287. storeFile rootProject.file(properties['keystore'])
  288. storePassword properties['storePassword']
  289. keyAlias properties['keyAlias']
  290. keyPassword properties['keyPassword']
  291. }
  292. }
  293. }
  294. }
  295.  
  296. // Hide / show menu items
  297. productFlavors {
  298. productFlavorMap.each { flavorName, appFlavor ->
  299. "$flavorName" {
  300. applicationId appFlavor.appId
  301. versionCode appFlavor.versionCode.toInteger()
  302. versionName appFlavor.versionName
  303.  
  304. // Create the Build Config for the menu items
  305. appFlavor.menuItems.menuItem.each { menuItem ->
  306. buildConfigField "boolean", menuItem.@name.toString(), 'Boolean.parseBoolean("' + menuItem.text().toString() + '")'
  307. }
  308.  
  309. // Create the Build Config for the default center position of the map
  310. buildConfigField "double", "CENTER_LAT", 'Double.parseDouble("' + appFlavor.map.get(0).@centerLat.toString() + '")'
  311. buildConfigField "double", "CENTER_LON", 'Double.parseDouble("' + appFlavor.map.get(0).@centerLon.toString() + '")'
  312. buildConfigField "int", "CENTER_ZOOM_LEVEL", 'Integer.parseInt("' + appFlavor.map.get(0).@centerZoomLevel.toString() + '")'
  313.  
  314. // Create the Build Config for the api addresses
  315. buildConfigField "String", "DEV_URL", '"' + appFlavor.apiAddresses.get(0).@devUrl.toString() + '"'
  316. buildConfigField "String", "PROD_URL", '"' + appFlavor.apiAddresses.get(0).@prodUrl.toString() + '"'
  317. }
  318. }
  319. }
  320.  
  321. buildTypes {
  322. release {
  323. minifyEnabled false
  324. proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
  325. productFlavorMap.each { flavorName, appFlavor ->
  326. productFlavors."$flavorName".signingConfig signingConfigs."$flavorName"
  327. }
  328. }
  329. debug {
  330. minifyEnabled false
  331. }
  332. }
  333.  
  334. lintOptions {
  335. abortOnError false
  336. }
  337. }
  338.  
  339. dependencies {
  340. compile fileTree(include: ['*.jar'], dir: 'libs')
  341. compile project(':locationModule')
  342. compile project(':lineChartModule')
  343. compile 'com.android.support:support-v4:23.1.1'
  344. compile 'com.android.support:support-v13:23.1.1'
  345. compile 'com.android.support:appcompat-v7:23.1.1'
  346. compile 'com.android.support:cardview-v7:23.1.1'
  347. compile 'com.android.support:recyclerview-v7:23.1.1'
  348. compile 'com.android.support:design:23.1.1'
  349. compile 'com.mcxiaoke.volley:library:1.0.19'
  350. compile 'com.google.code.gson:gson:2.4'
  351. compile 'de.greenrobot:eventbus:2.4.1'
  352. compile 'com.wdullaer:materialdatetimepicker:1.5.3'
  353. // Multi Dex
  354. compile 'com.android.support:multidex:1.0.1'
  355. // Crash Analytics
  356. compile('com.crashlytics.sdk.android:crashlytics:2.5.5@aar') {
  357. transitive = true;
  358. }
  359. // Unit Tests
  360. testCompile 'junit:junit:4.12'
  361. testCompile 'org.assertj:assertj-core:1.7.0'
  362. testCompile('org.robolectric:shadows-play-services:3.0') {
  363. exclude module: 'commons-logging'
  364. exclude module: 'httpclient'
  365. }
  366. testCompile 'org.robolectric:shadows-support-v4:3.0'
  367. testCompile 'org.robolectric:shadows-multidex:3.0'
  368. testCompile 'org.mockito:mockito-core:1.10.19'
  369. // Instrumentation Tests
  370. androidTestCompile 'org.assertj:assertj-core:1.7.0'
  371. androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.5.2'
  372. androidTestCompile 'com.squareup.spoon:spoon-client:1.1.10'
  373. }
  374.  
  375. spoon {
  376. // Enable debug output
  377. debug = true
  378. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement