From 1aa3cbf57675767e92c50ea142251589905d8a36 Mon Sep 17 00:00:00 2001 From: Sean Riley Hawkins Date: Sun, 13 Aug 2023 16:11:22 +0200 Subject: [PATCH 1/4] feat: ensure AppFlowy builds for Android platform --- frontend/.vscode/launch.json | 24 +++++- frontend/.vscode/tasks.json | 26 +++---- frontend/Makefile.toml | 52 +++++++++++++ frontend/appflowy_flutter/android/README.md | 38 +++++----- .../appflowy_flutter/android/app/build.gradle | 12 ++- .../android/app/src/main/AndroidManifest.xml | 1 + .../app/src/main/jniLibs/CMakeLists.txt | 73 +++++++++++++++++++ .../appflowy_flutter/android/build.gradle | 5 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- .../appflowy_backend/android/build.gradle | 5 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- .../example/android/app/build.gradle | 2 +- .../android/app/src/main/AndroidManifest.xml | 1 + .../example/android/build.gradle | 3 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- .../flowy_infra_ui/android/build.gradle | 3 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- frontend/scripts/makefile/desktop.toml | 27 ------- frontend/scripts/makefile/env.toml | 23 ++++-- frontend/scripts/makefile/mobile.toml | 53 ++++++++++++++ 22 files changed, 276 insertions(+), 84 deletions(-) create mode 100644 frontend/appflowy_flutter/android/app/src/main/jniLibs/CMakeLists.txt diff --git a/frontend/.vscode/launch.json b/frontend/.vscode/launch.json index c26200df878a..246a1f25490d 100644 --- a/frontend/.vscode/launch.json +++ b/frontend/.vscode/launch.json @@ -43,6 +43,16 @@ }, "cwd": "${workspaceRoot}/appflowy_flutter" }, + { + "name": "AF-iOS: Build Dart Only", + "request": "launch", + "program": "./lib/main.dart", + "type": "dart", + "env": { + "RUST_LOG": "trace" + }, + "cwd": "${workspaceRoot}/appflowy_flutter" + }, { "name": "AF-iOS: Clean + Rebuild All", "request": "launch", @@ -55,11 +65,21 @@ "cwd": "${workspaceRoot}/appflowy_flutter" }, { - "name": "AF-iOS-Simulator: Clean + Rebuild All", + "name": "AF-Android: Build Dart Only", + "request": "launch", + "program": "./lib/main.dart", + "type": "dart", + "env": { + "RUST_LOG": "trace" + }, + "cwd": "${workspaceRoot}/appflowy_flutter" + }, + { + "name": "AF-Android: Clean + Rebuild All", "request": "launch", "program": "./lib/main.dart", "type": "dart", - "preLaunchTask": "AF: Clean + Rebuild All (iOS Simulator)", + "preLaunchTask": "AF: Clean + Rebuild All (Android)", "env": { "RUST_LOG": "trace" }, diff --git a/frontend/.vscode/tasks.json b/frontend/.vscode/tasks.json index 30b48151ab7a..95f76daa4d8e 100644 --- a/frontend/.vscode/tasks.json +++ b/frontend/.vscode/tasks.json @@ -46,13 +46,22 @@ } }, { - "label": "AF: Clean + Rebuild All (iOS Simulator)", + "label": "AF: Build Appflowy Core For iOS", + "type": "shell", + "command": "cargo make --profile development-ios-arm64 appflowy-core-dev-ios", + "group": "build", + "options": { + "cwd": "${workspaceFolder}" + } + }, + { + "label": "AF: Clean + Rebuild All (Android)", "type": "shell", "dependsOrder": "sequence", "dependsOn": [ "AF: Dart Clean", "AF: Flutter Clean", - "AF: Build Appflowy Core For iOS Simulator", + "AF: Build Appflowy Core For Android", "AF: Flutter Pub Get", "AF: Flutter Package Get", "AF: Generate Language Files", @@ -64,18 +73,9 @@ } }, { - "label": "AF: Build Appflowy Core For iOS", - "type": "shell", - "command": "cargo make --profile development-ios-arm64 appflowy-core-dev-ios", - "group": "build", - "options": { - "cwd": "${workspaceFolder}" - } - }, - { - "label": "AF: Build Appflowy Core For iOS Simulator", + "label": "AF: Build Appflowy Core For Android", "type": "shell", - "command": "cargo make --profile development-ios-arm64-sim appflowy-core-dev-ios", + "command": "cargo make --profile production-android appflowy-core-dev-android", "group": "build", "options": { "cwd": "${workspaceFolder}" diff --git a/frontend/Makefile.toml b/frontend/Makefile.toml index 1602aeda2f60..44f01528b236 100644 --- a/frontend/Makefile.toml +++ b/frontend/Makefile.toml @@ -220,6 +220,58 @@ script = [ ] script_runner = "@duckscript" +[tasks.setup-sqlite-crate] +private = true +script = [ + ''' + toml = readfile ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/flowy-sqlite/Cargo.toml + val = replace ${toml} "optional = true" "optional = false" + result = writefile ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/flowy-sqlite/Cargo.toml ${val} + assert ${result} + ''', +] +script_runner = "@duckscript" + +[tasks.setup-sqlite-openssl] +private = true +script = [ + ''' + org = set "\"openssl\", \"openssl-sys\"" + mod = set "\"openssl/vendored\", \"openssl-sys/vendored\"" + toml = readfile ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/flowy-sqlite/Cargo.toml + val = replace ${toml} ${org} ${mod} + result = writefile ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/flowy-sqlite/Cargo.toml ${val} + assert ${result} + ''', +] +script_runner = "@duckscript" + +[tasks.restore-sqlite-crate] +private = true +script = [ + ''' + toml = readfile ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/flowy-sqlite/Cargo.toml + val = replace ${toml} "optional = false" "optional = true" + result = writefile ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/flowy-sqlite/Cargo.toml ${val} + assert ${result} + ''', +] +script_runner = "@duckscript" + +[tasks.restore-sqlite-openssl] +private = true +script = [ + ''' + org = set "\"openssl\", \"openssl-sys\"" + mod = set "\"openssl/vendored\", \"openssl-sys/vendored\"" + toml = readfile ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/flowy-sqlite/Cargo.toml + val = replace ${toml} ${mod} ${org} + result = writefile ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/flowy-sqlite/Cargo.toml ${val} + assert ${result} + ''', +] +script_runner = "@duckscript" + [tasks.restore-crate-type] private = true script = [ diff --git a/frontend/appflowy_flutter/android/README.md b/frontend/appflowy_flutter/android/README.md index 52f0dd3e6fd0..e8f2568511f5 100644 --- a/frontend/appflowy_flutter/android/README.md +++ b/frontend/appflowy_flutter/android/README.md @@ -1,15 +1,17 @@ # Description -This is a guide on how to build the rust SDK for AppFlowy on android. +This is a rough guide on how to build the rust SDK for AppFlowy on android. Compiling the sdk is easy it just needs a few tweaks. When compiling for android we need the following pre-requisites: -- Android NDK Tools. (v24 has been tested). +- Android NDK Tools. (v24 has been tested for this) even the latest version works. - Cargo NDK. (@latest version). +**Warning** currently the rust backend for android does not compile on windows. + **Getting the tools** - Install cargo-ndk ```bash cargo install cargo-ndk```. -- [Download](https://developer.android.com/ndk/downloads/) Android NDK version 24. +- [Android NDK](https://developer.android.com/ndk/downloads/) . - When downloading Android NDK you can get the compressed version as a standalone from the site. Or you can download it through [Android Studio](https://developer.android.com/studio). - After downloading the two you need to set the environment variables. For Windows that's a separate process. @@ -19,7 +21,7 @@ When compiling for android we need the following pre-requisites: **Cargo Config File** This code needs to be written in ~/.cargo/config, this helps cargo know where to locate the android tools(linker and archiver). -**NB** Keep in mind just replace 'user' with your own user name. Or just point it to the location of where you put the NDK. +**NB** Keep in mind just replace `user` with your own `username`. Or just point it to the location of where you put the NDK. ```toml [target.aarch64-linux-android] @@ -39,19 +41,6 @@ ar = "/home/user/Android/Sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86 linker = "/home/user/Android/Sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android29-clang" ``` -**Clang Fix** - In order to get clang to work properly with version 24 you need to create this file. - libgcc.a, then add this one line. - ``` - INPUT(-lunwind) - ``` - -**Folder path: 'Android/Sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/14.0.1/lib/linux'.** -After that you have to copy this file into three different folders namely aarch64, arm, i386 and x86_64. -We have to do this so we Android NDK can find clang on our system, if we used NDK 22 we wouldn't have to do this process. -Though using NDK v22 will not give us a lot of features to work with. -This GitHub [issue](https://github.com/fzyzcjy/flutter_rust_bridge/issues/419) explains the reason why we are doing this. - --- **Android NDK** @@ -60,5 +49,16 @@ This GitHub [issue](https://github.com/fzyzcjy/flutter_rust_bridge/issues/419) e (.vimrc, .zshrc, .profile, .bashrc file), That way it can be found. ```vim - export PATH=/home/sean/Android/Sdk/ndk/24.0.8215888 - ``` \ No newline at end of file + export PATH=/home/user/Android/Sdk/ndk/24.0.8215888 + ``` + +You also need to copy a specific file `libc++_shared.so` into the android `jniLib` folder +During the building of the backend process it somehow got skipped. The best fix for now +is to manually copy it into the folder. +The block below shows an example of where it is on a linux machine +`$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/x86_64-android/libc++_shared.so` + +Then from there you can just run this in the frontend folder to build the rust backend +`cargo make --profile production-android appflowy-core-dev-android` + +Or you can head into vscode and run the android task \ No newline at end of file diff --git a/frontend/appflowy_flutter/android/app/build.gradle b/frontend/appflowy_flutter/android/app/build.gradle index 948e9b7f4275..bfc21a816462 100644 --- a/frontend/appflowy_flutter/android/app/build.gradle +++ b/frontend/appflowy_flutter/android/app/build.gradle @@ -26,8 +26,8 @@ apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - compileSdkVersion 31 - ndkVersion "24.0.8215888" + compileSdkVersion 33 + ndkVersion "25.2.9519653" compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 @@ -63,6 +63,14 @@ android { signingConfig signingConfigs.debug } } + + externalNativeBuild { + cmake { + path 'src/main/jniLibs/CMakeLists.txt' + } + } + + //Eventually split ABI for google playstore } flutter { diff --git a/frontend/appflowy_flutter/android/app/src/main/AndroidManifest.xml b/frontend/appflowy_flutter/android/app/src/main/AndroidManifest.xml index 264e1d3232ff..ab9c6a57e5b3 100644 --- a/frontend/appflowy_flutter/android/app/src/main/AndroidManifest.xml +++ b/frontend/appflowy_flutter/android/app/src/main/AndroidManifest.xml @@ -6,6 +6,7 @@ android:name="${applicationName}"> Date: Sun, 20 Aug 2023 16:50:34 +0200 Subject: [PATCH 2/4] chore: restore iOS sim tasks & launch --- frontend/.vscode/launch.json | 11 +++++++++ frontend/.vscode/tasks.json | 44 ++++++++++++++++++++++++++++++++---- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/frontend/.vscode/launch.json b/frontend/.vscode/launch.json index 8b446a8459d8..a8007eeac060 100644 --- a/frontend/.vscode/launch.json +++ b/frontend/.vscode/launch.json @@ -64,6 +64,17 @@ }, "cwd": "${workspaceRoot}/appflowy_flutter" }, + { + "name": "AF-iOS-Simulator: Clean + Rebuild All", + "request": "launch", + "program": "./lib/main.dart", + "type": "dart", + "preLaunchTask": "AF: Clean + Rebuild All (iOS Simulator)", + "env": { + "RUST_LOG": "trace" + }, + "cwd": "${workspaceRoot}/appflowy_flutter" + }, { "name": "AF-Android: Build Dart Only", "request": "launch", diff --git a/frontend/.vscode/tasks.json b/frontend/.vscode/tasks.json index 6a57d0785913..3a96b5b97be3 100644 --- a/frontend/.vscode/tasks.json +++ b/frontend/.vscode/tasks.json @@ -47,6 +47,25 @@ "panel": "new" } }, + { + "label": "AF: Clean + Rebuild All (iOS Simulator)", + "type": "shell", + "dependsOrder": "sequence", + "dependsOn": [ + "AF: Dart Clean", + "AF: Flutter Clean", + "AF: Build Appflowy Core For iOS Simulator", + "AF: Flutter Pub Get", + "AF: Flutter Package Get", + "AF: Generate Language Files", + "AF: Generate Freezed Files", + "AF: Generate Svg Files" + ], + "presentation": { + "reveal": "always", + "panel": "new" + } + }, { "label": "AF: Build Appflowy Core For iOS", "type": "shell", @@ -56,6 +75,15 @@ "cwd": "${workspaceFolder}" } }, + { + "label": "AF: Build Appflowy Core For iOS Simulator", + "type": "shell", + "command": "cargo make --profile development-ios-arm64-sim appflowy-core-dev-ios", + "group": "build", + "options": { + "cwd": "${workspaceFolder}" + } + }, { "label": "AF: Clean + Rebuild All (Android)", "type": "shell", @@ -222,7 +250,10 @@ "label": "AF: flutter build aar", "type": "flutter", "command": "flutter", - "args": ["build", "aar"], + "args": [ + "build", + "aar" + ], "group": "build", "problemMatcher": [], "detail": "appflowy_flutter" @@ -232,7 +263,9 @@ "type": "shell", "isBackground": true, "command": "yarn", - "args": ["dev"], + "args": [ + "dev" + ], "options": { "cwd": "${workspaceFolder}/appflowy_tauri" } @@ -265,7 +298,10 @@ "label": "AF: Tauri Clean + Dev", "type": "shell", "dependsOrder": "sequence", - "dependsOn": ["AF: Tauri Clean", "AF: Tauri UI Dev"], + "dependsOn": [ + "AF: Tauri Clean", + "AF: Tauri UI Dev" + ], "options": { "cwd": "${workspaceFolder}" } @@ -287,4 +323,4 @@ } } ] -} +} \ No newline at end of file From 0b906e4670136ce981ac5d932ba8ab2d24ad2b8a Mon Sep 17 00:00:00 2001 From: Sean Riley Hawkins Date: Tue, 10 Oct 2023 17:08:32 +0200 Subject: [PATCH 3/4] fix: rename android vscode label --- frontend/.vscode/tasks.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend/.vscode/tasks.json b/frontend/.vscode/tasks.json index a9051d62a5b8..742c32e4c060 100644 --- a/frontend/.vscode/tasks.json +++ b/frontend/.vscode/tasks.json @@ -85,7 +85,7 @@ } }, { - "label": "AF: Clean + Rebuild All (Android)", + "label": "AF-Android: Clean + Rebuild All", "type": "shell", "dependsOrder": "sequence", "dependsOn": [ @@ -104,7 +104,7 @@ } }, { - "label": "AF: Build Appflowy Core For Android", + "label": "AF-Android: Build Appflowy Core", "type": "shell", "command": "cargo make --profile production-android appflowy-core-dev-android", "group": "build", @@ -331,4 +331,4 @@ } } ] -} \ No newline at end of file +} From 6eae6655f85c5d627953528ec587111cb727e766 Mon Sep 17 00:00:00 2001 From: Sean Riley Hawkins Date: Tue, 10 Oct 2023 17:12:51 +0200 Subject: [PATCH 4/4] chore: ignore android generated build files --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 489c26223f73..c69e17d1bea5 100644 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,5 @@ frontend/package frontend/*.deb **/Cargo.toml.bak + +frontend/appflowy_flutter/android/app/.cxx/