chiark / gitweb /
Revert: gradle file: use flavour specific versionCode/versionName, fall back to parsi...
[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     sourceSets {
133         main {
134             manifest.srcFile 'AndroidManifest.xml'
135             java.srcDirs = ['src']
136             resources.srcDirs = ['src']
137             aidl.srcDirs = ['src']
138             renderscript.srcDirs = ['src']
139             res.srcDirs = ['res']
140             assets.srcDirs = ['assets']
141         }
142
143         androidTest.setRoot('test')
144         androidTest {
145             manifest.srcFile 'test/AndroidManifest.xml'
146             java.srcDirs = ['test/src']
147             resources.srcDirs = ['test/src']
148             aidl.srcDirs = ['test/src']
149             renderscript.srcDirs = ['test/src']
150             res.srcDirs = ['test/res']
151             assets.srcDirs = ['test/assets']
152         }
153     }
154
155     buildTypes {
156         release {
157             minifyEnabled false
158         }
159         buildTypes {
160             debug {
161                 debuggable true
162             }
163         }
164     }
165
166     compileOptions {
167         compileOptions.encoding = "UTF-8"
168
169         // Use Java 1.7, requires minSdk 8
170         sourceCompatibility JavaVersion.VERSION_1_7
171         targetCompatibility JavaVersion.VERSION_1_7
172     }
173
174     lintOptions {
175         checkReleaseBuilds false
176         abortOnError false
177     }
178
179     // Enable all Android lint warnings
180     gradle.projectsEvaluated {
181         tasks.withType(JavaCompile) {
182             options.compilerArgs << "-Xlint:all"
183         }
184     }
185
186 }
187
188 // This person took the example code below from another blogpost online, however
189 // I lost the reference to it:
190 // http://stackoverflow.com/questions/23297562/gradle-javadoc-and-android-documentation
191 android.applicationVariants.all { variant ->
192
193     task("generate${variant.name}Javadoc", type: Javadoc) {
194         title = "$name $version API"
195         description "Generates Javadoc for F-Droid."
196         source = variant.javaCompile.source
197
198         def sdkDir
199         Properties properties = new Properties()
200         File localProps = project.rootProject.file('local.properties')
201         if (localProps.exists()) {
202             properties.load(localProps.newDataInputStream())
203             sdkDir = properties.getProperty('sdk.dir')
204         } else {
205             sdkDir = System.getenv('ANDROID_HOME')
206         }
207         if (!sdkDir) {
208             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)
209         }
210
211         ext.androidJar = "${sdkDir}/platforms/${android.compileSdkVersion}/android.jar"
212         classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar)
213         options.links("http://docs.oracle.com/javase/7/docs/api/");
214         options.links("http://d.android.com/reference/");
215         exclude '**/BuildConfig.java'
216         exclude '**/R.java'
217     }
218 }