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 <86001920+appflowy@users.noreply.github.com>
Co-authored-by: Lucas.Xu <lucas.xu@appflowy.io>
This commit is contained in:
Sean Riley Hawkins 2022-09-01 06:27:09 +02:00 committed by GitHub
parent 70f9a289a4
commit 69e3aed6b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 287 additions and 36 deletions

View File

@ -16,6 +16,18 @@
},
"cwd": "${workspaceRoot}/app_flowy"
},
{
// This task builds the Rust and Dart code of AppFlowy for android.
"name": "AF: Run Android",
"request": "launch",
"program": "./lib/main.dart",
"type": "dart",
"preLaunchTask": "AF: build_mobile_sdk",
"env": {
"RUST_LOG": "info"
},
"cwd": "${workspaceRoot}/app_flowy"
},
{
"name": "AF: Debug Rust",
"request": "attach",
@ -48,6 +60,21 @@
},
"cwd": "${workspaceRoot}/app_flowy"
},
{
// This task builds will:
// - call the clean task,
// - rebuild all the generated Files (including freeze and language files)
// - rebuild the the Rust and Dart code of AppFlowy.
"name": "AF: Clean + Rebuild All (Android)",
"request": "launch",
"program": "./lib/main.dart",
"type": "dart",
"preLaunchTask": "AF: Clean + Rebuild All (Android)",
"env": {
"RUST_LOG": "info"
},
"cwd": "${workspaceRoot}/app_flowy"
},
{
"name": "AF: Build All (rustlog: trace)",
"request": "launch",
@ -59,6 +86,17 @@
},
"cwd": "${workspaceRoot}/app_flowy"
},
{
"name": "AF: Build All Android (rustlog: trace)",
"request": "launch",
"program": "./lib/main.dart",
"type": "dart",
"preLaunchTask": "AF: build_mobile_sdk",
"env": {
"RUST_LOG": "trace"
},
"cwd": "${workspaceRoot}/app_flowy"
},
{
"name": "AF: app_flowy (profile mode)",
"request": "launch",

View File

@ -27,6 +27,33 @@
"panel": "new"
}
},
{
"label": "AF: Clean + Rebuild All (Android)",
"type": "shell",
"dependsOrder": "sequence",
"dependsOn": [
"AF: Rust Clean",
"AF: Flutter Clean",
"AF: build_flowy_sdk_for_android",
"AF: Flutter Pub Get",
"AF: Flutter Package Get",
"AF: Generate Language Files",
"AF: Generate Freezed Files",
],
"presentation": {
"reveal": "always",
"panel": "new",
},
},
{
"label": "AF: build_flowy_sdk_for_android",
"type": "shell",
"command": "cargo make --profile development-android flowy-sdk-dev-android",
"group": "build",
"options": {
"cwd": "${workspaceFolder}"
}
},
{
"label": "AF: build_flowy_sdk",
"type": "shell",

View File

@ -161,6 +161,11 @@ TARGET_OS = "ios"
FLUTTER_OUTPUT_DIR = "Release"
PRODUCT_EXT = "ipa"
[env.development-android]
BUILD_FLAG = "debug"
TARGET_OS = "android"
CRATE_TYPE = "cdylib"
FLUTTER_OUTPUT_DIR = "Debug"
[tasks.setup-crate-type]
private = true

View File

@ -0,0 +1,64 @@
# Description
This is a 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).
- Cargo NDK. (@latest version).
**Getting the tools**
- Install cargo-ndk ```bash cargo install cargo-ndk```.
- [Download](https://developer.android.com/ndk/downloads/) Android NDK version 24.
- 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 seperate process.
On MacOs and Linux the process is similar.
- The variables needed are '$ANDROID_NDK_HOME', this will point to where the NDK is located.
---
**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.
```toml
[target.aarch64-linux-android]
ar = "/home/user/Android/Sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar"
linker = "/home/user/Android/Sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android29-clang"
[target.armv7-linux-androideabi]
ar = "/home/user/Android/Sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar"
linker = "/home/user/Android/Sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi29-clang"
[target.i686-linux-android]
ar = "/home/user/Android/Sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar"
linker = "/home/user/Android/Sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android29-clang"
[target.x86_64-linux-android]
ar = "/home/user/Android/Sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar"
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 wouldnt have to do this process.
Though using NDK v22 will not give us alot 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**
After installing the NDK tools for android you should export the PATH to your config file
(.vimrc, .zshrc, .profile, .bashrc file), That way it can be found.
```vim
export PATH=/home/sean/Android/Sdk/ndk/24.0.8215888
```

View File

@ -26,7 +26,8 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 30
compileSdkVersion 31
ndkVersion "24.0.8215888"
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
@ -39,21 +40,26 @@ android {
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
main.jniLibs.srcDirs += 'jniLibs/'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.app_flowy"
minSdkVersion 16
targetSdkVersion 30
minSdkVersion 19
targetSdkVersion 31
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
minifyEnabled true
shrinkResources true
signingConfig signingConfigs.debug
}
}
@ -65,4 +71,5 @@ flutter {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "com.android.support:multidex:2.0.1"
}

View File

@ -2,7 +2,8 @@
package="com.example.app_flowy">
<application
android:label="app_flowy"
android:icon="@mipmap/ic_launcher">
android:icon="@mipmap/ic_launcher"
android:name="${applicationName}">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"

View File

@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.3.50'
ext.kotlin_version = '1.6.10'
repositories {
google()
mavenCentral()

View File

@ -1,3 +1,4 @@
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
org.gradle.caching=true

View File

@ -1,6 +1,5 @@
#Fri Jun 23 08:50:38 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip

View File

@ -9,3 +9,19 @@ localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()
def plugins = new Properties()
def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins')
if(pluginsFile.exists()){
pluginsFile.withReader('UTF-8'){reader -> plugins.load(reader)}
}
plugins.each{name, path ->
def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile()
include ":$name"
project(":$name").projectDir = pluginDirectory
}

View File

@ -34,6 +34,7 @@ class _MultiBoardListExampleState extends State<MultiBoardListExample> {
RichTextItem(title: "Card 8", subtitle: 'Aug 1, 2020 4:05 PM'),
TextItem("Card 9"),
];
final column1 = AFBoardColumnData(id: "To Do", name: "To Do", items: a);
final column2 = AFBoardColumnData(
id: "In Progress",

View File

@ -2,6 +2,7 @@ group 'com.example.flowy_infra_ui'
version '1.0'
buildscript {
ext.kotlin_version = '1.6.10'
repositories {
google()
mavenCentral()

View File

@ -24,8 +24,16 @@ if (flutterVersionName == null) {
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
//apply plugin: 'kotlin-android-extensions'
//androidExtensions {
// experimental = true
//}
android {
compileSdkVersion flutter.compileSdkVersion
ndkVersion flutter.ndkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
@ -43,20 +51,23 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.flowy_infra_ui_example"
minSdkVersion 16
targetSdkVersion 30
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
compileSdkVersion 30
}
flutter {
@ -65,4 +76,5 @@ flutter {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:multidex:2.0.1'
}

View File

@ -1,7 +0,0 @@
package com.example.flowy_infra_ui_example;
import io.flutter.embedding.android.FlutterActivity;
public class MainActivity extends FlutterActivity {
}

View File

@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.3.50'
ext.kotlin_version = '1.6.10'
repositories {
google()
mavenCentral()

View File

@ -9,3 +9,19 @@ localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()
def plugins = new Properties()
def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins')
if (pluginsFile.exists()) {
pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) }
}
plugins.each { name, path ->
def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile()
include ":$name"
project(":$name").projectDir = pluginDirectory
}

View File

@ -0,0 +1,4 @@
package example.android.app.src.main.java.com.example.flowy_infra_ui_example;
public class FlutterActivity {
}

View File

@ -2,7 +2,7 @@ group 'com.plugin.flowy_sdk'
version '1.0-SNAPSHOT'
buildscript {
ext.kotlin_version = '1.3.50'
ext.kotlin_version = '1.6.10'
repositories {
google()
jcenter()
@ -25,7 +25,7 @@ apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
android {
compileSdkVersion 30
compileSdkVersion 31
sourceSets {
main.java.srcDirs += 'src/main/kotlin'

View File

@ -36,7 +36,7 @@ android {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.plugin.flowy_sdk_example"
minSdkVersion 16
targetSdkVersion 30
targetSdkVersion 31
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}

View File

@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.3.50'
ext.kotlin_version = '1.6.10'
repositories {
google()
jcenter()

View File

@ -14,11 +14,14 @@ final DynamicLibrary dl = _dl;
DynamicLibrary _open() {
if (Platform.environment.containsKey('FLUTTER_TEST')) {
final prefix = "${Directory.current.path}/.sandbox";
if (Platform.isLinux) return DynamicLibrary.open('${prefix}/libdart_ffi.so');
if (Platform.isAndroid) return DynamicLibrary.open('${prefix}/libdart_ffi.so');
if (Platform.isLinux)
return DynamicLibrary.open('${prefix}/libdart_ffi.so');
if (Platform.isAndroid)
return DynamicLibrary.open('${prefix}/libdart_ffi.so');
if (Platform.isMacOS) return DynamicLibrary.open('${prefix}/libdart_ffi.a');
if (Platform.isIOS) return DynamicLibrary.open('${prefix}/libdart_ffi.a');
if (Platform.isWindows) return DynamicLibrary.open('${prefix}/dart_ffi.dll');
if (Platform.isWindows)
return DynamicLibrary.open('${prefix}/dart_ffi.dll');
} else {
if (Platform.isLinux) return DynamicLibrary.open('libdart_ffi.so');
if (Platform.isAndroid) return DynamicLibrary.open('libdart_ffi.so');
@ -39,7 +42,8 @@ void async_event(
_invoke_async(port, input, len);
}
final _invoke_async_Dart _invoke_async = _dl.lookupFunction<_invoke_async_C, _invoke_async_Dart>('async_event');
final _invoke_async_Dart _invoke_async =
_dl.lookupFunction<_invoke_async_C, _invoke_async_Dart>('async_event');
typedef _invoke_async_C = Void Function(
Int64 port,
Pointer<Uint8> input,
@ -59,7 +63,8 @@ Pointer<Uint8> sync_event(
return _invoke_sync(input, len);
}
final _invoke_sync_Dart _invoke_sync = _dl.lookupFunction<_invoke_sync_C, _invoke_sync_Dart>('sync_event');
final _invoke_sync_Dart _invoke_sync =
_dl.lookupFunction<_invoke_sync_C, _invoke_sync_Dart>('sync_event');
typedef _invoke_sync_C = Pointer<Uint8> Function(
Pointer<Uint8> input,
Uint64 len,
@ -76,7 +81,8 @@ int init_sdk(
return _init_sdk(path);
}
final _init_sdk_Dart _init_sdk = _dl.lookupFunction<_init_sdk_C, _init_sdk_Dart>('init_sdk');
final _init_sdk_Dart _init_sdk =
_dl.lookupFunction<_init_sdk_C, _init_sdk_Dart>('init_sdk');
typedef _init_sdk_C = Int64 Function(
Pointer<ffi.Utf8> path,
);
@ -90,7 +96,8 @@ int set_stream_port(int port) {
}
final _set_stream_port_Dart _set_stream_port =
_dl.lookupFunction<_set_stream_port_C, _set_stream_port_Dart>('set_stream_port');
_dl.lookupFunction<_set_stream_port_C, _set_stream_port_Dart>(
'set_stream_port');
typedef _set_stream_port_C = Int32 Function(
Int64 port,
@ -104,8 +111,8 @@ void link_me_please() {
_link_me_please();
}
final _link_me_please_Dart _link_me_please =
_dl.lookupFunction<_link_me_please_C, _link_me_please_Dart>('link_me_please');
final _link_me_please_Dart _link_me_please = _dl
.lookupFunction<_link_me_please_C, _link_me_please_Dart>('link_me_please');
typedef _link_me_please_C = Void Function();
typedef _link_me_please_Dart = void Function();
@ -116,8 +123,9 @@ void store_dart_post_cobject(
_store_dart_post_cobject(ptr);
}
final _store_dart_post_cobject_Dart _store_dart_post_cobject =
_dl.lookupFunction<_store_dart_post_cobject_C, _store_dart_post_cobject_Dart>('store_dart_post_cobject');
final _store_dart_post_cobject_Dart _store_dart_post_cobject = _dl
.lookupFunction<_store_dart_post_cobject_C, _store_dart_post_cobject_Dart>(
'store_dart_post_cobject');
typedef _store_dart_post_cobject_C = Void Function(
Pointer<NativeFunction<Int8 Function(Int64, Pointer<Dart_CObject>)>> ptr,
);

View File

@ -5,4 +5,20 @@
rustflags=["-C", "link-arg=-mmacosx-version-min=10.11"]
[target.aarch64-apple-darwin]
rustflags=["-C", "link-arg=-mmacosx-version-min=10.11"]
rustflags=["-C", "link-arg=-mmacosx-version-min=10.11"]
[target.aarch64-linux-android]
ar = "path-to-ndk/llvm-ar"
linker = "path-to-ndk/aarch64-linux-android29-clang"
[target.armv7-linux-androideabi]
ar = "path-to-ndk/llvm-ar"
linker = "path-to-ndk/armv7a-linux-androideabi29-clang"
[target.i686-linux-android]
ar = "path-to-ndk/llvm-ar"
linker = "path-to-ndk/i686-linux-android29-clang"
[target.x86_64-linux-android]
ar = "path-to-ndk/llvm-ar"
linker = "path-to-ndk/x86_64-linux-android29-clang"

View File

@ -1796,6 +1796,7 @@ dependencies = [
"lazy_static",
"libsqlite3-sys",
"log",
"openssl",
"r2d2",
"scheduled-thread-pool",
]
@ -2096,6 +2097,15 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
[[package]]
name = "openssl-src"
version = "111.22.0+1.1.1q"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f31f0d509d1c1ae9cada2f9539ff8f37933831fd5098879e482aa687d659853"
dependencies = [
"cc",
]
[[package]]
name = "openssl-sys"
version = "0.9.72"
@ -2105,6 +2115,7 @@ dependencies = [
"autocfg",
"cc",
"libc",
"openssl-src",
"pkg-config",
"vcpkg",
]

View File

@ -38,4 +38,4 @@ http_sync = ["flowy-sdk/http_sync", "flowy-sdk/use_bunyan"]
#use_protobuf= ["protobuf"]
[build-dependencies]
lib-infra = { path = "../../../shared-lib/lib-infra", features = ["protobuf_file_gen", "dart"] }
lib-infra = { path = "../../../shared-lib/lib-infra", features = ["protobuf_file_gen", "dart"] }

View File

@ -15,6 +15,6 @@ lazy_static = "1.4.0"
scheduled-thread-pool = "0.2.5"
error-chain = "=0.12.0"
log = "0.4.11"
openssl = { version = "0.10.38", features = ["vendored"] }
#[features]
#windows = ["libsqlite3-sys/bundled-windows"]

View File

@ -13,6 +13,11 @@ mac_alias = "flowy-sdk-dev-macos"
windows_alias = "flowy-sdk-dev-windows"
linux_alias = "flowy-sdk-dev-linux"
[tasks.flowy-sdk-dev-android]
category = "Build"
dependencies = ["env_check"]
run_task = { name = ["setup-crate-type","sdk-build-android", "restore-crate-type"] }
[tasks.flowy-sdk-dev-macos]
category = "Build"
dependencies = ["env_check"]
@ -42,6 +47,32 @@ script = [
]
script_runner = "@shell"
[tasks.sdk-build-android]
private = true
script = [
"""
cd rust-lib/
rustup show
rustup target add aarch64-linux-android \
armv7-linux-androideabi \
i686-linux-android \
x86_64-linux-android
DEST=${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/app_flowy/android/app/src/main/jniLibs
rm -rf $DEST/arm64-v8a \
$DEST/armeabi-v7a \
$DEST/x86 \
$DEST/x86_64
cargo ndk \
-t arm64-v8a \
-t armeabi-v7a \
-t x86 \
-t x86_64 \
-o $DEST build
cd ../
""",
]
script_runner = "@shell"
[tasks.sdk-build.windows]
private = true
script = [