Skip to content

Commit 26486fc

Browse files
authored
feat: add kotlin bindings
Merge pull request #1239 from matrix-org/ganfra/kotlin_bindings
2 parents c488488 + 97578e4 commit 26486fc

32 files changed

+862
-1
lines changed

bindings/kotlin/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Matrix rust components kotlin
2+
3+
This project and build scripts demonstrate how to create an aar and how to import it in your android projects.
4+
5+
## Prerequisites
6+
7+
* the Rust toolchain
8+
* UniFFI - `cargo install uniffi_bindgen`
9+
* cargo-ndk < 2.12.0 `cargo install cargo-ndk --version 2.11.0`
10+
* android targets (e.g. `rustup target add \
11+
aarch64-linux-android \
12+
armv7-linux-androideabi \
13+
x86_64-linux-android \
14+
i686-linux-android`)
15+
16+
## Building the SDK
17+
18+
To build the full sdk and get an aar you can call :
19+
`./bindings/kotlin/scripts/build_sdk.sh /matrix-rust_sdk/bindings/kotlin/sample/libs`
20+
where the parameter is the path for the aar to go
21+
22+
## License
23+
24+
[Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0)

bindings/kotlin/SECURITY.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Reporting a Vulnerability
2+
3+
**If you've found a security vulnerability, please report it to [email protected]**
4+
5+
For more information on our security disclosure policy, visit https://www.matrix.org/security-disclosure-policy/

bindings/kotlin/build.gradle

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2+
3+
apply plugin: 'io.github.gradle-nexus.publish-plugin'
4+
apply from: "${rootDir}/scripts/publish-root.gradle"
5+
6+
buildscript {
7+
repositories {
8+
maven { url "https://plugins.gradle.org/m2/" }
9+
google()
10+
mavenCentral()
11+
}
12+
13+
dependencies {
14+
classpath BuildPlugins.android
15+
classpath BuildPlugins.kotlin
16+
classpath BuildPlugins.nexusPublish
17+
}
18+
}
19+
20+
21+
task clean(type: Delete) {
22+
delete rootProject.buildDir
23+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import org.gradle.kotlin.dsl.`kotlin-dsl`
2+
3+
plugins {
4+
`kotlin-dsl`
5+
}
6+
7+
repositories {
8+
mavenCentral()
9+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
object ConfigurationData {
2+
const val compileSdk = 31
3+
const val targetSdk = 31
4+
const val minSdk = 21
5+
const val majorVersion = 0
6+
const val minorVersion = 2
7+
const val patchVersion = 0
8+
const val versionName = "$majorVersion.$minorVersion.$patchVersion"
9+
const val snapshotVersionName = "$majorVersion.$minorVersion.${patchVersion + 1}-SNAPSHOT"
10+
const val publishGroupId = "org.matrix.rustcomponents"
11+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
internal object Versions {
2+
const val androidGradlePlugin = "7.1.2"
3+
const val kotlin = "1.6.10"
4+
const val jUnit = "4.12"
5+
const val nexusPublishGradlePlugin = "1.1.0"
6+
const val jna = "5.10.0"
7+
}
8+
9+
internal object BuildPlugins {
10+
const val android = "com.android.tools.build:gradle:${Versions.androidGradlePlugin}"
11+
const val kotlin = "org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlin}"
12+
const val nexusPublish = "io.github.gradle-nexus:publish-plugin:${Versions.nexusPublishGradlePlugin}"
13+
}
14+
15+
/**
16+
* To define dependencies
17+
*/
18+
internal object Dependencies {
19+
const val kotlin = "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${Versions.kotlin}"
20+
const val junit = "junit:junit:${Versions.jUnit}"
21+
const val jna = "net.java.dev.jna:jna:${Versions.jna}@aar"
22+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
plugins {
2+
id 'com.android.library'
3+
id 'org.jetbrains.kotlin.android'
4+
}
5+
6+
ext {
7+
PUBLISH_GROUP_ID = ConfigurationData.publishGroupId
8+
PUBLISH_ARTIFACT_ID = 'crypto-android'
9+
PUBLISH_VERSION = rootVersionName
10+
PUBLISH_DESCRIPTION = 'Android Bindings to the Matrix Rust Crypto SDK'
11+
}
12+
13+
apply from: "${rootDir}/scripts/publish-module.gradle"
14+
15+
android {
16+
17+
compileSdk ConfigurationData.compileSdk
18+
19+
defaultConfig {
20+
minSdk ConfigurationData.minSdk
21+
targetSdk ConfigurationData.targetSdk
22+
versionName ConfigurationData.versionName
23+
24+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
25+
consumerProguardFiles "consumer-rules.pro"
26+
}
27+
28+
buildTypes {
29+
release {
30+
minifyEnabled false
31+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
32+
}
33+
}
34+
compileOptions {
35+
sourceCompatibility JavaVersion.VERSION_1_8
36+
targetCompatibility JavaVersion.VERSION_1_8
37+
}
38+
kotlinOptions {
39+
jvmTarget = '1.8'
40+
}
41+
}
42+
43+
android.libraryVariants.all { variant ->
44+
def sourceSet = variant.sourceSets.find { it.name == variant.name }
45+
sourceSet.java.srcDir new File(buildDir, "generated/source/${variant.name}")
46+
}
47+
48+
dependencies {
49+
implementation Dependencies.jna
50+
testImplementation Dependencies.junit
51+
}

bindings/kotlin/crypto/crypto-android/consumer-rules.pro

Whitespace-only changes.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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

0 commit comments

Comments
 (0)