blob: 5192885b27e358cd78431b7366562217a1836674 [file] [log] [blame]
Dominik Schürmann1bb476c2016-08-09 23:35:31 +02001apply plugin: 'com.android.application'
2apply plugin: 'checkstyle'
3
Hans-Christoph Steiner76c07a32016-08-09 15:21:01 +02004/* gets the version name from the latest Git tag, stripping the leading v off */
5def 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ürmann99aa8522016-08-01 23:06:54 +020014repositories {
15 jcenter()
16}
17
Dominik Schürmann1bb476c2016-08-09 23:35:31 +020018dependencies {
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ürmann99aa8522016-08-01 23:06:54 +020025
26android {
27 compileSdkVersion 24
28 buildToolsVersion '24.0.1'
29
30 defaultConfig {
Hans-Christoph Steiner76c07a32016-08-09 15:21:01 +020031 archivesBaseName = "FDroidPrivilegedExtension"
32
Dominik Schürmann1bb476c2016-08-09 23:35:31 +020033 testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Dominik Schürmann99aa8522016-08-01 23:06:54 +020034 }
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
relan5c58c3e2016-08-11 22:04:26 +030044 buildTypes {
45 all {
46 // Keep IPackageInstallObserver and IPackageDeleteObserver
47 minifyEnabled false
48 useProguard false
49 shrinkResources false
50 }
51 }
52
Dominik Schürmann99aa8522016-08-01 23:06:54 +020053 lintOptions {
Hans-Christoph Steinere40a2502016-08-08 16:36:31 +020054 checkReleaseBuilds false
55 abortOnError true
56
57 htmlReport true
58 xmlReport false
59 textReport false
60
Dominik Schürmann1bb476c2016-08-09 23:35:31 +020061 // this is never going to be a real "app"
62 disable 'GoogleAppIndexingWarning'
Dominik Schürmann99aa8522016-08-01 23:06:54 +020063 }
64
Hans-Christoph Steiner9b578ed2016-08-11 15:03:34 +020065 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 Steiner76c07a32016-08-09 15:21:01 +020080 applicationVariants.all { variant ->
81 def name = variant.buildType.name
82 def zipBase = file("${buildDir}/intermediates/updateZip${name.capitalize()}")
Hans-Christoph Steiner2da60fe2016-08-11 14:12:27 +020083 def zipWithFDroidBase = file("${buildDir}/intermediates/updateZipWithFDroid${name.capitalize()}")
Hans-Christoph Steiner76c07a32016-08-09 15:21:01 +020084
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 Steiner2da60fe2016-08-11 14:12:27 +0200115 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 Steiner76c07a32016-08-09 15:21:01 +0200157 project.tasks.build.dependsOn zipTask
158 }
Dominik Schürmann99aa8522016-08-01 23:06:54 +0200159}
160
161checkstyle {
Hans-Christoph Steiner9db56cf2016-08-10 11:59:55 +0200162 toolVersion = '7.1'
Dominik Schürmann99aa8522016-08-01 23:06:54 +0200163}
164
165task 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}