Skip to content

Commit 69e3aed

Browse files
rileyhawk1417appflowyLucasXu0
authored
Android vscode workflow (#912)
* fix: fix linux build * Merge pull request #599 from AppFlowy-IO/refactor/grid_decode_cell_data Refactor/grid decode cell data * feat: ⭐ configured android vscode workflow * chore: clean up android vscode * fix: fixed typo * chore: remove unused code Co-authored-by: Nathan.fooo <[email protected]> Co-authored-by: Lucas.Xu <[email protected]>
1 parent 70f9a28 commit 69e3aed

File tree

27 files changed

+287
-36
lines changed

27 files changed

+287
-36
lines changed

frontend/.vscode/launch.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@
1616
},
1717
"cwd": "${workspaceRoot}/app_flowy"
1818
},
19+
{
20+
// This task builds the Rust and Dart code of AppFlowy for android.
21+
"name": "AF: Run Android",
22+
"request": "launch",
23+
"program": "./lib/main.dart",
24+
"type": "dart",
25+
"preLaunchTask": "AF: build_mobile_sdk",
26+
"env": {
27+
"RUST_LOG": "info"
28+
},
29+
"cwd": "${workspaceRoot}/app_flowy"
30+
},
1931
{
2032
"name": "AF: Debug Rust",
2133
"request": "attach",
@@ -48,6 +60,21 @@
4860
},
4961
"cwd": "${workspaceRoot}/app_flowy"
5062
},
63+
{
64+
// This task builds will:
65+
// - call the clean task,
66+
// - rebuild all the generated Files (including freeze and language files)
67+
// - rebuild the the Rust and Dart code of AppFlowy.
68+
"name": "AF: Clean + Rebuild All (Android)",
69+
"request": "launch",
70+
"program": "./lib/main.dart",
71+
"type": "dart",
72+
"preLaunchTask": "AF: Clean + Rebuild All (Android)",
73+
"env": {
74+
"RUST_LOG": "info"
75+
},
76+
"cwd": "${workspaceRoot}/app_flowy"
77+
},
5178
{
5279
"name": "AF: Build All (rustlog: trace)",
5380
"request": "launch",
@@ -59,6 +86,17 @@
5986
},
6087
"cwd": "${workspaceRoot}/app_flowy"
6188
},
89+
{
90+
"name": "AF: Build All Android (rustlog: trace)",
91+
"request": "launch",
92+
"program": "./lib/main.dart",
93+
"type": "dart",
94+
"preLaunchTask": "AF: build_mobile_sdk",
95+
"env": {
96+
"RUST_LOG": "trace"
97+
},
98+
"cwd": "${workspaceRoot}/app_flowy"
99+
},
62100
{
63101
"name": "AF: app_flowy (profile mode)",
64102
"request": "launch",

frontend/.vscode/tasks.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,33 @@
2727
"panel": "new"
2828
}
2929
},
30+
{
31+
"label": "AF: Clean + Rebuild All (Android)",
32+
"type": "shell",
33+
"dependsOrder": "sequence",
34+
"dependsOn": [
35+
"AF: Rust Clean",
36+
"AF: Flutter Clean",
37+
"AF: build_flowy_sdk_for_android",
38+
"AF: Flutter Pub Get",
39+
"AF: Flutter Package Get",
40+
"AF: Generate Language Files",
41+
"AF: Generate Freezed Files",
42+
],
43+
"presentation": {
44+
"reveal": "always",
45+
"panel": "new",
46+
},
47+
},
48+
{
49+
"label": "AF: build_flowy_sdk_for_android",
50+
"type": "shell",
51+
"command": "cargo make --profile development-android flowy-sdk-dev-android",
52+
"group": "build",
53+
"options": {
54+
"cwd": "${workspaceFolder}"
55+
}
56+
},
3057
{
3158
"label": "AF: build_flowy_sdk",
3259
"type": "shell",

frontend/Makefile.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@ TARGET_OS = "ios"
161161
FLUTTER_OUTPUT_DIR = "Release"
162162
PRODUCT_EXT = "ipa"
163163

164+
[env.development-android]
165+
BUILD_FLAG = "debug"
166+
TARGET_OS = "android"
167+
CRATE_TYPE = "cdylib"
168+
FLUTTER_OUTPUT_DIR = "Debug"
164169

165170
[tasks.setup-crate-type]
166171
private = true
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Description
2+
3+
This is a guide on how to build the rust SDK for AppFlowy on android.
4+
Compiling the sdk is easy it just needs a few tweaks.
5+
When compiling for android we need the following pre-requisites:
6+
7+
- Android NDK Tools. (v24 has been tested).
8+
- Cargo NDK. (@latest version).
9+
10+
**Getting the tools**
11+
- Install cargo-ndk ```bash cargo install cargo-ndk```.
12+
- [Download](https://developer.android.com/ndk/downloads/) Android NDK version 24.
13+
- When downloading Android NDK you can get the compressed version as a standalone from the site.
14+
Or you can download it through [Android Studio](https://developer.android.com/studio).
15+
- After downloading the two you need to set the environment variables. For Windows that's a seperate process.
16+
On MacOs and Linux the process is similar.
17+
- The variables needed are '$ANDROID_NDK_HOME', this will point to where the NDK is located.
18+
---
19+
20+
**Cargo Config File**
21+
This code needs to be written in ~/.cargo/config, this helps cargo know where to locate the android tools(linker and archiver).
22+
**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.
23+
24+
```toml
25+
[target.aarch64-linux-android]
26+
ar = "/home/user/Android/Sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar"
27+
linker = "/home/user/Android/Sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android29-clang"
28+
29+
[target.armv7-linux-androideabi]
30+
ar = "/home/user/Android/Sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar"
31+
linker = "/home/user/Android/Sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi29-clang"
32+
33+
[target.i686-linux-android]
34+
ar = "/home/user/Android/Sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar"
35+
linker = "/home/user/Android/Sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android29-clang"
36+
37+
[target.x86_64-linux-android]
38+
ar = "/home/user/Android/Sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar"
39+
linker = "/home/user/Android/Sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android29-clang"
40+
```
41+
42+
**Clang Fix**
43+
In order to get clang to work properly with version 24 you need to create this file.
44+
libgcc.a, then add this one line.
45+
```
46+
INPUT(-lunwind)
47+
```
48+
49+
**Folder path: 'Android/Sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/14.0.1/lib/linux'.**
50+
After that you have to copy this file into three different folders namely aarch64, arm, i386 and x86_64.
51+
We have to do this so we Android NDK can find clang on our system, if we used NDK 22 we wouldnt have to do this process.
52+
Though using NDK v22 will not give us alot of features to work with.
53+
This github [issue](https://github.com/fzyzcjy/flutter_rust_bridge/issues/419) explains the reason why we are doing this.
54+
55+
---
56+
57+
**Android NDK**
58+
59+
After installing the NDK tools for android you should export the PATH to your config file
60+
(.vimrc, .zshrc, .profile, .bashrc file), That way it can be found.
61+
62+
```vim
63+
export PATH=/home/sean/Android/Sdk/ndk/24.0.8215888
64+
```

frontend/app_flowy/android/app/build.gradle

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ apply plugin: 'kotlin-android'
2626
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
2727

2828
android {
29-
compileSdkVersion 30
29+
compileSdkVersion 31
30+
ndkVersion "24.0.8215888"
3031

3132
compileOptions {
3233
sourceCompatibility JavaVersion.VERSION_1_8
@@ -39,21 +40,26 @@ android {
3940

4041
sourceSets {
4142
main.java.srcDirs += 'src/main/kotlin'
43+
main.jniLibs.srcDirs += 'jniLibs/'
4244
}
4345

4446
defaultConfig {
4547
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
4648
applicationId "com.example.app_flowy"
47-
minSdkVersion 16
48-
targetSdkVersion 30
49+
minSdkVersion 19
50+
targetSdkVersion 31
4951
versionCode flutterVersionCode.toInteger()
5052
versionName flutterVersionName
53+
multiDexEnabled true
5154
}
5255

5356
buildTypes {
5457
release {
5558
// TODO: Add your own signing config for the release build.
5659
// Signing with the debug keys for now, so `flutter run --release` works.
60+
minifyEnabled true
61+
shrinkResources true
62+
5763
signingConfig signingConfigs.debug
5864
}
5965
}
@@ -65,4 +71,5 @@ flutter {
6571

6672
dependencies {
6773
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
74+
implementation "com.android.support:multidex:2.0.1"
6875
}

frontend/app_flowy/android/app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
package="com.example.app_flowy">
33
<application
44
android:label="app_flowy"
5-
android:icon="@mipmap/ic_launcher">
5+
android:icon="@mipmap/ic_launcher"
6+
android:name="${applicationName}">
67
<activity
78
android:name=".MainActivity"
89
android:launchMode="singleTop"

frontend/app_flowy/android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
buildscript {
2-
ext.kotlin_version = '1.3.50'
2+
ext.kotlin_version = '1.6.10'
33
repositories {
44
google()
55
mavenCentral()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
org.gradle.jvmargs=-Xmx1536M
22
android.useAndroidX=true
33
android.enableJetifier=true
4+
org.gradle.caching=true
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
#Fri Jun 23 08:50:38 CEST 2017
21
distributionBase=GRADLE_USER_HOME
32
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-all.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip

frontend/app_flowy/android/settings.gradle

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,19 @@ localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
99
def flutterSdkPath = properties.getProperty("flutter.sdk")
1010
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
1111
apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
12+
13+
14+
def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()
15+
16+
def plugins = new Properties()
17+
def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins')
18+
19+
if(pluginsFile.exists()){
20+
pluginsFile.withReader('UTF-8'){reader -> plugins.load(reader)}
21+
}
22+
23+
plugins.each{name, path ->
24+
def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile()
25+
include ":$name"
26+
project(":$name").projectDir = pluginDirectory
27+
}

0 commit comments

Comments
 (0)