Skip to content

Commit

Permalink
Custom go compiler works
Browse files Browse the repository at this point in the history
  • Loading branch information
guillemcordoba committed May 20, 2024
1 parent 9b14114 commit 690d175
Show file tree
Hide file tree
Showing 33 changed files with 304 additions and 251 deletions.
24 changes: 20 additions & 4 deletions crates/scaffold-tauri-app/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,32 @@ pub fn scaffold_tauri_app(
let package_json_content = add_npm_script_to_package(
&(root_package_json_path.clone(), package_json_content),
&String::from("network"),
&format!("BOOTSTRAP_PORT=$(port) SIGNAL_PORT=$(port) INTERNAL_IP=$(internal-ip --ipv4) concurrently -k \"{}\" \"{}\" \"{}\"", package_manager.run_script_command(String::from("local-services"), None ),
package_manager.run_script_command(String::from("start"), Some(ui_package.clone())),
package_manager.run_script_command(String::from("launch"), None)
&format!("{} && BOOTSTRAP_PORT=$(port) SIGNAL_PORT=$(port) INTERNAL_IP=$(internal-ip --ipv4) concurrently -k \"{}\" \"UI_PORT=1420 {}\" \"{}\"",

package_manager.run_script_command(String::from("build:happ"), None),
package_manager.run_script_command(String::from("local-services"), None ),
package_manager.run_script_command(String::from("start"), Some(ui_package.clone())),
package_manager.run_script_command(String::from("launch"), None)
),
)?;
let package_json_content = add_npm_script_to_package(
&(root_package_json_path.clone(), package_json_content),
&String::from("local-services"),
&format!("hc run-local-services --bootstrap-port $BOOTSTRAP_PORT --signal-port $SIGNAL_PORT"),
&format!("hc run-local-services --bootstrap-interface $INTERNAL_IP --bootstrap-port $BOOTSTRAP_PORT --signal-interfaces $INTERNAL_IP --signal-port $SIGNAL_PORT"),
)?;

let package_json_content = add_npm_script_to_package(
&(root_package_json_path.clone(), package_json_content),
&String::from("android:network"),
&format!("{} && BOOTSTRAP_PORT=$(port) SIGNAL_PORT=$(port) INTERNAL_IP=$(internal-ip --ipv4) concurrently -k \"{}\" \"UI_PORT=1420 {}\" \"{}\" \"{}\"",
package_manager.run_script_command(String::from("build:happ"), None),
package_manager.run_script_command(String::from("local-services"), None),
package_manager.run_script_command(String::from("start"), Some(ui_package.clone())),
package_manager.run_script_command(String::from("tauri dev"), None),
package_manager.run_script_command(String::from("tauri android dev"), None),
),
)?;

let package_json_content = add_npm_script_to_package(
&(root_package_json_path.clone(), package_json_content),
&String::from("build:zomes"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{previous_file_content}}

[patch.crates-io]
# TODO: remove these patches once https://github.com/holochain/tx5/issues/87 is resolved
tx5-go-pion-sys = { git = "https://github.com/guillemcordoba/tx5", branch = "custom-go" }
tx5-go-pion-turn = { git = "https://github.com/guillemcordoba/tx5", branch = "custom-go" }

Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,8 @@ url2 = "0.0.6"
app_dirs2 = "2.5.5"
tempdir = "0.3.7"
anyhow = "1"

[patch.crates-io]
# TODO: remove these patches once https://github.com/holochain/tx5/issues/87 is resolved
tx5-go-pion-sys = { git = "https://github.com/guillemcordoba/tx5", branch = "custom-go" }
tx5-go-pion-turn = { git = "https://github.com/guillemcordoba/tx5", branch = "custom-go" }
17 changes: 15 additions & 2 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,21 @@ export default defineConfig({
link: "/documentation/getting-to-know-tauri",
},
{
text: "Setting up Android",
link: "/documentation/android-setup",
text: "Android",
items: [
{
text: "Setup",
link: "/documentation/android/setup",
},
{
text: "Developing",
link: "/documentation/android/developing",
},
{
text: "Publishing",
link: "/documentation/android/publishing",
},
],
},
],
},
Expand Down
23 changes: 23 additions & 0 deletions docs/documentation/android/developing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## Developing for Android

While developing a hApp, it's not that useful to just have one agent to test your hApp with. Instead, you usually need a couple of peers to be able to interact with one another.

The scaffolding setup

::: code-group
```bash [npm]
npm run android:network
```

```bash [yarn]
yarn android:network
```

```bash [pnpm]
pnpm android:network
```
:::

```bash
adb devices
```
171 changes: 171 additions & 0 deletions docs/documentation/android/publishing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
# Android Setup

> [!NOTE]
> This guide assumes that you have already gone through either [how to create an executable hApp](./how-to-create-an-executable-happ.md) or [how to create a holochain runtime](./how-to-create-a-holochain-runtime.md).
1. In the root folder of your repository, run:

::: code-group
```bash [npm]
npm run tauri android init
```

```bash [yarn]
yarn tauri android init
```

```bash [pnpm]
pnpm tauri android init
```
:::

This should initialize all the necessary android files for your app.

2. Go in the `src-tauri/gen/android/app/build.gradle.kts` that was generated in the previous step, and set the "usesCleartextTraffic" to true:

```kotlin
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("rust")
}

android {
compileSdk = 33
namespace = "com.tauri.tauri_app"
defaultConfig {
manifestPlaceholders["usesCleartextTraffic"] = "false" // [!code --]
manifestPlaceholders["usesCleartextTraffic"] = "true" // [!code ++]
applicationId = "com.tauri.tauri_app"
minSdk = 24
targetSdk = 33
versionCode = 1
versionName = "1.0"
}

buildTypes {
getByName("debug") {
manifestPlaceholders["usesCleartextTraffic"] = "true"
isDebuggable = true
isJniDebuggable = true
isMinifyEnabled = false
packaging {
jniLibs.keepDebugSymbols.add("*/arm64-v8a/*.so")
jniLibs.keepDebugSymbols.add("*/armeabi-v7a/*.so")
jniLibs.keepDebugSymbols.add("*/x86/*.so")
jniLibs.keepDebugSymbols.add("*/x86_64/*.so")
}
}
getByName("release") {
signingConfig = signingConfigs.getByName("release")
isMinifyEnabled = true
proguardFiles(
*fileTree(".") { include("**/*.pro") }
.plus(getDefaultProguardFile("proguard-android-optimize.txt"))
.toList().toTypedArray()
)
}
}
kotlinOptions {
jvmTarget = "1.8"
}
}

rust {
rootDirRel = "../../../"
}

dependencies {
implementation("androidx.webkit:webkit:1.6.1")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.8.0")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.4")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.0")
}

apply(from = "tauri.build.gradle.kts")
```

3. In your Android device, enable the [developer options](https://developer.android.com/studio/debug/dev-options).

4. After you have enabled the developer options, [enable USB debbuging](https://developer.android.com/studio/debug/dev-options#Enable-debugging).

5. Connect your Android device to your computer with a USB cable, and confirm in your Android device that you allow USB debugging from this computer.

6. In the root folder of your repository, run:

```bash
nix develop .#androidDev
```

This is a replacement command for the usual `nix develop`, which includes `Android Studio`, and all the necessary tooling that you need for Android development. Every time you want to test or build for the Android platform, you will need to enter the nix devShell this way and then your command from inside of it.

> [!WARNING]
> The first time this is run, it will take some time. This is because nix has to download and build all the necessary Android tooling. After the first time, it will be almost instant.
7. Inside your `androidDev` devShell, run:

```bash
adb devices
```

If all the previous steps were successful, you should see your device in the list of devices.

8. Verify that everything is working by running the app for android with:

::: code-group
```bash [npm]
npm run tauri android dev
```

```bash [yarn]
yarn tauri android dev
```

```bash [pnpm]
pnpm tauri android dev
```
:::

---

That's it! You have completed the setup for the Android platform.

## Android Development

### Developing

::: code-group
```bash [npm]
npm run tauri android dev
```

```bash [yarn]
yarn tauri android dev
```

```bash [pnpm]
pnpm tauri android dev
```
:::

```bash
adb devices
```

### Publishing

::: code-group
```bash [npm]
npm run tauri android build
```

```bash [yarn]
yarn tauri android build
```

```bash [pnpm]
pnpm tauri android build
```
:::
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,5 @@ pnpm tauri android dev
---

That's it! You have completed the setup for the Android platform.

Continue to [Android developing](./developing) to learn how to develop your app while targeting the Android platform.
9 changes: 4 additions & 5 deletions docs/documentation/faqs.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@ Well, not quite. Let's break it down to the two main mobile platforms:

Holochain has experimental support for Android. This means that holochain works as expected on Android, **except for these issues**:

- [Go compiler issue on Android 11 or later](https://github.com/holochain/tx5/issues/87). This means that in these Android versions, the device can't communicate with anyone on the network, so in practicality holochain does not work.
- [Installation of apps takes more than 40 seconds to complete on an average Android device](https://github.com/holochain/holochain/issues/3243).
- [Every time the Android app is opened, holochain takes ~10 seconds to boot up, so there is a long loading screen](https://github.com/holochain/holochain/issues/3243).
- [Go compiler issue on Android 11 or later](https://github.com/holochain/tx5/issues/87). `tauri-plugin-holochain` solves this issue by providing a custom go toolchain, which is already included in the `devShells` and scaffolded projects described in throughout this documentation site, so **if you use `tauri-plugin-holochain`, this issue is not present at all**.

### iOS

In development, holochain works as expected in iOS. But Apple prevents JIT compilation in iOS devices, so when a holochain app is published in the iOS store, it does not work. Thankfully there is already [work in progress done by wasmer](https://github.com/wasmerio/wasmer/issues/4486) to address this issue. Stay tuned for updates!

---

## Well, okey... Then how does tauri-plugin-holochain help me now?
## Well, okey... Then how does `tauri-plugin-holochain` help me now?

For now, you can build a desktop only executable hApp that your users can download and use. It's ready to be deployed and iterated upon. After the issues with holochain mobile outlined above are resolved, you will be able to upgrade to a new version of the plugin to automatically get mobile support in your hApp.
For now, you can build a desktop executable hApp that your users can download and use, and start experimenting with Android support. After the issues with holochain mobile outlined above are resolved, you will be able to upgrade to a new version of the plugin to automatically get full mobile support in your hApp.

This is the way ourselves in darskoil studio are building hApps right now. We are monitoring the issues at the technical level, and in constant communication with the core holochain development team. At the same time, while they get resolved, we are building the MVP version for our hApps.
This is the way ourselves in darskoil.studio are building hApps right now. We are monitoring the issues at the core holochain infrastructure level, and in constant communication with the core holochain development team to help get them fixed.
2 changes: 1 addition & 1 deletion docs/documentation/getting-to-know-tauri.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ After the initial set up and scaffolding, our tauri app can only be built for de

### Android Setup

Continue to the [Android setup](./android-setup).
Continue to the [Android setup](./android/setup).

### iOS Setup

Expand Down
6 changes: 3 additions & 3 deletions docs/documentation/troubleshooting.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
### NixOS
## NixOS

#### Connect to devices
### Connect to devices

```bash
sudo adb devices
```

#### Firewall
### Firewall

Disable the firewall to get the tauri frontend with:

Expand Down
Loading

0 comments on commit 690d175

Please sign in to comment.