### Access Git Repository Metadata with JGit Plugin Source: https://context7.com/lsposed/lsplugin/llms.txt Access Git repository metadata such as commit count and latest tag using the JGit plugin. This example shows how to derive version information for Android applications from Git history. The `jgit.repo()` extension can be configured to search from the root project or the subproject directory. ```kotlin plugins { id("org.lsposed.lsplugin.jgit") version "1.1" } val repo = jgit.repo() // fromRootProject = true by default // Derive a version code from commit count on HEAD val commitCount: Int = repo?.commitCount("HEAD") ?: 1 // Read the latest annotated or lightweight tag (e.g. "v1.2.3") val tagName: String = repo?.latestTag ?: "unknown" android { defaultConfig { versionCode = commitCount versionName = tagName } } // Full JGit API available via repo.git and repo.raw: val log = repo?.git?.log()?.setMaxCount(10)?.call() log?.forEach { commit -> println("${commit.abbreviate(7).name()} ${commit.shortMessage}") } // repo() with fromRootProject = false → looks for .git in the subproject dir only val localRepo = jgit.repo(fromRootProject = false) ``` -------------------------------- ### Run aapt2 Sparse-Encoding Optimization on Release APK Resources Source: https://context7.com/lsposed/lsplugin/llms.txt Apply the resopt plugin to your app's build.gradle.kts. This plugin automatically hooks into the AGP 'optimizeResources' task for release build types, re-running aapt2 with sparse-encoding optimization. Failures during this process are silently ignored, preserving the original file. ```kotlin plugins { id("com.android.application") id("org.lsposed.lsplugin.resopt") version "1.6" } android { buildToolsVersion = "35.0.0" // aapt2 is resolved from SDK build-tools at this version buildTypes { release { isMinifyEnabled = true isShrinkResources = true // resopt runs automatically after optimizeReleaseResources } debug { // resopt is a no-op for non-release variants; skipped automatically } } } ``` ```bash $ aapt2 optimize \ --collapse-resource-names \ --enable-sparse-encoding \ -o resources-release-optimize.ap_.opt \ resources-release-optimize.ap_ then the .opt file is renamed back to replace the original .ap_ ``` -------------------------------- ### Configure Maven Central and GitHub Packages Publishing Source: https://context7.com/lsposed/lsplugin/llms.txt Apply the publish plugin to your root build.gradle.kts. For Gradle plugin subprojects, configure the publish block to set up GitHub Packages and register the plugin descriptor with POM details for Maven Central. For plain library artifacts, use the publications() variant. ```kotlin plugins { id("org.lsposed.lsplugin.publish") version "1.3" } // In a Gradle plugin subproject (e.g. myfeature/build.gradle.kts): plugins { `java-gradle-plugin` `maven-publish` signing } version = "2.0" publish { // Sets up a GitHub Packages maven repo using GITHUB_ACTOR / GITHUB_TOKEN env vars githubRepo = "MyOrg/MyRepo" // Register a Gradle plugin AND configure its POM for Maven Central publishPlugin("myfeature", "com.example.MyFeaturePlugin") { name = "My Feature" description = "Does something great." url = "https://github.com/MyOrg/MyRepo" licenses { license { name = "Apache License 2.0" url = "https://www.apache.org/licenses/LICENSE-2.0" } } developers { developer { name = "My Org" url = "https://example.com" } } scm { connection = "scm:git:https://github.com/MyOrg/MyRepo.git" url = "https://github.com/MyOrg/MyRepo" } } // For a plain library (non-plugin) artifact: // publications("my-library") { /* same POM DSL */ } } // Signing keys supplied via Gradle properties (CI: pass as secrets): // ORG_GRADLE_PROJECT_signingKey= // ORG_GRADLE_PROJECT_signingPassword= // Maven Central credentials: // ORG_GRADLE_PROJECT_mavenCentralUsername= // ORG_GRADLE_PROJECT_mavenCentralPassword= // Publish tasks automatically wired by AGP: // ./gradlew :myfeature:publish → publishes to all configured repositories // ./gradlew :myfeature:publishToMavenLocal ``` ```kotlin plugins { id("org.lsposed.lsplugin.publish") version "1.3" } ``` -------------------------------- ### Configure Release Signing with ApkSign Plugin Source: https://context7.com/lsposed/lsplugin/llms.txt The apksign plugin reads keystore credentials from Gradle properties to configure release signing. If the keystore file is not found, it falls back to the debug signing configuration. ```kotlin // settings.gradle.kts — apply from the plugin portal / local maven pluginManagement { repositories { mavenCentral() gradlePluginPortal() } } // app/build.gradle.kts plugins { id("com.android.application") id("org.lsposed.lsplugin.apksign") version "1.4" } // Configure via property names — the plugin resolves actual values from // gradle.properties or -P flags at configuration time. apksign { storeFileProperty = "myApp.storeFile" // property whose value is the keystore path storePasswordProperty = "myApp.storePassword" keyAliasProperty = "myApp.keyAlias" keyPasswordProperty = "myApp.keyPassword" } // gradle.properties (local, git-ignored): // myApp.storeFile=../release.jks // myApp.storePassword=s3cr3t // myApp.keyAlias=mykey // myApp.keyPassword=s3cr3t // Result: a signing config named "apksign" is created and applied to every // build type. If ../release.jks doesn't exist, all build types fall back to // the "debug" signing config and a warning is printed. ``` -------------------------------- ### Custom APK Transformations with ApkTransform Plugin Source: https://context7.com/lsposed/lsplugin/llms.txt The apktransform plugin allows custom per-variant APK transformations. Use the 'transform' function for full control over the artifact or 'copy' for simple APK copying to a specified destination. ```kotlin // app/build.gradle.kts plugins { id("com.android.application") id("org.lsposed.lsplugin.apktransform") version "1.2" } apktransform { // transform: full control — receive the BuiltArtifact, return the replacement File transform { variant -> if (variant.buildType == "release") { { artifact -> val src = File(artifact.outputFile) val dest = File(src.parent, "signed-${src.name}") // custom processing: e.g. re-signing, patching manifest, etc. src.copyTo(dest, overwrite = true) dest // return the new file; null would leave original in place } } else null // null action = skip this variant entirely } // copy: simple variant — just declare where the APK should land copy { variant -> when (variant.buildType) { "release" -> rootProject.file("out/app-release.apk") "debug" -> rootProject.file("out/app-debug.apk") else -> null // null = don't copy this variant } } } // Registered Gradle tasks (one per variant): // :app:transformReleaseApk // :app:copyReleaseApk // :app:copyDebugApk ``` -------------------------------- ### Configure CMaker Plugin for Default and Build Type Flags Source: https://context7.com/lsposed/lsplugin/llms.txt Apply opinionated default C/C++ compiler flags across all subprojects using the CMaker plugin. Configure default arguments and C++ flags, and layer in build-type-specific options like LTO and optimization for release and debug builds. ```kotlin plugins { id("com.android.application") apply false id("org.lsposed.lsplugin.cmaker") version "1.4" } cmarker { // default() → applied to defaultConfig.externalNativeBuild.cmake for every variant default { // Runs after the built-in flags (-Wall, -fno-rtti, -fno-exceptions, etc.) // Add project-specific defines here: arguments += "-DPROJECT_VERSION=42" cppFlags("-DENABLE_FEATURE_X") // ccache is auto-detected from PATH or the "ccache.path" Gradle property // and injected as -DANDROID_CCACHE= automatically. } // buildTypes() → applied per build type; receives the BuildType object buildTypes { buildType -> when (buildType.name) { "release" -> { // Runs after built-in LTO + section GC flags and // -DCMAKE_BUILD_TYPE=Release / -Oz -DNDEBUG injection arguments += "-DRELEASE_ONLY_FLAG=1" } "debug" -> { // -Og injected automatically; add extras here arguments += "-DDEBUG_LOGGING=1" } } } } // To find a tool in PATH or fall back to a Gradle property: // val ninjaPath = project.findInPath("ninja", "ninja.path") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.