Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AppFlowy build tasks for Android platform #3184

Closed
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions frontend/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@
},
"cwd": "${workspaceRoot}/appflowy_flutter"
},
{
"name": "AF-iOS: Build Dart Only",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this task just for people who want to run AppFlowy, without rebuilding the backend

"request": "launch",
"program": "./lib/main.dart",
"type": "dart",
"env": {
"RUST_LOG": "trace"
},
"cwd": "${workspaceRoot}/appflowy_flutter"
},
{
"name": "AF-iOS: Clean + Rebuild All",
"request": "launch",
Expand All @@ -65,6 +75,27 @@
},
"cwd": "${workspaceRoot}/appflowy_flutter"
},
{
"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 (Android)",
"env": {
"RUST_LOG": "trace"
},
"cwd": "${workspaceRoot}/appflowy_flutter"
},
{
"name": "AF-desktop: Debug Rust",
"request": "attach",
Expand Down
44 changes: 40 additions & 4 deletions frontend/.vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,34 @@
"cwd": "${workspaceFolder}"
}
},
{
"label": "AF: Clean + Rebuild All (Android)",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's easier to see if you're running the right task, if the label include critical information at the beginning.

Suggested change
"label": "AF: Clean + Rebuild All (Android)",
"label": "AF-Android: Clean + Rebuild All",

"type": "shell",
"dependsOrder": "sequence",
"dependsOn": [
"AF: Dart Clean",
"AF: Flutter Clean",
"AF: Build Appflowy Core For Android",
"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 Android",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"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",
"options": {
"cwd": "${workspaceFolder}"
}
},
{
"label": "AF: Build Appflowy Core",
"type": "shell",
Expand Down Expand Up @@ -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"
Expand All @@ -232,7 +263,9 @@
"type": "shell",
"isBackground": true,
"command": "yarn",
"args": ["dev"],
"args": [
"dev"
],
"options": {
"cwd": "${workspaceFolder}/appflowy_tauri"
}
Expand Down Expand Up @@ -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}"
}
Expand All @@ -287,4 +323,4 @@
}
}
]
}
}
52 changes: 52 additions & 0 deletions frontend/Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
38 changes: 19 additions & 19 deletions frontend/appflowy_flutter/android/README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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]
Expand All @@ -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**
Expand All @@ -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
```
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
12 changes: 10 additions & 2 deletions frontend/appflowy_flutter/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -63,6 +63,14 @@ android {
signingConfig signingConfigs.debug
}
}

externalNativeBuild {
cmake {
path 'src/main/jniLibs/CMakeLists.txt'
}
}

//Eventually split ABI for google playstore
}

flutter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
android:name="${applicationName}">
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
cmake_minimum_required(VERSION 3.10)
project(appflowy_flutter)

if (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Linux")
file(COPY
$ENV{ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/arm64-v8a
)

file(COPY
$ENV{ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/arm-linux-androideabi/libc++_shared.so
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/armeabi-v7a
)

file(COPY
$ENV{ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/i686-linux-android/libc++_shared.so
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/x86
)

file(COPY
$ENV{ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/x86_64-linux-android/libc++_shared.so
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/x86_64
)

elseif (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Darwin")
file(COPY
${ANDROID_NDK}/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/arm64-v8a
)

file(COPY
${ANDROID_NDK}/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/lib/arm-linux-androideabi/libc++_shared.so
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/armeabi-v7a
)

file(COPY
${ANDROID_NDK}/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/lib/i686-linux-android/libc++_shared.so
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/x86
)

file(COPY
${ANDROID_NDK}/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/lib/x86_64-linux-android/libc++_shared.so
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/x86_64
)

elseif(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Windows")
file(COPY
${ANDROID_NDK}/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/arm64-v8a
)

file(COPY
${ANDROID_NDK}/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/lib/arm-linux-androideabi/libc++_shared.so
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/armeabi-v7a
)

file(COPY
${ANDROID_NDK}/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/lib/i686-linux-android/libc++_shared.so
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/x86
)

file(COPY
${ANDROID_NDK}/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/lib/x86_64-linux-android/libc++_shared.so
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/x86_64
)

else()
message("Unable to detect the platform to copy NDK Files")
endif()

# Remove cmake files after build
file(REMOVE ${CMAKE_CURRENT_SOURCE_DIR}/CMakeCache.txt)
file(REMOVE_RECURSE ${CMAKE_CURRENT_SOURCE_DIR}/CMakeFiles)
5 changes: 3 additions & 2 deletions frontend/appflowy_flutter/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
buildscript {
ext.kotlin_version = '1.6.10'
ext.gradle_tool = '7.1.2'
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "com.android.tools.build:gradle:$gradle_tool"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand All @@ -24,6 +25,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading
Loading