build.gradle 6 KB
Newer Older
1
apply plugin: 'com.android.application'
2
apply plugin: 'witness'
3
apply from: 'witness.gradle'
4

5
def getStdout = { command, defaultValue ->
6 7 8
	def stdout = new ByteArrayOutputStream()
	try {
		exec {
9
			commandLine = command
10 11 12 13
			standardOutput = stdout
		}
		return stdout.toString().trim()
	} catch (Exception ignored) {
14
		return defaultValue
15 16 17
	}
}

18
android {
19 20
	compileSdkVersion 28
	buildToolsVersion '28.0.2'
21

22
	defaultConfig {
akwizgran's avatar
akwizgran committed
23
		minSdkVersion 15
24
		targetSdkVersion 26
25 26
		versionCode 10101
		versionName "1.1.1"
27
		applicationId "org.briarproject.briar.android"
28 29
		buildConfigField "String", "GitHash",
				"\"${getStdout(['git', 'rev-parse', '--short=7', 'HEAD'], 'No commit hash')}\""
30
		def now = (long) (System.currentTimeMillis() / 1000)
31
		buildConfigField "Long", "BuildTimestamp",
32
				"${getStdout(['git', 'log', '-n', '1', '--format=%ct'], now)}000L"
33
		testInstrumentationRunner 'org.briarproject.briar.android.BriarTestRunner'
34
	}
35

36 37
	buildTypes {
		debug {
38
			applicationIdSuffix ".debug"
39
			shrinkResources false
40
			minifyEnabled true
Torsten Grote's avatar
Torsten Grote committed
41
			crunchPngs false
42
			proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
43 44
			testProguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt', 'proguard-test.txt'
		}
45
		release {
46
			shrinkResources false
47
			minifyEnabled true
Torsten Grote's avatar
Torsten Grote committed
48
			crunchPngs false
49 50 51
			proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
		}
	}
52

53 54 55 56 57 58 59
	flavorDimensions "version"
	productFlavors {
		screenshot {
			dimension "version"
			minSdkVersion 18
			applicationIdSuffix ".screenshot" // = org.briarproject.briar.android.screenshot.debug
		}
60
		official {
61 62 63 64 65 66 67 68 69
			dimension "version"
		}
	}
	variantFilter { variant ->
		if (variant.flavors*.name.contains("screenshot") && variant.buildType.name == "release") {
			setIgnore(true)
		}
	}

70
	compileOptions {
71 72
		sourceCompatibility JavaVersion.VERSION_1_8
		targetCompatibility JavaVersion.VERSION_1_8
73
	}
74

75 76 77 78 79 80
	testOptions {
		unitTests {
			includeAndroidResources = true
		}
	}

81
	lintOptions {
ligi's avatar
ligi committed
82 83
		warning 'MissingTranslation'
		warning 'ImpliedQuantity'
84
		warning 'ExtraTranslation'
85
	}
86
}
Julian Dehm's avatar
Julian Dehm committed
87

88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
dependencies {
	implementation project(path: ':briar-core', configuration: 'default')
	implementation project(path: ':bramble-core', configuration: 'default')
	implementation project(':bramble-android')

	def supportVersion = '27.1.1'
	implementation "com.android.support:support-v4:$supportVersion"
	implementation("com.android.support:appcompat-v7:$supportVersion") {
		exclude module: 'support-v4'
	}
	implementation("com.android.support:preference-v14:$supportVersion") {
		exclude module: 'support-v4'
	}
	implementation("com.android.support:design:$supportVersion") {
		exclude module: 'support-v4'
		exclude module: 'recyclerview-v7'
	}
	implementation "com.android.support:cardview-v7:$supportVersion"
	implementation "com.android.support:support-annotations:$supportVersion"
	implementation 'com.android.support.constraint:constraint-layout:1.1.3'

	implementation('ch.acra:acra:4.9.1') {
		exclude module: 'support-v4'
		exclude module: 'support-annotations'
	}
	implementation 'info.guardianproject.panic:panic:0.5'
	implementation 'info.guardianproject.trustedintents:trustedintents:0.2'
	implementation 'de.hdodenhof:circleimageview:2.2.0'
	implementation 'com.google.zxing:core:3.3.0'
	implementation 'uk.co.samuelwall:material-tap-target-prompt:2.8.0'
	implementation 'com.vanniktech:emoji-google:0.5.1'

	annotationProcessor 'com.google.dagger:dagger-compiler:2.0.2'

	compileOnly 'javax.annotation:jsr250-api:1.0'

	testImplementation project(path: ':bramble-api', configuration: 'testOutput')
	testImplementation project(path: ':bramble-core', configuration: 'testOutput')
	testImplementation 'org.robolectric:robolectric:3.8'
	testImplementation 'org.robolectric:shadows-support-v4:3.3.2'
	testImplementation 'org.mockito:mockito-core:2.13.0'
	testImplementation 'junit:junit:4.12'
	testImplementation "org.jmock:jmock:2.8.2"
	testImplementation "org.jmock:jmock-junit4:2.8.2"
	testImplementation "org.jmock:jmock-legacy:2.8.2"
	testImplementation "org.hamcrest:hamcrest-library:1.3"
	testImplementation "org.hamcrest:hamcrest-core:1.3"

	def espressoVersion = '3.0.2'
	androidTestImplementation "com.android.support.test.espresso:espresso-core:$espressoVersion"
	androidTestImplementation "com.android.support.test.espresso:espresso-contrib:$espressoVersion"
	androidTestImplementation "com.android.support.test.espresso:espresso-intents:$espressoVersion"
	androidTestAnnotationProcessor "com.google.dagger:dagger-compiler:2.0.2"
	androidTestCompileOnly 'javax.annotation:jsr250-api:1.0'
	androidTestImplementation 'junit:junit:4.12'
143
	androidTestScreenshotImplementation "tools.fastlane:screengrab:1.2.0"
144 145 146
	androidTestScreenshotImplementation "com.android.support.test.uiautomator:uiautomator-v18:2.1.3"
}

Julian Dehm's avatar
Julian Dehm committed
147 148
task verifyTranslations {
	doLast {
149
		def file = project.file("src/main/res/values/arrays.xml")
Julian Dehm's avatar
Julian Dehm committed
150 151 152 153 154 155
		def arrays = new XmlParser().parse(file)
		def lc = arrays.children().find { it.@name == "pref_language_values" }
		def translations = []
		lc.children().each { value -> translations.add(value.text()) }

		def folders = ["default", "en-US"]
156
		def exceptions = ["values-night", "values-v21", "values-ldrtl"]
157
		project.file("src/main/res").eachDir { dir ->
158
			if (dir.name.startsWith("values-") && !exceptions.contains(dir.name)) {
Julian Dehm's avatar
Julian Dehm committed
159 160 161 162
				folders.add(dir.name.substring(7).replace("-r", "-"))
			}
		}
		folders.each { n ->
Julian Dehm's avatar
Julian Dehm committed
163
			if (!translations.remove(n) && n != 'iw') {
Julian Dehm's avatar
Julian Dehm committed
164 165 166 167 168 169
				throw new GradleException("Translation " + n + " is missing in $file")
			}
		}
		if (translations.size() != 0)
			throw new GradleException("Translations\n" + translations.join("\n")
					+ "\nhave no matching value folder")
Julian Dehm's avatar
Julian Dehm committed
170 171

		// Some devices use iw instead of he for hebrew
172 173
		def hebrew_legacy = project.file("src/main/res/values-iw")
		def hebrew = project.file("src/main/res/values-he")
Julian Dehm's avatar
Julian Dehm committed
174 175 176 177
		// Copy values-he to values-iw
		if (hebrew.exists()) {
			hebrew_legacy.mkdir()
			copy {
178 179
				from hebrew.getAbsolutePath()
				into hebrew_legacy.getAbsolutePath()
Julian Dehm's avatar
Julian Dehm committed
180 181
			}
		}
Julian Dehm's avatar
Julian Dehm committed
182 183 184 185 186 187
	}
}

project.afterEvaluate {
	preBuild.dependsOn.add(verifyTranslations)
}