Skip to content

Commit

Permalink
Add some instructions for testing changes with the simulator
Browse files Browse the repository at this point in the history
  • Loading branch information
dae committed Jun 10, 2022
1 parent 4c5d134 commit 0fd6f8f
Showing 1 changed file with 96 additions and 0 deletions.
96 changes: 96 additions & 0 deletions docs/easy-testing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Testing changes with AnkiDroid on an X86_64 sim (Linux)

## Setup

Make sure you can build AnkiDroid first.

Install NDK:

- Download https://developer.android.com/studio#command-tools
- Rename cmdline-tools to $ANDROID_SDK_ROOT/cmdline-tools/latest
- Get ndk version from rslib/build.grade
- .github/scripts/install_ndk.sh 22.0.7026061

Install Rust:

- rustup install 1.54.0
- rustup target add x86_64-linux-android
- sudo ln -sf /usr/bin/gcc /usr/bin/x86_64--unknown-linux-gnu-gcc

Install protobuf:

- Install protobuf with your package manager
- pip install protobuf, or see the venv section below

## Limit build to x86_64

So you don't need to install cross compilers, patch the sources to
only build the x86_64 image for the aar file:

```diff
diff --git a/rsdroid/build.gradle b/rsdroid/build.gradle
index bc3a401..7c69a5b 100644
--- a/rsdroid/build.gradle
+++ b/rsdroid/build.gradle
@@ -72,7 +72,7 @@ dependencies {

}

-preBuild.dependsOn "cargoBuild"
+preBuild.dependsOn "cargoBuildX86_64"

signing {
def hasPrivate = project.hasProperty('SIGNING_PRIVATE_KEY')
```

## Using a custom python venv

To use a Python venv instead of the system-wide one:

```diff
diff --git a/tools/protoc-gen/protoc-gen.sh b/tools/protoc-gen/protoc-gen.sh
index d4039ec..3ac5d29 100755
--- a/tools/protoc-gen/protoc-gen.sh
+++ b/tools/protoc-gen/protoc-gen.sh
@@ -1,2 +1,3 @@
#!/bin/bash
-./tools/protoc-gen/protoc-gen.py
+
+$HOME/Local/python/misc/bin/python3 ./tools/protoc-gen/protoc-gen.py
```

## Build

```
export ANDROID_SDK_ROOT=$HOME/Android/Sdk
export PATH=$HOME/Android/Sdk/cmdline-tools/latest/bin/:$PATH
./gradlew assembleRelease
```

## Modify AnkiDroid to use built library

Tell gradle to load the compiled .aar file from disk:

```diff
diff --git a/AnkiDroid/build.gradle b/AnkiDroid/build.gradle
index a5fa4d6d2..8007dedf4 100644
--- a/AnkiDroid/build.gradle
+++ b/AnkiDroid/build.gradle
@@ -263,10 +263,10 @@ dependencies {
implementation 'com.github.CanHub:Android-Image-Cropper:4.2.1'

// build with ./gradlew rsdroid:assembleRelease
- // In my experience, using `files()` currently requires a reindex operation.
- // implementation files("C:\\GitHub\\Rust-Test\\rsdroid\\build\\outputs\\aar\\rsdroid-release.aar")
+ // after changing one of the lines below, you must run a gradle sync
+ // implementation "io.github.david-allison-1:anki-android-backend:$ankidroid_backend_version"
+ implementation files("../../Anki-Android-Backend/rsdroid/build/outputs/aar/rsdroid-release.aar")
implementation 'com.google.protobuf:protobuf-java:3.21.1' // This is required when loading from a file
- implementation "io.github.david-allison-1:anki-android-backend:$ankidroid_backend_version"
// build with ./gradlew rsdroid-testing:assembleRelease
// RobolectricTest.java: replace RustBackendLoader.init(); with RustBackendLoader.loadRsdroid(path);
// A path for a testing library is typically under rsdroid-testing/assets
```

After making the change, force a gradle sync, and then you should be able to build
and run the project on an x86_64 emulator.

0 comments on commit 0fd6f8f

Please sign in to comment.