mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 10:46:53 -04:00
468 lines
15 KiB
Groovy
468 lines
15 KiB
Groovy
import com.android.build.OutputFile
|
|
import groovy.json.JsonSlurper
|
|
|
|
buildscript {
|
|
repositories {
|
|
mavenCentral()
|
|
jcenter()
|
|
google()
|
|
}
|
|
|
|
dependencies {
|
|
classpath 'com.testdroid:gradle:1.5.0'
|
|
classpath 'org.apache.httpcomponents:httpclient-android:4.3.3'
|
|
}
|
|
}
|
|
|
|
plugins {
|
|
id 'com.android.application'
|
|
id 'kotlin-android'
|
|
id 'kotlin-android-extensions'
|
|
id 'kotlin-kapt'
|
|
id 'checkstyle'
|
|
id 'io.objectbox'
|
|
id 'com.github.triplet.play' version '2.2.1'
|
|
}
|
|
|
|
apply plugin: 'testdroid'
|
|
apply plugin: 'jacoco-android'
|
|
|
|
repositories {
|
|
mavenCentral()
|
|
jcenter()
|
|
maven {
|
|
url 'https://maven.google.com'
|
|
}
|
|
google()
|
|
}
|
|
|
|
String[] archs = ['arm64-v8a', 'armeabi-v7a', 'x86', 'x86_64']
|
|
dependencies {
|
|
|
|
// Get kiwixlib online if it is not populated locally
|
|
if (file("../kiwixlib/src/main").list().length == 1) {
|
|
implementation 'org.kiwix.kiwixlib:kiwixlib:1.0.12'
|
|
} else {
|
|
implementation project(':kiwixlib')
|
|
archs = file("../kiwixlib/src/main/jniLibs").list()
|
|
}
|
|
|
|
// Storage Devices
|
|
implementation 'eu.mhutti1.utils.storage:android-storage-devices:0.6.2'
|
|
|
|
// Android Support
|
|
implementation "com.android.support:appcompat-v7:$supportLibraryVersion"
|
|
implementation "com.android.support:support-v13:$supportLibraryVersion"
|
|
implementation "com.android.support:support-v4:$supportLibraryVersion"
|
|
implementation "com.android.support:design:$supportLibraryVersion"
|
|
implementation "com.android.support:cardview-v7:$supportLibraryVersion"
|
|
|
|
androidTestImplementation 'com.android.support.test.uiautomator:uiautomator-v18:2.1.3'
|
|
|
|
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1', {
|
|
exclude group: 'com.android.support', module: 'support-annotations'
|
|
}
|
|
|
|
androidTestImplementation 'com.android.support.test.espresso:espresso-web:3.0.1'
|
|
androidTestImplementation 'com.android.support.test.espresso:espresso-intents:3.0.1'
|
|
androidTestImplementation 'com.android.support.test.espresso:espresso-idling-resource:3.0.1'
|
|
androidTestImplementation 'com.android.support.test.espresso:espresso-contrib:3.0.0', {
|
|
exclude group: 'com.android.support', module: 'support-v4'
|
|
exclude group: 'com.android.support', module: 'appcompat-v7'
|
|
exclude group: 'com.android.support', module: 'design'
|
|
exclude group: 'com.android.support', module: 'recyclerview-v7'
|
|
}
|
|
|
|
androidTestImplementation('com.schibsted.spain:barista:2.4.0') {
|
|
exclude group: 'com.android.support'
|
|
}
|
|
|
|
androidTestImplementation "com.android.support:support-annotations:$supportLibraryVersion"
|
|
androidTestImplementation 'com.android.support.test:runner:1.0.1'
|
|
androidTestImplementation 'com.android.support.test:rules:1.0.1'
|
|
|
|
// Dagger
|
|
compileOnly "javax.annotation:javax.annotation-api:$javaxAnnotationVersion"
|
|
androidTestCompileOnly "javax.annotation:javax.annotation-api:$javaxAnnotationVersion"
|
|
implementation "com.google.dagger:dagger:$daggerVersion"
|
|
implementation "com.google.dagger:dagger-android:$daggerVersion"
|
|
kapt "com.google.dagger:dagger-compiler:$daggerVersion"
|
|
kapt "com.google.dagger:dagger-android-processor:$daggerVersion"
|
|
kaptAndroidTest "com.google.dagger:dagger-compiler:$daggerVersion"
|
|
|
|
// SquiDB
|
|
implementation 'com.yahoo.squidb:squidb:2.0.0'
|
|
implementation 'com.yahoo.squidb:squidb-annotations:2.0.0'
|
|
kapt 'com.yahoo.squidb:squidb-processor:2.0.0'
|
|
|
|
// Square
|
|
implementation "com.squareup.okhttp3:okhttp:$okHttpVersion"
|
|
implementation "com.squareup.okhttp3:logging-interceptor:$okHttpVersion"
|
|
implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
|
|
implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofitVersion"
|
|
implementation('com.squareup.retrofit2:converter-simplexml:2.1.0') {
|
|
exclude group: 'xpp3', module: 'xpp3'
|
|
exclude group: 'stax', module: 'stax-api'
|
|
exclude group: 'stax', module: 'stax'
|
|
}
|
|
androidTestImplementation 'com.squareup.okhttp3:mockwebserver:3.6.0'
|
|
|
|
// Butterknife
|
|
implementation 'com.jakewharton:butterknife:8.0.1'
|
|
kapt 'com.jakewharton:butterknife-compiler:8.0.1'
|
|
|
|
// RxJava
|
|
implementation "io.reactivex.rxjava2:rxandroid:$rxAndroidVersion"
|
|
implementation "io.reactivex.rxjava2:rxjava:$rxJavaVersion"
|
|
|
|
// JUnit
|
|
androidTestImplementation 'junit:junit:4.12'
|
|
|
|
// Mockito
|
|
androidTestImplementation "org.mockito:mockito-android:2.24.5"
|
|
|
|
// Leak canary
|
|
implementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.3'
|
|
// Only enable leak canary in debug builds
|
|
configurations.all { config ->
|
|
if (config.name.contains('debug') || config.name.contains("Debug")) {
|
|
config.resolutionStrategy.eachDependency { details ->
|
|
if (details.requested.group == 'com.squareup.leakcanary' &&
|
|
details.requested.name == 'leakcanary-android-no-op') {
|
|
details.useTarget(group: details.requested.group, name: 'leakcanary-android',
|
|
version: details.requested.version)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
|
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
|
|
implementation "android.arch.lifecycle:extensions:1.1.1"
|
|
implementation "io.objectbox:objectbox-kotlin:$objectboxVersion"
|
|
implementation "io.objectbox:objectbox-rxjava:$objectboxVersion"
|
|
|
|
testImplementation "org.junit.jupiter:junit-jupiter:5.4.2"
|
|
testImplementation "io.mockk:mockk:1.9"
|
|
testImplementation "org.assertj:assertj-core:3.11.1"
|
|
//update this with androidx
|
|
testImplementation 'com.jraska.livedata:testing-ktx:0.2.1'
|
|
testImplementation 'android.arch.core:core-testing:1.1.1'
|
|
|
|
}
|
|
|
|
// Set custom app import directory
|
|
def map = [:]
|
|
def custom = new File("app/src")
|
|
if (project.hasProperty('customDir')) {
|
|
custom = file(project.property('customDir'))
|
|
}
|
|
|
|
// Set up flavours for each custom app in the directory
|
|
if (custom.listFiles()) {
|
|
custom.eachFile() { file ->
|
|
|
|
def fileName = file.getName()
|
|
if (fileName.startsWith(".") ||
|
|
fileName.contains("test") ||
|
|
fileName == "main" ||
|
|
fileName.contains("Test")) {
|
|
return
|
|
}
|
|
map.put(fileName, file.getAbsolutePath())
|
|
}
|
|
}
|
|
|
|
jacoco {
|
|
toolVersion = "0.8.3"
|
|
}
|
|
|
|
tasks.withType(Test) {
|
|
jacoco.includeNoLocationClasses = true
|
|
}
|
|
|
|
def branchName = System.getenv('TRAVIS_PULL_REQUEST') ?: "false" == "false"
|
|
? System.getenv('TRAVIS_BRANCH') ?: "local"
|
|
: System.getenv('TRAVIS_PULL_REQUEST_BRANCH')
|
|
def buildNumber = System.getenv('TRAVIS_BUILD_NUMBER') ?: "dev"
|
|
|
|
ext {
|
|
versionMajor = 2
|
|
versionMinor = 5
|
|
versionPatch = 0
|
|
}
|
|
|
|
private String generateVersionName() {
|
|
"${ext.versionMajor}.${ext.versionMinor}.${ext.versionPatch}"
|
|
}
|
|
|
|
private Integer generateVersionCode() {
|
|
200000 + (ext.versionMajor * 10000) + (ext.versionMinor * 100) + (ext.versionPatch)
|
|
}
|
|
|
|
android {
|
|
compileSdkVersion 27
|
|
|
|
defaultConfig {
|
|
minSdkVersion 15
|
|
targetSdkVersion 27
|
|
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
|
// See https://github.com/linkedin/dexmaker/issues/65 for why we need the following line.
|
|
testInstrumentationRunnerArguments.notClass = 'com.android.dex.DexIndexOverflowException'
|
|
vectorDrawables.useSupportLibrary = true
|
|
archivesBaseName = "${branchName.replace('/', '-')}-$buildNumber"
|
|
}
|
|
|
|
aaptOptions {
|
|
cruncherEnabled true
|
|
}
|
|
|
|
lintOptions {
|
|
// Treat lint seriously
|
|
abortOnError true
|
|
// Hardcoded strings in xml
|
|
error 'HardcodedText'
|
|
// Hardcoded strings in setText
|
|
error 'SetTextI18n'
|
|
// Strings.xml issues
|
|
warning 'ExtraTranslation'
|
|
warning 'MissingTranslation'
|
|
|
|
// Warnings
|
|
warning 'InvalidPackage'
|
|
warning 'StringFormatInvalid'
|
|
}
|
|
testOptions {
|
|
unitTests.returnDefaultValues = true
|
|
unitTests.all {
|
|
useJUnitPlatform()
|
|
testLogging {
|
|
events "passed", "skipped", "failed", "standardOut", "standardError"
|
|
outputs.upToDateWhen { false }
|
|
showStandardStreams = true
|
|
}
|
|
}
|
|
}
|
|
|
|
flavorDimensions "default"
|
|
|
|
signingConfigs {
|
|
release {
|
|
storeFile file("../kiwix-android.keystore")
|
|
storePassword System.getenv("KEY_STORE_PASSWORD") ?: "000000"
|
|
keyAlias System.getenv("KEY_ALIAS") ?: "keystore"
|
|
keyPassword System.getenv("KEY_PASSWORD") ?: "000000"
|
|
}
|
|
}
|
|
|
|
buildTypes {
|
|
|
|
// Main build type for debugging
|
|
debug {
|
|
buildConfigField "String", "KIWIX_DOWNLOAD_URL", "\"http://download.kiwix.org/\""
|
|
buildConfigField "boolean", "KIWIX_ERROR_ACTIVITY", "false"
|
|
testCoverageEnabled true
|
|
}
|
|
|
|
mock_network {
|
|
initWith(buildTypes.debug)
|
|
matchingFallbacks = ['debug', 'release']
|
|
// TODO add DI for the mock network
|
|
}
|
|
|
|
local_download_server {
|
|
initWith(buildTypes.debug)
|
|
buildConfigField "String", "KIWIX_DOWNLOAD_URL", "\"http://kiwix-download-server/\""
|
|
matchingFallbacks = ['debug', 'release']
|
|
}
|
|
|
|
// Release Type
|
|
release {
|
|
signingConfig signingConfigs.release
|
|
buildConfigField "String", "KIWIX_DOWNLOAD_URL", "\"http://download.kiwix.org/\""
|
|
buildConfigField "boolean", "KIWIX_ERROR_ACTIVITY", "false"
|
|
}
|
|
}
|
|
|
|
productFlavors {
|
|
// Vanilla Kiwix app
|
|
kiwix {
|
|
println "Configuring Kiwix"
|
|
// Set vanilla config
|
|
buildConfigField "boolean", "IS_CUSTOM_APP", "false"
|
|
buildConfigField "boolean", "HAS_EMBEDDED_ZIM", "false"
|
|
buildConfigField "String", "ZIM_FILE_NAME", "\"\""
|
|
buildConfigField "long", "ZIM_FILE_SIZE", "0"
|
|
buildConfigField "int", "CONTENT_VERSION_CODE", "0"
|
|
buildConfigField "String", "ENFORCED_LANG", "\"\""
|
|
resValue "string", "app_name", "Kiwix"
|
|
resValue "string", "app_search_string", "Search Kiwix"
|
|
if (project.hasProperty('version_code')) {
|
|
def version_code = project.property('version_code')
|
|
versionCode version_code.toInteger()
|
|
} else {
|
|
versionCode generateVersionCode()
|
|
}
|
|
if (project.hasProperty('version_name')) {
|
|
versionName project.property('version_name')
|
|
} else {
|
|
versionName generateVersionName()
|
|
}
|
|
}
|
|
|
|
// Custom apps built from a json file, zim file and icon set
|
|
map.each { name, directory ->
|
|
"$name" {
|
|
println "Configuring $name"
|
|
if (name == "kiwix") {
|
|
return
|
|
}
|
|
if (file(directory + "/build.gradle").exists()) {
|
|
apply from: directory + "/build.gradle"
|
|
}
|
|
def jsonFile
|
|
if (project.hasProperty('jsonFile')) {
|
|
// Read json file from properties e.g command line
|
|
jsonFile = file(project.property('jsonFile'))
|
|
} else {
|
|
// If no file provided use the test file
|
|
jsonFile = file(directory + '/info.json')
|
|
}
|
|
def parsedJson = new JsonSlurper().parseText(jsonFile.text)
|
|
def sourceFile = file(parsedJson.zim_file)
|
|
if (!sourceFile.exists()) {
|
|
sourceFile = file(directory + "/" + parsedJson.zim_file)
|
|
}
|
|
if (parsedJson.embed_zim) {
|
|
// Place content in each lib directory for embeded zims
|
|
for (String archName : archs) {
|
|
copy {
|
|
from sourceFile
|
|
into file(directory + "/jniLibs/" + archName)
|
|
rename { String filename -> "libcontent.so" }
|
|
}
|
|
}
|
|
parsedJson.zim_file = "libcontent.so"
|
|
}
|
|
// Set custom config from json
|
|
applicationId "$parsedJson.package"
|
|
buildConfigField "boolean", "IS_CUSTOM_APP", "true"
|
|
buildConfigField "boolean", "HAS_EMBEDDED_ZIM", "$parsedJson.embed_zim"
|
|
def filename
|
|
if (parsedJson.zim_file.lastIndexOf('/') >= 0) {
|
|
filename = parsedJson.zim_file.substring(parsedJson.zim_file.lastIndexOf('/') + 1)
|
|
} else {
|
|
filename = parsedJson.zim_file
|
|
}
|
|
buildConfigField "String", "ZIM_FILE_NAME", "\"$filename\""
|
|
if (project.hasProperty('zim_file_size')) {
|
|
def length = Long.parseLong(project.property('zim_file_size'))
|
|
buildConfigField "long", "ZIM_FILE_SIZE", "${length}L"
|
|
} else {
|
|
long length = sourceFile.length()
|
|
buildConfigField "long", "ZIM_FILE_SIZE", "${length}L"
|
|
}
|
|
if (project.hasProperty('version_code')) {
|
|
def version_code = project.property('version_code')
|
|
versionCode version_code.toInteger()
|
|
} else {
|
|
versionCode parsedJson.version_code.toInteger()
|
|
}
|
|
if (project.hasProperty('version_name')) {
|
|
versionName project.property('version_name')
|
|
} else {
|
|
versionName parsedJson.version_name
|
|
}
|
|
if (project.hasProperty('content_version_code')) {
|
|
def content_version_code = project.property('content_version_code')
|
|
buildConfigField "int", "CONTENT_VERSION_CODE", "$content_version_code"
|
|
} else if (parsedJson.content_version_code != null) {
|
|
buildConfigField "int", "CONTENT_VERSION_CODE", "$parsedJson.content_version_code"
|
|
} else if (project.hasProperty('version_code')) {
|
|
def version_code = project.property('version_code')
|
|
buildConfigField "int", "CONTENT_VERSION_CODE", "$version_code"
|
|
} else if (parsedJson.version_code != null) {
|
|
buildConfigField "int", "CONTENT_VERSION_CODE", "$parsedJson.version_code"
|
|
}
|
|
buildConfigField "String", "ENFORCED_LANG", "\"$parsedJson.enforced_lang\""
|
|
resValue "string", "app_name", "$parsedJson.app_name"
|
|
resValue "string", "app_search_string", 'Search ' + "$parsedJson.app_name"
|
|
}
|
|
}
|
|
}
|
|
|
|
// Set each custom apps respective source directory
|
|
sourceSets {
|
|
map.each { name, directory ->
|
|
"$name" {
|
|
setRoot directory
|
|
jni.srcDirs = []
|
|
jniLibs.srcDir directory + '/jniLibs'
|
|
}
|
|
}
|
|
}
|
|
|
|
compileOptions {
|
|
encoding = "UTF-8"
|
|
sourceCompatibility JavaVersion.VERSION_1_8
|
|
targetCompatibility JavaVersion.VERSION_1_8
|
|
}
|
|
|
|
dexOptions {
|
|
javaMaxHeapSize "4g"
|
|
}
|
|
|
|
/*
|
|
Add back once proguard is configured
|
|
buildTypes {
|
|
release {
|
|
minifyEnabled true
|
|
proguardFiles getDefaultProguardFile('proguard-android.txt')
|
|
}
|
|
}
|
|
*/
|
|
androidExtensions {
|
|
experimental = true
|
|
}
|
|
|
|
def abiCodes = ['arm64-v8a': 1, 'x86': 2, 'x86_64': 3, 'armeabi-v7a': 4]
|
|
splits {
|
|
abi {
|
|
enable true
|
|
reset()
|
|
include "x86", "x86_64", 'armeabi-v7a', "arm64-v8a"
|
|
universalApk true
|
|
}
|
|
}
|
|
applicationVariants.all { variant ->
|
|
variant.outputs.each { output ->
|
|
def baseAbiVersionCode = abiCodes.get(output.getFilter(OutputFile.ABI))
|
|
if (baseAbiVersionCode != null) {
|
|
output.versionCodeOverride = baseAbiVersionCode * 1000000 + variant.versionCode
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
play {
|
|
enabled = branchName == "master" || branchName == "release"
|
|
serviceAccountCredentials = file("../google.json")
|
|
track = "alpha"
|
|
resolutionStrategy = "fail"
|
|
}
|
|
|
|
def findJar(prefix) {
|
|
configurations.runtime.filter { it.name.startsWith(prefix) }
|
|
}
|
|
|
|
testdroid {
|
|
authorization "APIKEY"
|
|
apiKey System.getenv('BITBAR_API_KEY')
|
|
deviceGroup 'Kiwix'
|
|
projectName "Kiwix"
|
|
testRunName "Auto Test " + buildNumber
|
|
|
|
fullRunConfig {
|
|
instrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
|
|
}
|
|
} |