Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions AnkiDroid/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
plugins {
// Gradle plugin portal
alias(libs.plugins.tripletPlay)
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.parcelize)
// TODO: migrate to .kts & replace the next 2 id lines with id("ankidroid.android.app")
id 'com.android.application'
id 'org.jetbrains.kotlin.plugin.parcelize'
Comment thread
david-allison marked this conversation as resolved.
alias(libs.plugins.kotlin.serialization)
alias(libs.plugins.keeper)
alias(libs.plugins.roborazzi)
Expand Down
22 changes: 1 addition & 21 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,15 @@ import com.android.build.api.dsl.LibraryExtension
import com.android.build.gradle.internal.tasks.factory.dependsOn

plugins {
alias(libs.plugins.android.library)
Comment thread
david-allison marked this conversation as resolved.
id("ankidroid.android.api")
id("maven-publish")
}

group = "com.ichi2.anki"
version = "2.0.0"

kotlin {
explicitApi()
compilerOptions {
// enable explicit api mode for additional checks related to the public api
// see https://kotlinlang.org/docs/whatsnew14.html#explicit-api-mode-for-library-authors
freeCompilerArgs.add("-Xexplicit-api=strict")
}
}

configure<LibraryExtension> {
namespace = "com.ichi2.anki.api"
compileSdk =
libs.versions.compileSdk
.get()
.toInt()

buildFeatures {
buildConfig = true
Expand Down Expand Up @@ -55,11 +42,6 @@ configure<LibraryExtension> {
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}
compileOptions {
// API remains on VERSION_11 for compatibility
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

publishing {
singleVariant("release") {
Expand All @@ -69,8 +51,6 @@ configure<LibraryExtension> {
}
}

apply(from = "../lint.gradle")

dependencies {
implementation(libs.androidx.annotation)
implementation(libs.kotlin.stdlib)
Expand Down
12 changes: 7 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ import kotlin.system.exitProcess

// Top-level build file where you can add configuration options common to all subprojects/modules.
plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.android.library) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.kotlin.parcelize) apply false
alias(libs.plugins.kotlin.jvm) apply false
// Use `id` to avoid classpath conflicts. Versions are pinned by buildSrc/.
id("com.android.application") apply false
id("com.android.library") apply false
id("org.jetbrains.kotlin.android") apply false
id("org.jetbrains.kotlin.plugin.parcelize") apply false
id("org.jetbrains.kotlin.jvm") apply false
// Serialization is a separate artifact, not pinned transitively by AGP.
alias(libs.plugins.kotlin.serialization) apply false
alias(libs.plugins.ktlint.gradle.plugin) apply false
alias(libs.plugins.keeper) apply false
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ outside the `.gradle.kts` build scripts.
* NOTE: The overhead for one-off scripts is not worthwhile
* Extracting build logic to support the [Gradle Configuration Cache](https://docs.gradle.org/current/userguide/configuration_cache.html)
* Closures inside `.kts` files can capture an implicit `this` reference, which is CC-incompatible.
* (Planned) Defining a convention plugin to reduce duplication in `.kts` files
* Defining a convention plugin to reduce duplication in `.kts` files
9 changes: 9 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,19 @@ plugins {
}

repositories {
google()
mavenCentral()
gradlePluginPortal()
}

dependencies {
// Needed by precompiled script plugins that apply `com.android.library`.
// Pins AGP/KGP transitively, so call sites need `id("com.android.library")` etc. with no version.
implementation("com.android.tools.build:gradle:${libs.versions.androidGradlePlugin.get()}")
// Force the catalog version of KGP, otherwise it's overridden by AGP.
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:${libs.versions.kotlin.get()}")
}

configure<KtlintExtension> {
version.set(libs.versions.ktlint.get())
}
55 changes: 55 additions & 0 deletions buildSrc/src/main/kotlin/ankidroid.android.api.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2026 David Allison <davidallisongithub@gmail.com>
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/

// Convention plugin: Android library published as a public API artifact.
//
// Distinct from ankidroid.android-library:
// * Java source/target compat is 11 (not 17) for consumer compatibility.
// * Kotlin explicit-API strict mode is enabled (library-author quality check).
// * minSdk is not set.
//
// Publishing (maven-publish, singleVariant setup, POM metadata) is left to
// the consuming module — it's intrinsically per-module configuration.

import com.android.build.api.dsl.LibraryExtension
import com.ichi2.anki.gradle.libsVersionFor
import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension

plugins {
id("com.android.library")
}

extensions.configure<LibraryExtension> {
compileSdk = libsVersionFor("compileSdk").toInt()

compileOptions {
// API remains on VERSION_11 for consumer compatibility.
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
}

extensions.configure<KotlinAndroidProjectExtension> {
explicitApi()
compilerOptions {
// Stricter checks on public API shape for library authors.
// See https://kotlinlang.org/docs/whatsnew14.html#explicit-api-mode-for-library-authors
freeCompilerArgs.add("-Xexplicit-api=strict")
}
}

// Shared project-wide lint configuration.
apply(from = "${rootDir}/lint.gradle")
49 changes: 49 additions & 0 deletions buildSrc/src/main/kotlin/ankidroid.android.library.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2026 David Allison <davidallisongithub@gmail.com>
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/

/*
Convention plugin: applies `com.android.library` and pins the settings
shared across every Android library module in this project.

This does not apply to the API module,
*/

import com.android.build.api.dsl.LibraryExtension
import com.ichi2.anki.gradle.libsVersionFor

plugins {
id("com.android.library")
}

extensions.configure<LibraryExtension> {
compileSdk = libsVersionFor("compileSdk").toInt()

defaultConfig {
minSdk = libsVersionFor("minSdk").toInt()
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
}

// Shared project-wide lint configuration.
apply(from = "${rootDir}/lint.gradle")

// Apply jacoco so module unit tests produce .exec files that
// AnkiDroid's jacocoUnitTestReport aggregates across modules.
apply(from = "${rootDir}/jacocoSupport.gradle")
36 changes: 36 additions & 0 deletions buildSrc/src/main/kotlin/ankidroid.jvm.library.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2026 David Allison <davidallisongithub@gmail.com>
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/

// Convention plugin: applies the Kotlin JVM plugin and pins Java/Kotlin
// toolchain settings for pure-JVM (non-Android) modules in this project.

import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id("org.jetbrains.kotlin.jvm")
}

tasks.withType(JavaCompile::class).configureEach {
sourceCompatibility = JavaVersion.VERSION_17.toString()
targetCompatibility = JavaVersion.VERSION_17.toString()
}

tasks.withType(KotlinCompile::class).configureEach {
compilerOptions {
jvmTarget = JvmTarget.JVM_17
}
}
38 changes: 38 additions & 0 deletions buildSrc/src/main/kotlin/com/ichi2/anki/gradle/VersionCatalogs.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2026 David Allison <davidallisongithub@gmail.com>
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.ichi2.anki.gradle

import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalog
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.kotlin.dsl.getByType

// Type-safe `libs` accessors aren't available in precompiled script plugins,
// so read versions from the `libs` catalog explicitly.

@Volatile
private var cachedLibs: VersionCatalog? = null

// A Project reference is required, so this can't be `by lazy { }`
private fun Project.libs(): VersionCatalog =
cachedLibs ?: extensions
.getByType<VersionCatalogsExtension>()
.named("libs")
.also { cachedLibs = it }

fun Project.libsVersionFor(alias: String): String =
libs().findVersion(alias).get().requiredVersion
4 changes: 0 additions & 4 deletions buildSrc/src/main/kotlin/placeholder.gradle.kts

This file was deleted.

33 changes: 1 addition & 32 deletions common/android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,13 @@
import com.android.build.api.dsl.LibraryExtension

plugins {
alias(libs.plugins.android.library)
id("ankidroid.android.library")
}

configure<LibraryExtension> {
namespace = "com.ichi2.anki.common.android"
compileSdk =
libs.versions.compileSdk
.get()
.toInt()

defaultConfig {
minSdk =
libs.versions.minSdk
.get()
.toInt()
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}

buildTypes {
release {
isMinifyEnabled = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro",
)
}
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
}

apply(from = "../../lint.gradle")
apply(from = "../../jacocoSupport.gradle")

dependencies {
implementation(project(":common"))

Expand Down
35 changes: 0 additions & 35 deletions common/android/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,35 +0,0 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

# FIXME remove this entire Android 4.2 workaround from 12/3/15 timrae commit for 2.15.x+
# Samsung Android 4.2 bug workaround
# https://code.google.com/p/android/issues/detail?id=78377
-keepattributes **
-keep class !android.support.v7.view.menu.**,!android.support.design.internal.NavigationMenu,!android.support.design.internal.NavigationMenuPresenter,!android.support.design.internal.NavigationSubMenu,** {*;}
#5806 - Class: ActionBarOverflow
-keep public class android.support.v7.internal.view.menu.** { *; }
-keep public class androidx.appcompat.view.menu.** { *; }
-dontpreverify
-dontoptimize
-dontshrink
-dontwarn **
-dontnote **
Loading
Loading