chiark / gitweb /
gradle file: use flavour specific versionCode/versionName, fall back to parsing line...
[fdroidserver.git] / tests / source-files / fdroid / fdroidclient / build.gradle
1 apply plugin: 'com.android.application'
2
3 if ( !hasProperty( 'sourceDeps' ) ) {
4
5     logger.info "Setting up *binary* dependencies for F-Droid (if you'd prefer to build from source, pass the -PsourceDeps argument to gradle while building)."
6
7     repositories {
8         jcenter()
9
10         // This is here until we sort out all dependencies from mavenCentral/jcenter. Once all of
11         // the dependencies below have been sorted out, this can be removed.
12         flatDir {
13             dirs 'libs/binaryDeps'
14         }
15     }
16
17     dependencies {
18
19         compile 'com.android.support:support-v4:22.1.0',
20                 'com.android.support:appcompat-v7:22.1.0',
21                 'com.android.support:support-annotations:22.1.0',
22
23                 'org.thoughtcrime.ssl.pinning:AndroidPinning:1.0.0',
24                 'com.nostra13.universalimageloader:universal-image-loader:1.9.4',
25                 'com.google.zxing:core:3.2.0',
26                 'eu.chainfire:libsuperuser:1.0.0.201504231659',
27
28                 // We use a slightly modified spongycastle, see
29                 // openkeychain/spongycastle with some changes on top of 1.51.0.0
30                 'com.madgag.spongycastle:pkix:1.51.0.0',
31                 'com.madgag.spongycastle:prov:1.51.0.0',
32                 'com.madgag.spongycastle:core:1.51.0.0'
33
34         // Upstream doesn't have a binary on mavenCentral/jcenter yet:
35         // https://github.com/kolavar/android-support-v4-preferencefragment/issues/13
36         compile(name: 'support-v4-preferencefragment-release', ext: 'aar')
37
38         // Fork for F-Droid, including support for https. Not merged into upstream
39         // yet (seems to be a little unsupported as of late), so not using mavenCentral/jcenter.
40         compile(name: 'nanohttpd-2.1.0')
41
42         // Upstream doesn't have a binary on mavenCentral.
43         compile(name: 'zipsigner')
44
45         // Project semi-abandoned, 3.4.1 is from 2011 and we use trunk from 2013
46         compile(name: 'jmdns')
47
48         androidTestCompile 'commons-io:commons-io:2.2'
49     }
50
51 } else {
52
53     logger.info "Setting up *source* dependencies for F-Droid (because you passed in the -PsourceDeps argument to gradle while building)."
54
55     repositories {
56         jcenter()
57     }
58
59     dependencies {
60         compile project(':extern:AndroidPinning')
61         compile project(':extern:UniversalImageLoader:library')
62         compile project(':extern:libsuperuser:libsuperuser')
63         compile project(':extern:nanohttpd:core')
64         compile project(':extern:jmdns')
65         compile project(':extern:zipsigner')
66         compile project(':extern:zxing-core')
67         compile( project(':extern:support-v4-preferencefragment') ) {
68             exclude module: 'support-v4'
69         }
70
71         // Until the android team updates the gradle plugin version from 0.10.0 to
72         // a newer version, we can't build this from source with our gradle version
73         // of 1.0.0. They use API's which have been moved in the newer plugin.
74         // So yes, this is a little annoying that our "source dependencies" include
75         // a bunch of binaries from jcenter - but the ant build file (which is the
76         // one used to build F-Droid which is distributed on https://f-droid.org
77         // builds these from source - well - not support-v4).
78         //
79         // If the android team gets the build script working with the newer plugin,
80         // then you can find the relevant portions of the ../build.gradle file that
81         // include magic required to make it work at around about the v0.78 git tag.
82         // They have since been removed to clean up the build file.
83         compile 'com.android.support:support-v4:22.1.0',
84                 'com.android.support:appcompat-v7:22.1.0',
85                 'com.android.support:support-annotations:22.1.0'
86
87         androidTestCompile 'commons-io:commons-io:2.2'
88     }
89
90 }
91
92 task cleanBinaryDeps(type: Delete) {
93
94     enabled = project.hasProperty('sourceDeps')
95     description = "Removes all .jar and .aar files from F-Droid/libs/. Requires the sourceDeps property to be set (\"gradle -PsourceDeps cleanBinaryDeps\")"
96
97     delete fileTree('libs/binaryDeps') {
98         include '*.aar'
99         include '*.jar'
100     }
101 }
102
103 task binaryDeps(type: Copy, dependsOn: ':F-Droid:prepareReleaseDependencies') {
104
105     enabled = project.hasProperty('sourceDeps')
106     description = "Copies .jar and .aar files from subproject dependencies in extern/ to F-Droid/libs. Requires the sourceDeps property to be set (\"gradle -PsourceDeps binaryDeps\")"
107
108     from ('../extern/' ) {
109         include 'support-v4-preferencefragment/build/outputs/aar/support-v4-preferencefragment-release.aar',
110                 'nanohttpd/core/build/libs/nanohttpd-2.1.0.jar',
111                 'zipsigner/build/libs/zipsigner.jar',
112                 'jmdns/build/libs/jmdns.jar',
113                 'Support/v4/build/libs/support-v4.jar'
114     }
115
116     into 'libs/binaryDeps'
117
118     includeEmptyDirs false
119
120     eachFile { FileCopyDetails details ->
121         // Don't copy to a sub folder such as libs/binaryDeps/Project/build/outputs/aar/project.aar, but
122         // rather libs/binaryDeps/project.aar.
123         details.path = details.name
124     }
125
126 }
127
128 android {
129     compileSdkVersion 21
130     buildToolsVersion '22.0.1'
131
132     defaultConfig {
133
134         flavorDimensions "default"
135
136         productFlavors {
137             devVersion {
138                 applicationId "org.fdroid.fdroid.dev"
139                 dimension "default"
140                 versionCode 949
141                 versionName "0.95-dev"
142             }
143         }
144
145     }
146
147     sourceSets {
148         main {
149             manifest.srcFile 'AndroidManifest.xml'
150             java.srcDirs = ['src']
151             resources.srcDirs = ['src']
152             aidl.srcDirs = ['src']
153             renderscript.srcDirs = ['src']
154             res.srcDirs = ['res']
155             assets.srcDirs = ['assets']
156         }
157
158         androidTest.setRoot('test')
159         androidTest {
160             manifest.srcFile 'test/AndroidManifest.xml'
161             java.srcDirs = ['test/src']
162             resources.srcDirs = ['test/src']
163             aidl.srcDirs = ['test/src']
164             renderscript.srcDirs = ['test/src']
165             res.srcDirs = ['test/res']
166             assets.srcDirs = ['test/assets']
167         }
168     }
169
170     buildTypes {
171         release {
172             minifyEnabled false
173         }
174         buildTypes {
175             debug {
176                 debuggable true
177             }
178         }
179     }
180
181     compileOptions {
182         compileOptions.encoding = "UTF-8"
183
184         // Use Java 1.7, requires minSdk 8
185         sourceCompatibility JavaVersion.VERSION_1_7
186         targetCompatibility JavaVersion.VERSION_1_7
187     }
188
189     lintOptions {
190         checkReleaseBuilds false
191         abortOnError false
192     }
193
194     // Enable all Android lint warnings
195     gradle.projectsEvaluated {
196         tasks.withType(JavaCompile) {
197             options.compilerArgs << "-Xlint:all"
198         }
199     }
200
201 }
202
203 // This person took the example code below from another blogpost online, however
204 // I lost the reference to it:
205 // http://stackoverflow.com/questions/23297562/gradle-javadoc-and-android-documentation
206 android.applicationVariants.all { variant ->
207
208     task("generate${variant.name}Javadoc", type: Javadoc) {
209         title = "$name $version API"
210         description "Generates Javadoc for F-Droid."
211         source = variant.javaCompile.source
212
213         def sdkDir
214         Properties properties = new Properties()
215         File localProps = project.rootProject.file('local.properties')
216         if (localProps.exists()) {
217             properties.load(localProps.newDataInputStream())
218             sdkDir = properties.getProperty('sdk.dir')
219         } else {
220             sdkDir = System.getenv('ANDROID_HOME')
221         }
222         if (!sdkDir) {
223             throw new ProjectConfigurationException("Cannot find android sdk. Make sure sdk.dir is defined in local.properties or the environment variable ANDROID_HOME is set.", null)
224         }
225
226         ext.androidJar = "${sdkDir}/platforms/${android.compileSdkVersion}/android.jar"
227         classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar)
228         options.links("http://docs.oracle.com/javase/7/docs/api/");
229         options.links("http://d.android.com/reference/");
230         exclude '**/BuildConfig.java'
231         exclude '**/R.java'
232     }
233 }