├── example ├── app │ ├── .gitignore │ ├── src │ │ ├── rust_library │ │ │ ├── .gitignore │ │ │ ├── Cargo.toml │ │ │ └── src │ │ │ │ └── lib.rs │ │ └── main │ │ │ ├── res │ │ │ ├── values │ │ │ │ ├── dimens.xml │ │ │ │ ├── colors.xml │ │ │ │ ├── strings.xml │ │ │ │ └── themes.xml │ │ │ ├── values-land │ │ │ │ └── dimens.xml │ │ │ ├── values-w600dp │ │ │ │ └── dimens.xml │ │ │ ├── values-w1240dp │ │ │ │ └── dimens.xml │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── menu │ │ │ │ └── menu_main.xml │ │ │ ├── xml │ │ │ │ ├── backup_rules.xml │ │ │ │ └── data_extraction_rules.xml │ │ │ ├── values-night │ │ │ │ └── themes.xml │ │ │ ├── layout │ │ │ │ ├── content_main.xml │ │ │ │ ├── fragment_second.xml │ │ │ │ ├── fragment_first.xml │ │ │ │ └── activity_main.xml │ │ │ ├── navigation │ │ │ │ └── nav_graph.xml │ │ │ ├── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ │ └── drawable │ │ │ │ └── ic_launcher_background.xml │ │ │ ├── java │ │ │ └── dev │ │ │ │ └── matrix │ │ │ │ └── rust │ │ │ │ └── MainActivity.kt │ │ │ └── AndroidManifest.xml │ ├── proguard-rules.pro │ └── build.gradle.kts ├── gradle │ ├── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ └── libs.versions.toml ├── .gitignore ├── build.gradle.kts ├── settings.gradle.kts ├── gradle.properties ├── gradlew.bat └── gradlew ├── gradle ├── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties └── libs.versions.toml ├── .gitignore ├── src └── main │ └── kotlin │ └── dev │ └── matrix │ └── agp │ └── rust │ ├── utils │ ├── Logger.kt │ ├── NullOutputStream.kt │ ├── Os.kt │ ├── RustBinaries.kt │ ├── ProjectExt.kt │ ├── SemanticVersion.kt │ └── Abi.kt │ ├── RustCleanTask.kt │ ├── RustTestTask.kt │ ├── AndroidRustExtension.kt │ ├── RustBuildTask.kt │ ├── RustInstaller.kt │ └── AndroidRustPlugin.kt ├── LICENSE ├── gradlew.bat ├── README.md └── gradlew /example/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /example/app/src/rust_library/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /Cargo.lock 3 | -------------------------------------------------------------------------------- /example/app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 16dp 3 | -------------------------------------------------------------------------------- /example/app/src/main/res/values-land/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 48dp 3 | -------------------------------------------------------------------------------- /example/app/src/main/res/values-w600dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 48dp 3 | -------------------------------------------------------------------------------- /example/app/src/main/res/values-w1240dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 200dp 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatrixDev/GradleAndroidRustPlugin/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /example/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatrixDev/GradleAndroidRustPlugin/HEAD/example/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.gradle 2 | /.idea/ 3 | /build/ 4 | /captures/ 5 | /local.properties 6 | 7 | .DS_Store/ 8 | .externalNativeBuild/ 9 | .cxx/ 10 | *.iml 11 | -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | /.gradle 2 | /.idea/ 3 | /build/ 4 | /captures/ 5 | /local.properties 6 | 7 | .DS_Store/ 8 | .externalNativeBuild/ 9 | .cxx/ 10 | *.iml 11 | -------------------------------------------------------------------------------- /example/app/src/main/res/mipmap-hdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatrixDev/GradleAndroidRustPlugin/HEAD/example/app/src/main/res/mipmap-hdpi/ic_launcher.webp -------------------------------------------------------------------------------- /example/app/src/main/res/mipmap-mdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatrixDev/GradleAndroidRustPlugin/HEAD/example/app/src/main/res/mipmap-mdpi/ic_launcher.webp -------------------------------------------------------------------------------- /example/app/src/main/res/mipmap-xhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatrixDev/GradleAndroidRustPlugin/HEAD/example/app/src/main/res/mipmap-xhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /example/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatrixDev/GradleAndroidRustPlugin/HEAD/example/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /example/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatrixDev/GradleAndroidRustPlugin/HEAD/example/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /src/main/kotlin/dev/matrix/agp/rust/utils/Logger.kt: -------------------------------------------------------------------------------- 1 | package dev.matrix.agp.rust.utils 2 | 3 | internal fun log(message: String) { 4 | println("AndroidRust: $message") 5 | } 6 | -------------------------------------------------------------------------------- /example/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatrixDev/GradleAndroidRustPlugin/HEAD/example/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /example/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatrixDev/GradleAndroidRustPlugin/HEAD/example/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /example/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatrixDev/GradleAndroidRustPlugin/HEAD/example/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /example/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatrixDev/GradleAndroidRustPlugin/HEAD/example/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /example/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatrixDev/GradleAndroidRustPlugin/HEAD/example/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /example/app/src/rust_library/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rust_library" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | [lib] 7 | crate-type = ["cdylib"] 8 | 9 | [dependencies] 10 | jni = "0.19.0" 11 | -------------------------------------------------------------------------------- /gradle/libs.versions.toml: -------------------------------------------------------------------------------- 1 | [versions] 2 | agp = "8.7.2" 3 | 4 | [libraries] 5 | agp = { module = "com.android.tools.build:gradle", version.ref = "agp" } 6 | agp-api = { module = "com.android.tools.build:gradle-api", version.ref = "agp" } 7 | -------------------------------------------------------------------------------- /src/main/kotlin/dev/matrix/agp/rust/utils/NullOutputStream.kt: -------------------------------------------------------------------------------- 1 | package dev.matrix.agp.rust.utils 2 | 3 | import java.io.OutputStream 4 | 5 | internal object NullOutputStream : OutputStream() { 6 | override fun write(value: Int) = Unit 7 | } 8 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Dec 04 11:21:35 EET 2024 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | -------------------------------------------------------------------------------- /example/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Dec 04 11:21:35 EET 2024 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | -------------------------------------------------------------------------------- /example/build.gradle.kts: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | plugins { 3 | alias(libs.plugins.android.application) apply false 4 | alias(libs.plugins.kotlin.android) apply false 5 | alias(libs.plugins.android.rust) apply false 6 | } 7 | -------------------------------------------------------------------------------- /example/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /example/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /example/app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFBB86FC 4 | #FF6200EE 5 | #FF3700B3 6 | #FF03DAC5 7 | #FF018786 8 | #FF000000 9 | #FFFFFFFF 10 | -------------------------------------------------------------------------------- /example/app/src/rust_library/src/lib.rs: -------------------------------------------------------------------------------- 1 | use jni::JNIEnv; 2 | use jni::objects::JObject; 3 | use jni::sys::jstring; 4 | 5 | #[no_mangle] 6 | extern "C" fn Java_dev_matrix_rust_MainActivity_callRustCode(env: JNIEnv, _: JObject) -> jstring { 7 | env.new_string("Hello from rust!").unwrap().into_inner() 8 | } 9 | 10 | #[cfg(test)] 11 | mod test { 12 | #[test] 13 | fn test() { 14 | println!("Hello from rust test!") 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /example/app/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 5 | 10 | -------------------------------------------------------------------------------- /example/app/src/main/res/xml/backup_rules.xml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 13 | -------------------------------------------------------------------------------- /example/app/src/main/java/dev/matrix/rust/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package dev.matrix.rust 2 | 3 | import android.os.Bundle 4 | import android.widget.Toast 5 | import androidx.appcompat.app.AppCompatActivity 6 | 7 | class MainActivity : AppCompatActivity() { 8 | private external fun callRustCode(): String 9 | 10 | override fun onCreate(savedInstanceState: Bundle?) { 11 | super.onCreate(savedInstanceState) 12 | 13 | System.loadLibrary("rust_library") 14 | 15 | Toast.makeText(this, callRustCode(), Toast.LENGTH_LONG).show() 16 | 17 | finish() 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /example/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | GradlePlugin 3 | Settings 4 | 5 | First Fragment 6 | Second Fragment 7 | Next 8 | Previous 9 | 10 | Hello first fragment 11 | Hello second fragment. Arg: %1$s 12 | -------------------------------------------------------------------------------- /src/main/kotlin/dev/matrix/agp/rust/RustCleanTask.kt: -------------------------------------------------------------------------------- 1 | package dev.matrix.agp.rust 2 | 3 | import org.gradle.api.DefaultTask 4 | import org.gradle.api.provider.Property 5 | import org.gradle.api.tasks.Input 6 | import org.gradle.api.tasks.TaskAction 7 | import java.io.File 8 | 9 | internal abstract class RustCleanTask : DefaultTask() { 10 | @get:Input 11 | abstract val variantJniLibsDirectory: Property 12 | 13 | @TaskAction 14 | fun taskAction() { 15 | val variantJniLibsDirectory = variantJniLibsDirectory.get() 16 | 17 | project.delete { 18 | delete(variantJniLibsDirectory) 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /example/app/src/main/res/xml/data_extraction_rules.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 12 | 13 | 19 | -------------------------------------------------------------------------------- /example/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /example/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | google { 4 | content { 5 | includeGroupByRegex("com\\.android.*") 6 | includeGroupByRegex("com\\.google.*") 7 | includeGroupByRegex("androidx.*") 8 | } 9 | } 10 | mavenCentral() 11 | gradlePluginPortal() 12 | } 13 | } 14 | 15 | dependencyResolutionManagement { 16 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) 17 | repositories { 18 | mavenCentral() 19 | google() 20 | maven("https://plugins.gradle.org/m2/") 21 | } 22 | } 23 | 24 | rootProject.name = "android-rust-example" 25 | include(":app") 26 | 27 | includeBuild("..") { 28 | dependencySubstitution { 29 | substitute(module("io.github.MatrixDev.android-rust:plugin")) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /example/app/src/main/res/values-night/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | -------------------------------------------------------------------------------- /src/main/kotlin/dev/matrix/agp/rust/utils/Os.kt: -------------------------------------------------------------------------------- 1 | package dev.matrix.agp.rust.utils 2 | 3 | import org.gradle.internal.os.OperatingSystem 4 | 5 | internal enum class Os { 6 | Linux, 7 | MacOs, 8 | Windows, 9 | Unknown; 10 | 11 | companion object { 12 | val current: Os 13 | 14 | init { 15 | val os = OperatingSystem.current() 16 | current = when { 17 | os.isLinux -> Linux 18 | os.isMacOsX -> MacOs 19 | os.isWindows -> Windows 20 | else -> Unknown 21 | } 22 | } 23 | } 24 | 25 | val isLinux: Boolean 26 | get() { 27 | return this == Linux 28 | } 29 | 30 | val isMacOs: Boolean 31 | get() { 32 | return this == MacOs 33 | } 34 | 35 | val isWindows: Boolean 36 | get() { 37 | return this == Windows 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /example/app/src/main/res/layout/content_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Rostyslav Lesovyi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /example/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 15 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /example/app/src/main/res/navigation/nav_graph.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | 17 | 18 | 23 | 24 | 27 | 28 | -------------------------------------------------------------------------------- /example/app/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | 17 | 21 | 22 |