Dominik Schürmann | 1bb476c | 2016-08-09 23:35:31 +0200 | [diff] [blame] | 1 | apply plugin: 'com.android.application' |
| 2 | apply plugin: 'checkstyle' |
| 3 | |
Hans-Christoph Steiner | 76c07a3 | 2016-08-09 15:21:01 +0200 | [diff] [blame] | 4 | /* gets the version name from the latest Git tag, stripping the leading v off */ |
| 5 | def getVersionName = { -> |
| 6 | def stdout = new ByteArrayOutputStream() |
| 7 | exec { |
| 8 | commandLine 'git', 'describe', '--tags', '--always' |
| 9 | standardOutput = stdout |
| 10 | } |
| 11 | return stdout.toString().trim().substring(1) |
| 12 | } |
| 13 | |
Dominik Schürmann | 99aa852 | 2016-08-01 23:06:54 +0200 | [diff] [blame] | 14 | repositories { |
| 15 | jcenter() |
| 16 | } |
| 17 | |
Dominik Schürmann | 1bb476c | 2016-08-09 23:35:31 +0200 | [diff] [blame] | 18 | dependencies { |
| 19 | testCompile 'junit:junit:4.12' |
| 20 | |
| 21 | androidTestCompile 'com.android.support:support-annotations:24.1.1' |
| 22 | androidTestCompile 'com.android.support.test:runner:0.5' |
| 23 | androidTestCompile 'com.android.support.test:rules:0.5' |
| 24 | } |
Dominik Schürmann | 99aa852 | 2016-08-01 23:06:54 +0200 | [diff] [blame] | 25 | |
| 26 | android { |
| 27 | compileSdkVersion 24 |
| 28 | buildToolsVersion '24.0.1' |
| 29 | |
| 30 | defaultConfig { |
Hans-Christoph Steiner | 76c07a3 | 2016-08-09 15:21:01 +0200 | [diff] [blame] | 31 | archivesBaseName = "FDroidPrivilegedExtension" |
| 32 | |
Dominik Schürmann | 1bb476c | 2016-08-09 23:35:31 +0200 | [diff] [blame] | 33 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" |
Dominik Schürmann | 99aa852 | 2016-08-01 23:06:54 +0200 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | compileOptions { |
| 37 | compileOptions.encoding = "UTF-8" |
| 38 | |
| 39 | // Use Java 1.7, requires minSdk 8 |
| 40 | sourceCompatibility JavaVersion.VERSION_1_7 |
| 41 | targetCompatibility JavaVersion.VERSION_1_7 |
| 42 | } |
| 43 | |
relan | 5c58c3e | 2016-08-11 22:04:26 +0300 | [diff] [blame] | 44 | buildTypes { |
| 45 | all { |
| 46 | // Keep IPackageInstallObserver and IPackageDeleteObserver |
| 47 | minifyEnabled false |
| 48 | useProguard false |
| 49 | shrinkResources false |
| 50 | } |
| 51 | } |
| 52 | |
Dominik Schürmann | 99aa852 | 2016-08-01 23:06:54 +0200 | [diff] [blame] | 53 | lintOptions { |
Hans-Christoph Steiner | e40a250 | 2016-08-08 16:36:31 +0200 | [diff] [blame] | 54 | checkReleaseBuilds false |
| 55 | abortOnError true |
| 56 | |
| 57 | htmlReport true |
| 58 | xmlReport false |
| 59 | textReport false |
| 60 | |
Dominik Schürmann | 1bb476c | 2016-08-09 23:35:31 +0200 | [diff] [blame] | 61 | // this is never going to be a real "app" |
| 62 | disable 'GoogleAppIndexingWarning' |
Dominik Schürmann | 99aa852 | 2016-08-01 23:06:54 +0200 | [diff] [blame] | 63 | } |
| 64 | |
Hans-Christoph Steiner | 9b578ed | 2016-08-11 15:03:34 +0200 | [diff] [blame^] | 65 | File signFile = rootProject.file('signing.properties') |
| 66 | if (signFile.exists()) { |
| 67 | Properties properties = new Properties() |
| 68 | properties.load(new FileInputStream(signFile)) |
| 69 | signingConfigs { |
| 70 | release { |
| 71 | storeFile rootProject.file(properties['key.store']) |
| 72 | storePassword properties['key.store.password'] |
| 73 | keyAlias properties['key.alias'] |
| 74 | keyPassword properties['key.alias.password'] |
| 75 | } |
| 76 | } |
| 77 | buildTypes.release.signingConfig signingConfigs.release |
| 78 | } |
| 79 | |
Hans-Christoph Steiner | 76c07a3 | 2016-08-09 15:21:01 +0200 | [diff] [blame] | 80 | applicationVariants.all { variant -> |
| 81 | def name = variant.buildType.name |
| 82 | def zipBase = file("${buildDir}/intermediates/updateZip${name.capitalize()}") |
Hans-Christoph Steiner | 2da60fe | 2016-08-11 14:12:27 +0200 | [diff] [blame] | 83 | def zipWithFDroidBase = file("${buildDir}/intermediates/updateZipWithFDroid${name.capitalize()}") |
Hans-Christoph Steiner | 76c07a3 | 2016-08-09 15:21:01 +0200 | [diff] [blame] | 84 | |
| 85 | def apkToCopy |
| 86 | variant.outputs.each { output -> |
| 87 | if (output.zipAlign) { |
| 88 | apkToCopy = output.outputFile |
| 89 | } |
| 90 | } |
| 91 | if (apkToCopy == null) { |
| 92 | return; |
| 93 | } |
| 94 | |
| 95 | def copyApkTask = project.tasks.create("copyApk${name.capitalize()}", Copy) { |
| 96 | dependsOn variant.assemble |
| 97 | from apkToCopy |
| 98 | into zipBase |
| 99 | rename { String fileName -> |
| 100 | fileName = "${archivesBaseName}.apk" |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | def copyScriptTask = project.tasks.create("copyScript${name.capitalize()}", Copy) { |
| 105 | from "src/main/scripts/update-binary" |
| 106 | into "${zipBase}/META-INF/com/google/android/" |
| 107 | } |
| 108 | |
| 109 | def zipTask = project.tasks.create("updateZip${name.capitalize()}", Zip) { |
| 110 | dependsOn copyApkTask, copyScriptTask |
| 111 | from zipBase |
| 112 | archiveName "${archivesBaseName}-${getVersionName()}-${name}.zip" |
| 113 | } |
| 114 | |
Hans-Christoph Steiner | 2da60fe | 2016-08-11 14:12:27 +0200 | [diff] [blame] | 115 | def getFDroidApkTask = project.tasks.create("getFDroidApk${name.capitalize()}") { |
| 116 | doLast { |
| 117 | def downloadDir = "${buildDir}/intermediates" |
| 118 | def f = new File("${downloadDir}/FDroid.apk") |
| 119 | if (!f.exists()) { |
| 120 | def url = 'https://f-droid.org/FDroid.apk' |
| 121 | println "Downloading ${url}" |
| 122 | new URL(url).withInputStream { i -> f.withOutputStream { it << i } } |
| 123 | } |
| 124 | def asc = new File("${downloadDir}/FDroid.apk.asc") |
| 125 | if (!asc.exists()) { |
| 126 | def url = 'https://f-droid.org/FDroid.apk.asc' |
| 127 | println "Downloading ${url}" |
| 128 | new URL(url).withInputStream { i -> asc.withOutputStream { it << i } } |
| 129 | } |
| 130 | println "Verifying using ${asc}" |
| 131 | exec { |
| 132 | def keyring = new File(project.rootDir, '/f-droid.org-signing-key.gpg') |
| 133 | executable = 'gpg' |
| 134 | args '--keyring', keyring, '--no-default-keyring', '--verify', asc |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | def copyUpdateZipDirTask = project.tasks.create("copyUpdateZipDir${name.capitalize()}", Copy) { |
| 140 | dependsOn copyApkTask, copyScriptTask |
| 141 | from zipBase |
| 142 | into zipWithFDroidBase |
| 143 | } |
| 144 | |
| 145 | def copyFDroidApkTask = project.tasks.create("copyFDroidApk${name.capitalize()}", Copy) { |
| 146 | dependsOn getFDroidApkTask, copyUpdateZipDirTask |
| 147 | from "${buildDir}/intermediates/FDroid.apk" |
| 148 | into zipWithFDroidBase |
| 149 | } |
| 150 | |
| 151 | def zipWithFDroidTask = project.tasks.create("updateZipWithFDroid${name.capitalize()}", Zip) { |
| 152 | dependsOn copyFDroidApkTask |
| 153 | from zipWithFDroidBase |
| 154 | archiveName "${archivesBaseName}WithFDroid-${getVersionName()}-${name}.zip" |
| 155 | } |
| 156 | |
Hans-Christoph Steiner | 76c07a3 | 2016-08-09 15:21:01 +0200 | [diff] [blame] | 157 | project.tasks.build.dependsOn zipTask |
| 158 | } |
Dominik Schürmann | 99aa852 | 2016-08-01 23:06:54 +0200 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | checkstyle { |
Hans-Christoph Steiner | 9db56cf | 2016-08-10 11:59:55 +0200 | [diff] [blame] | 162 | toolVersion = '7.1' |
Dominik Schürmann | 99aa852 | 2016-08-01 23:06:54 +0200 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | task checkstyle(type: Checkstyle) { |
| 166 | configFile file("${project.rootDir}/config/checkstyle/checkstyle.xml") |
| 167 | source 'src/main/java' |
| 168 | include '**/*.java' |
| 169 | |
| 170 | classpath = files() |
| 171 | } |