0
0
mirror of https://github.com/ankidroid/Anki-Android.git synced 2024-09-20 12:02:16 +02:00
Anki-Android/build.gradle

144 lines
6.2 KiB
Groovy
Raw Normal View History

import org.gradle.internal.jvm.Jvm
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilerExecutionStrategy
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
// The version for the Kotlin plugin and dependencies
ext.kotlin_version = '1.7.0'
2022-05-30 16:43:35 +02:00
ext.lint_version = '30.2.1'
ext.acra_version = '5.7.0'
Update to Anki 2.1.54 backend Squashes a few commits: Move the legacy schema toggle into BackendFactory Simplify backend handling; rework collection instantiation When the Rust code was initially introduced, it was not clear whether it would be usable on all devices, or whether it would need to be removed for some reason. This no doubt influenced the design of the existing API, which tries to make it easy to swap the Rust code out with something else. Unfortunately this approach has some downsides: - It makes it somewhat harder to follow, as method calls jump through multiple interfaces before they're actually sent to the backend. - It makes utilizing new methods considerably more cumbersome. For example, take the extract_av_tags() call. It follows the following path: collection method or method in related helper class: https://github.com/ankidroid/Anki-Android/blob/cea79e1b077bc30e7eed8f37529002aae416d34d/AnkiDroid/src/main/java/com/ichi2/libanki/TemplateManager.kt#L242 to generic interface: https://github.com/ankidroid/Anki-Android/blob/cea79e1b077bc30e7eed8f37529002aae416d34d/AnkiDroid/src/main/java/com/ichi2/libanki/backend/DroidBackend.kt#L83 to specific implementation: https://github.com/ankidroid/Anki-Android/blob/cea79e1b077bc30e7eed8f37529002aae416d34d/AnkiDroid/src/main/java/com/ichi2/libanki/backend/RustDroidV16Backend.kt#L57 and if it's unusable with the legacy schema (which I don't believe is actually true in this case), it also needs to be added to the other implementation: https://github.com/ankidroid/Anki-Android/blob/cea79e1b077bc30e7eed8f37529002aae416d34d/AnkiDroid/src/main/java/com/ichi2/libanki/backend/RustDroidBackend.kt#L87 and then finally, a method in the backend module is invoked. The backend module has code generation so that invoking a backend method is as simple as making a method call, but currently you have to weave the call through 3 or so levels of indirection before you can actually use it. With something like 170 available methods, that's a fair amount of extra work required. Rather than trying to insulate libanki from the backend code, this PR drops some of the indirection in favour of the approach the desktop takes: libanki is the insulation layer; it can call freely into the backend methods, but consumers (eg the GUI code) are expected to only call methods on the collection, and not access the backend directly. In addition to the above, collection initialization has been reworked to be more similar to the computer version. Instead of the collection being created from a database object, a backend is passed into the collection creation, and the collection takes care of creating a DB instance that wraps the backend. Remove always-on isUsingRustBackend Drop the legacy upgrade/initialization code Schema 11 was introduced in 2012, and decks that still are <11 are very rare. The desktop dropped support for schema 10 back in early 2020. This also removes the need to modify SCHEMA_VERSION when switching between TESTING_USE_V16_BACKEND. Remove DOWNGRADE_REQUIRED and slightly simplify startup error handling - The backend automatically downgrades when required, and possible. No backup is required, as the downgrade happens in a single transaction, and the downgrade code has proven itself over time. - Store the type of failure in getColSafe(), so it can be checked later. Update to work with desktop 2.1.53 code Depends on https://github.com/ankidroid/Anki-Android-Backend/pull/202 Due to the removal and change of a few backend methods, syncing, importing and the card templates screen will not work when the schema16 setting is active (actually schema18 now). To get them working again, those code paths will need to switch to the backend implementations. A few notes: - Downgrading happens automatically when loading the collection in schema11 mode, so the extra code dealing with downgrades & "can downgrade" reporting can be stripped. - Added the ability to run col.set_config("key", JSONObject.NULL), as unit tests were attempting to write the entire collection config, which is no longer supported. - All tests pass on both old and new backends, though the latter required disabling a few failed tests when running with the new schema (eg notetype updating). Integrates, and thus closes #11579 and closes #11581 Remove the time argument to Storage.collection() Collection does not currently take a time argument, and relies on the global object instead, so this change brings Storage in line with it. Reuse the backend when closing+reopening a collection Avoids having to re-initialize the translations, and reduces leaks (the import + export code leaks backends still)
2022-06-28 08:03:17 +02:00
ext.ankidroid_backend_version = '0.1.14-anki2.1.54'
ext.hamcrest_version = '2.2'
ext.junit_version = '5.8.2'
ext.coroutines_version = '1.6.2'
repositories {
google()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
2022-05-30 16:43:35 +02:00
classpath 'com.android.tools.build:gradle:7.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath "app.brant:amazonappstorepublisher:0.1.0"
2021-05-26 21:24:24 +02:00
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jlleitschuh.gradle:ktlint-gradle:10.3.0"
}
}
2021-05-27 07:41:13 +02:00
repositories {
mavenCentral()
}
allprojects {
apply plugin: "org.jlleitschuh.gradle.ktlint"
}
// Here we extract per-module "best practices" settings to a single top-level evaluation
subprojects {
afterEvaluate { project ->
if (project.hasProperty('android')) {
project.android.testOptions.unitTests {
includeAndroidResources = true
}
project.android.testOptions.unitTests.all {
useJUnitPlatform()
testLogging {
events "failed", "skipped"
showStackTraces = true
exceptionFormat = "full"
}
maxParallelForks = gradleTestMaxParallelForks
forkEvery = 40
systemProperties['junit.jupiter.execution.parallel.enabled'] = true
systemProperties['junit.jupiter.execution.parallel.mode.default'] = "concurrent"
}
}
// Deprecation is an error. Use @SuppressWarnings("deprecation") and justify in the PR if you must
project.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
}
ktlint {
// remove version override when ktlint gradle plugin releases with 0.45+ transitive
// check here https://github.com/JLLeitschuh/ktlint-gradle/blob/ddd465e28d77b879384886e1eef5666ebe518b4d/plugin/gradle/libs.versions.toml#L3
version = "0.45.2"
disabledRules = ["no-wildcard-imports"]
}
/**
Kotlin allows concrete function implementations inside interfaces.
For those to work when Kotlin compilation targets the JVM backend, you have to enable the interoperability via
'freeCompilerArgs' in your gradle file, and you have to choose one of the appropriate '-Xjvm-default' modes.
https://kotlinlang.org/docs/java-to-kotlin-interop.html#default-methods-in-interfaces
and we used "all" because we don't have downstream consumers
https://docs.gradle.org/current/userguide/task_configuration_avoidance.html
*/
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions {
allWarningsAsErrors = true
freeCompilerArgs = ['-Xjvm-default=all']
}
}
}
}
2016-03-11 23:45:45 +01:00
ext {
jvmVersion = Jvm.current().javaVersion.majorVersion
2021-04-16 20:26:10 +02:00
if (jvmVersion != "11" && jvmVersion != "14" && jvmVersion != "16") {
println "\n\n\n"
println "**************************************************************************************************************"
println "\n\n\n"
2021-04-16 20:26:10 +02:00
println "ERROR: AnkiDroid builds with JVM version 11, 14, or 16."
println " Incompatible major version detected: '" + jvmVersion + "'"
println "\n\n\n"
println "**************************************************************************************************************"
println "\n\n\n"
System.exit(1)
}
ciBuild = System.getenv("CI") == "true" // works for Travis CI or Github Actions
2016-03-11 23:45:45 +01:00
// allows for -Dpre-dex=false to be set
preDexEnabled = "true" == System.getProperty("pre-dex", "true")
// allows for universal APKs to be generated
universalApkEnabled = "true" == System.getProperty("universal-apk", "false")
if (System.getProperty("os.name") == "Mac OS X") {
// macOS reports hardware cores. This is accurate for CI, Intel (halved due to SMT) and Apple Silicon
gradleTestMaxParallelForks = "sysctl -n hw.physicalcpu".execute().text.toInteger()
} else if (ciBuild) {
// GitHub Actions (Standard_DS2_v2) are 1:1 on Linux/Windows with two vCPU cores
// Sources:
// Standard_DS2_v2 https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#cloud-hosts-for-github-hosted-runners
// Which is 1:1 https://docs.microsoft.com/en-gb/azure/virtual-machines/acu : DS1_v2 - DS15_v2 | 1:1
gradleTestMaxParallelForks = 2
// separate gradle compile process is a major speed improvement, but consumes 2x RAM
// the CI machines don't have enough RAM to do that without going in to swap quite a bit
// so for CI machines only - to improve reliability despite compilation speed hit, compile kotlin in process
println "CI build detected: setting compiler execution strategy to IN_PROCESS"
tasks.withType(KotlinCompile).configureEach {
compilerExecutionStrategy.set(KotlinCompilerExecutionStrategy.IN_PROCESS)
}
} else {
// Use 50% of cores to account for SMT which doesn't help this workload
gradleTestMaxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
}
2016-10-23 10:55:19 +02:00
}