0
0
mirror of https://github.com/ankidroid/Anki-Android.git synced 2024-09-20 12:02:16 +02:00
Anki-Android/AnkiDroid/build.gradle
Mike Hardy fa3c20167b Bumped version to 2.15alpha16
@branch-specific
2020-12-14 14:45:17 +00:00

280 lines
12 KiB
Groovy

import com.android.ddmlib.DdmPreferences
import com.android.build.OutputFile
plugins {
// Gradle plugin portal
id 'com.github.triplet.play' version '3.0.0'
}
apply plugin: 'com.android.application'
apply plugin: 'app.brant.amazonappstorepublisher'
repositories {
google()
jcenter()
}
def homePath = System.properties['user.home']
android {
compileSdkVersion 29 // change .travis.yml build tools at same time
defaultConfig {
applicationId "com.ichi2.anki"
// The version number is of the form:
// <major>.<minor>.<maintenance>[dev|alpha<build>|beta<build>|]
// The <build> is only present for alpha and beta releases (e.g., 2.0.4alpha2 or 2.0.4beta4), developer builds do
// not have a build number (e.g., 2.0.4dev) and official releases only have three components (e.g., 2.0.4).
//
// The version code is derived from the version name as follows:
// AbbCCtDD
// A: 1-digit decimal number representing the major version
// bb: 2-digit decimal number representing the minor version
// CC: 2-digit decimal number representing the maintenance version
// t: 1-digit decimal number representing the type of the build
// 0: developer build
// 1: alpha release
// 2: beta release
// 3: public release
// DD: 2-digit decimal number representing the build
// 00 for internal builds and public releases
// alpha/beta build number for alpha/beta releases
//
// This ensures the correct ordering between the various types of releases (dev < alpha < beta < release) which is
// needed for upgrades to be offered correctly.
versionCode=21500116
versionName="2.15alpha16"
minSdkVersion 21
//noinspection OldTargetApi - also performed in api/build.fradle
targetSdkVersion 29 // change .travis.yml platform download at same time
testApplicationId "com.ichi2.anki.tests"
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
// This enables long timeouts required on slow ARM emulators, e.g. Travis
adbOptions {
//logLevel verbose // let's try to see what is happening
timeOutInMs 20 * 60 * 1000 // 20 minutes
DdmPreferences.setTimeOut(120000)
}
}
signingConfigs {
release {
storeFile file("${homePath}/src/android-keystore")
keyAlias "nrkeystorealias"
storePassword System.getenv("KSTOREPWD")
keyPassword System.getenv("KEYPWD")
}
}
buildTypes {
debug {
debuggable true
splits.abi.universalApk = true // Build universal APK for debug always
// Check Crash Reports page on developer wiki for info on ACRA testing
buildConfigField "String", "ACRA_URL", '"https://918f7f55-f238-436c-b34f-c8b5f1331fe5-bluemix.cloudant.com/acra-ankidroid/_design/acra-storage/_update/report"'
// #6009 Allow optional disabling of JaCoCo for general build (assembleDebug).
// jacocoDebug task was slow, hung, and wasn't required unless I wanted coverage
if (project.rootProject.file('local.properties').exists()) {
Properties localProperties = new Properties()
localProperties.load(project.rootProject.file('local.properties').newDataInputStream())
testCoverageEnabled localProperties['enable_coverage'] != "false"
} else {
testCoverageEnabled true
}
}
release {
minifyEnabled true
splits.abi.universalApk = universalApkEnabled // Build universal APK for release with `-Duniversal-apk=true`
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
buildConfigField "String", "ACRA_URL", '"https://ankidroid.org/acra/report"'
}
}
/**
* Set this to true to create five separate APKs instead of one:
* - 2 APKs that only work on ARM/ARM64 devices
* - 2 APKs that only works on x86/x86_64 devices
* - a universal APK that works on all devices
* The advantage is the size of most APKs is reduced by about 2.5MB.
* Upload all the APKs to the Play Store and people will download
* the correct one based on the CPU architecture of their device.
*/
def enableSeparateBuildPerCPUArchitecture = true
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
//universalApk enableUniversalApk // set in debug + release config blocks above
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
}
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
// purge debug sounds from react-native-background-geolocation-android
if (variant.buildType.name == 'release') {
// We want the same version stream for all ABIs in debug but for release we can split them
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// https://developer.android.com/studio/build/configure-apk-splits.html
def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
// From: https://developer.android.com/studio/publish/versioning#appversioning
// "Warning: The greatest value Google Play allows for versionCode is 2100000000"
// AnkiDroid versionCodes have a budget 8 digits (through AnkiDroid 9)
// This style does ABI version code ranges with the 9th digit as 0-4.
// This consumes ~20% of the version range space, w/50 years of versioning at our major-version pace
output.versionCodeOverride =
// ex: 321200106 = 3 * 100000000 + 21200106
versionCodes.get(abi) * 100000000 + defaultConfig.versionCode
}
}
}
}
testOptions {
animationsDisabled true
unitTests {
includeAndroidResources = true
}
}
dexOptions {
// Skip pre-dexing when running on Travis CI or when disabled via -Dpre-dex=false.
preDexLibraries = preDexEnabled && !travisBuild
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
}
testOptions.unitTests.all {
testLogging {
events "failed", "skipped"
showStackTraces = true
exceptionFormat = "full"
}
maxParallelForks = gradleTestMaxParallelForks
forkEvery = 40
maxHeapSize = "2048m"
minHeapSize = "1024m"
systemProperties['junit.jupiter.execution.parallel.enabled'] = true
systemProperties['junit.jupiter.execution.parallel.mode.default'] = "concurrent"
}
sourceSets {
debug {
manifest.srcFile 'src/test/AndroidManifest.xml'
}
}
ndkVersion "21.3.6528147"
}
play {
serviceAccountCredentials.set(file("${homePath}/src/AnkiDroid-GCP-Publish-Credentials.json"))
track.set('alpha')
}
amazon {
securityProfile = file("${homePath}/src/AnkiDroid-Amazon-Publish-Security-Profile.json")
applicationId = "amzn1.devportal.mobileapp.524a424d314931494c55383833305539"
pathToApks = [ file("./build/outputs/apk/release/AnkiDroid-universal-release.apk") ]
replaceEdit = true
}
// Deprecation is an error. Use @SuppressWarnings("deprecation") and justify in the PR if you must
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:deprecation" << "-Xlint:fallthrough" << "-Xmaxwarns" << "1000" << "-Werror"
// https://guides.gradle.org/performance/#compiling_java
// 1- fork improves things over time with repeated builds, doesn't harm CI single builds
options.fork = true
// 2- incremental will be the default in the future and can help now
options.incremental = true
}
apply from: "./robolectricDownloader.gradle"
apply from: "./jacoco.gradle"
apply from: "../lint.gradle"
dependencies {
// Can possibly remove if upstream PR merges https://github.com/JakeWharton/timber/pull/398
configurations.all {
resolutionStrategy {
force 'org.jetbrains:annotations:20.1.0'
}
}
compileOnly 'org.jetbrains:annotations:20.1.0'
compileOnly "com.google.auto.service:auto-service-annotations:1.0-rc7"
annotationProcessor "com.google.auto.service:auto-service:1.0-rc7"
implementation fileTree(dir: 'libs', include: ['*.jar'])
// Note: the design support library can be quite buggy, so test everything thoroughly before updating it
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.annotation:annotation:1.1.0'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.browser:browser:1.3.0'
implementation 'androidx.exifinterface:exifinterface:1.3.2'
implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'
implementation "androidx.preference:preference:1.1.1"
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.sqlite:sqlite-framework:2.1.0'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'androidx.viewpager2:viewpager2:1.0.0'
implementation 'io.requery:sqlite-android:3.33.0'
implementation 'com.afollestad.material-dialogs:core:0.9.6.0'
implementation 'com.getbase:floatingactionbutton:1.10.1'
// io.github.java-diff-utils:java-diff-utils is the natural successor here, but requires API24, #7091
implementation 'org.bitbucket.cowwoc:diff-match-patch:1.2'
// noinspection GradleDependency - pinned at 1.12 until API26 minSdkVersion (File.toPath usage)
implementation 'org.apache.commons:commons-compress:1.12' // #6419 - handle >2GB apkg files
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
// May need a resolution strategy for support libs to our versions
implementation'ch.acra:acra-http:5.5.1'
implementation'ch.acra:acra-dialog:5.5.1'
implementation'ch.acra:acra-toast:5.5.1'
implementation'ch.acra:acra-limiter:5.5.1'
implementation 'net.mikehardy:google-analytics-java7:2.0.13'
//noinspection GradleDependency NewerVersionAvailable
implementation 'com.squareup.okhttp3:okhttp:3.12.12'
implementation 'com.arcao:slf4j-timber:3.1'
implementation 'com.jakewharton.timber:timber:4.7.1'
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'org.jsoup:jsoup:1.13.1'
api project(":api")
testImplementation 'org.junit.vintage:junit-vintage-engine:5.7.0'
testImplementation 'org.mockito:mockito-inline:3.6.28'
testImplementation 'org.hamcrest:hamcrest-all:1.3'
testImplementation 'net.lachlanmckee:timber-junit-rule:1.0.1'
testImplementation "org.robolectric:robolectric:4.4"
testImplementation 'androidx.test:core:1.3.0'
testImplementation 'androidx.test.ext:junit:1.1.2'
// debugImplementation required vs testImplementation: https://issuetracker.google.com/issues/128612536
debugImplementation("androidx.fragment:fragment-testing:1.2.5") {
// monitor dep constrained to 1.2 by fragment-testing, 1.3+ is needed: https://github.com/android/android-test/issues/481
exclude group:'androidx.test', module:'monitor'
}
// May need a resolution strategy for support libs to our versions
androidTestImplementation 'com.azimolabs.conditionwatcher:conditionwatcher:0.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.3.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test:rules:1.3.0'
//For AnkiDroid JS API Versioning
implementation "com.github.zafarkhaja:java-semver:0.9.0"
}