-
Notifications
You must be signed in to change notification settings - Fork 675
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7628 from vector-im/feature/bca/rust_flavor
Merging Element R in Element Android as a new flavor
- Loading branch information
Showing
441 changed files
with
24,708 additions
and
12,591 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
**/snapshots/**/*.png filter=lfs diff=lfs merge=lfs -text | ||
**/src/androidTest/assets/*.realm filter=lfs diff=lfs merge=lfs -text | ||
**/matrix-rust-sdk-crypto.aar filter=lfs diff=lfs merge=lfs -text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: ER APK Build | ||
|
||
on: | ||
pull_request: { } | ||
push: | ||
branches: [ develop ] | ||
|
||
# Enrich gradle.properties for CI/CD | ||
env: | ||
GRADLE_OPTS: -Dorg.gradle.jvmargs="-Xmx3072m -Dfile.encoding=UTF-8 -XX:+HeapDumpOnOutOfMemoryError" -Dkotlin.daemon.jvm.options="-Xmx2560m" -Dkotlin.incremental=false | ||
CI_GRADLE_ARG_PROPERTIES: --stacktrace -PpreDexEnable=false --max-workers 2 --no-daemon | ||
|
||
jobs: | ||
debug: | ||
name: Build debug APKs ER | ||
runs-on: ubuntu-latest | ||
if: github.ref != 'refs/heads/main' | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
target: [ Gplay, Fdroid ] | ||
# Allow all jobs on develop. Just one per PR. | ||
concurrency: | ||
group: ${{ github.ref == 'refs/heads/develop' && format('elementr-{0}-{1}', matrix.target, github.sha) || format('build-er-debug-{0}-{1}', matrix.target, github.ref) }} | ||
cancel-in-progress: true | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/.gradle/caches | ||
~/.gradle/wrapper | ||
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | ||
restore-keys: | | ||
${{ runner.os }}-gradle- | ||
- name: Assemble ${{ matrix.target }} debug apk | ||
run: ./gradlew assemble${{ matrix.target }}RustCryptoDebug $CI_GRADLE_ARG_PROPERTIES |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
name: Build and release Element R nightly APK | ||
|
||
on: | ||
schedule: | ||
# Every nights at 4 | ||
- cron: "0 4 * * *" | ||
|
||
env: | ||
GRADLE_OPTS: -Dorg.gradle.jvmargs="-Xmx3072m -Dfile.encoding=UTF-8 -XX:+HeapDumpOnOutOfMemoryError" -Dkotlin.daemon.jvm.options="-Xmx2560m" -Dkotlin.incremental=false | ||
CI_GRADLE_ARG_PROPERTIES: --stacktrace -PpreDexEnable=false --max-workers 2 --no-daemon | ||
|
||
jobs: | ||
nightly: | ||
name: Build and publish ER nightly Gplay APK to Firebase | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python 3.8 | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: 3.8 | ||
- uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/.gradle/caches | ||
~/.gradle/wrapper | ||
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | ||
restore-keys: | | ||
${{ runner.os }}-gradle- | ||
- name: Install towncrier | ||
run: | | ||
python3 -m pip install towncrier | ||
- name: Prepare changelog file | ||
run: | | ||
mv towncrier.toml towncrier.toml.bak | ||
sed 's/CHANGES\.md/CHANGES_NIGHTLY\.md/' towncrier.toml.bak > towncrier.toml | ||
rm towncrier.toml.bak | ||
yes n | towncrier build --version nightly | ||
- name: Build and upload Gplay Nightly ER APK | ||
run: | | ||
./gradlew assembleGplayRustCryptoNightly appDistributionUploadGplayRustCryptoNightly $CI_GRADLE_ARG_PROPERTIES | ||
env: | ||
ELEMENT_ANDROID_NIGHTLY_KEYID: ${{ secrets.ELEMENT_ANDROID_NIGHTLY_KEYID }} | ||
ELEMENT_ANDROID_NIGHTLY_KEYPASSWORD: ${{ secrets.ELEMENT_ANDROID_NIGHTLY_KEYPASSWORD }} | ||
ELEMENT_ANDROID_NIGHTLY_STOREPASSWORD: ${{ secrets.ELEMENT_ANDROID_NIGHTLY_STOREPASSWORD }} | ||
FIREBASE_TOKEN: ${{ secrets.ELEMENT_R_NIGHTLY_FIREBASE_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
## Overview | ||
|
||
Until the final migration to [rust crypto sdk](https://github.com/matrix-org/matrix-rust-components-kotlin), the Element Android project will support two | ||
different SDK as a product flavor. | ||
|
||
The `matrix-sdk-android` module is defining a new flavor dimension `crypto`, with two flavors `kotlinCrypto` and `rustCrypto`. | ||
The crypto module cannot be changed at runtime, it's a build time configuration. The app supports migration from kotlinCrypto to rustCrypto but not the other | ||
way around. | ||
|
||
The code that is not shared between the flavors is located in dedicated source sets (`src/kotlinCrypto/`, `src/rustCrypto/`). Some tests are also extracted | ||
in different source sets because they were accessing internal API and won't work with the rust crypto sdk. | ||
|
||
## Noticeable changes | ||
|
||
As a general rule, if you stick to the `kotlinCrypto` the app should behave as it was before the integration of favours. | ||
There is a noticeable exception though: | ||
In order to integrate the rust crypto several APIs had to be migrated from callback code to suspendable code. This change | ||
impacted a lot the key verification engine (user and device verification), so this part has been refactored for `kotlinCrypto`. The UI is also impacted, | ||
the verification flows now match the web experience. | ||
|
||
TLDR; Verification UI and engine has been refactored. | ||
|
||
## Testing with a local rust aar | ||
|
||
In order to run a custom rust SDK branch you can follow the direction in the [bindings repository](https://github.com/matrix-org/matrix-rust-components-kotlin) | ||
in order to build the `matrix-rust-sdk-crypto.aar`. | ||
|
||
Copy this lib in `library/rustCrypto/`, and rename it `matrix-rust-sdk-crypto.aar`. | ||
|
||
Then go to `matrix-sdk-android/build.gradle` and toggle the comments between the following lines. | ||
|
||
```` | ||
rustCryptoImplementation("org.matrix.rustcomponents:crypto-android:0.3.1") | ||
// rustCryptoApi project(":library:rustCrypto") | ||
```` | ||
|
||
## Changes in CI | ||
|
||
The workflow files have been updated to use the `kotlinCrypto` flavor, e.g | ||
|
||
`assembleGplayNightly` => `assembleGplayKotlinCryptoNightly` | ||
|
||
So building the unsigned release kotlin crypto apk is now: | ||
|
||
`> ./gradlew assembleGplayKotlinCryptoRelease` | ||
|
||
An additional workflow has been added to build the `rustCrypto` flavor (elementr.yml, ` Build debug APKs ER`). | ||
|
||
|
||
## Database migration from kotlin to rust | ||
|
||
With the kotlin flavor, the crypto information are persisted in the crypto realm database. | ||
With the rust flavor, the crypto information are in a sqllite database. | ||
|
||
The migration is handled when injecting `@SessionRustFilesDirectory` in the olmMachine. | ||
When launching the first time after migration, the app will detect that there is no rust data repository and it will | ||
create one. If there is an existing realm database, the data will then migrated to rust. See `ExtractMigrationDataUseCase`. | ||
This will extract your device keys, account secrets, active olm and megolm sessions. | ||
|
||
There is no inverse migration for now, as there is not yet rust pickle to olm pickle support in the sdk. | ||
|
||
If you migrate your app to rust, and want to revert to kotlin you have to logout then login again. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
android { | ||
|
||
flavorDimensions "crypto" | ||
|
||
productFlavors { | ||
kotlinCrypto { | ||
dimension "crypto" | ||
isDefault = true | ||
// versionName "${versionMajor}.${versionMinor}.${versionPatch}${getFdroidVersionSuffix()}" | ||
// buildConfigField "String", "SHORT_FLAVOR_DESCRIPTION", "\"JC\"" | ||
// buildConfigField "String", "FLAVOR_DESCRIPTION", "\"KotlinCrypto\"" | ||
} | ||
rustCrypto { | ||
dimension "crypto" | ||
// // versionName "${versionMajor}.${versionMinor}.${versionPatch}${getFdroidVersionSuffix()}" | ||
// buildConfigField "String", "SHORT_FLAVOR_DESCRIPTION", "\"RC\"" | ||
// buildConfigField "String", "FLAVOR_DESCRIPTION", "\"RustCrypto\"" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
configurations.maybeCreate("default") | ||
artifacts.add("default", file('matrix-rust-sdk-crypto.aar')) |
Git LFS file not shown
Oops, something went wrong.