Skip to content

Commit

Permalink
Multiplatform build
Browse files Browse the repository at this point in the history
  • Loading branch information
lbirkert committed Aug 22, 2024
1 parent 707a746 commit 56d3606
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 28 deletions.
18 changes: 18 additions & 0 deletions qb-mobile/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ android {
namespace = "com.example.qb_mobile"
compileSdk = flutter.compileSdkVersion
ndkVersion = flutter.ndkVersion

packagingOptions {
jniLibs {
useLegacyPackaging = true
}
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
Expand Down Expand Up @@ -37,6 +43,18 @@ android {
signingConfig = signingConfigs.debug
}
}

sourceSets {
main {
jniLibs.srcDirs += "native"
}
debug {
jniLibs.srcDirs += "native"
}
profile {
jniLibs.srcDirs += "native"
}
}
}

flutter {
Expand Down
9 changes: 7 additions & 2 deletions qb-mobile/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.qb_mobile" >
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/>

<application
android:label="qb_mobile"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
android:icon="@mipmap/ic_launcher"
android:extractNativeLibs="true"
tools:replace="android:extractNativeLibs" >
<activity
android:name=".MainActivity"
android:exported="true"
Expand Down
19 changes: 19 additions & 0 deletions qb-mobile/build_android.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This shell file is for building android specific
# files required for the application to work.

cd ..
# Build the daemon for android
cargo ndk \
-t armeabi-v7a \
-t arm64-v8a \
-t x86_64 \
build \
--bin qb-daemon \
--release \
--no-default-features \
--features ring

mkdir -p qb-mobile/bin
cp target/armv7-linux-androideabi/release/qb-daemon qb-mobile/assets/bin/qb-daemon-armeabi-v7a
cp target/aarch64-linux-android/release/qb-daemon qb-mobile/assets/bin/qb-daemon-arm64-v8a
cp target/x86_64-linux-android/release/qb-daemon qb-mobile/assets/bin/qb-daemon-x86_64
1 change: 1 addition & 0 deletions qb-mobile/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:qb_mobile/service.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();
print("kekw");
await initializeService();

runApp(const QuixByteApp());
Expand Down
63 changes: 40 additions & 23 deletions qb-mobile/lib/service.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:io';
import 'dart:ui';
import 'dart:async';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/services.dart';
import 'package:path_provider/path_provider.dart';
import 'package:process/process.dart';
Expand Down Expand Up @@ -48,18 +49,33 @@ Future<bool> onIosBackground(ServiceInstance service) async {
}

@pragma('vm:entry-point')

void onStart(ServiceInstance service) async {
final cacheDir = await getApplicationCacheDirectory();
final file = File('${cacheDir.path}/bin/qb-daemon');
//if(!await file.exists()) {
await copyBinary(file);
//}

final process = await processManager.start([file.path, '--no-ipc --std']);
process.stdout.listen((data) {
print("recv: $data");
});
final dir = await getApplicationSupportDirectory();
final deviceInfo = DeviceInfoPlugin();
print("kekw");
if (Platform.isAndroid) {
final binaryAbis = ["arm64-v8a", "armeabi-v7a", "x86_64"];
final androidInfo = await deviceInfo.androidInfo;
final supportedAbis = androidInfo.supportedAbis;
final abi = binaryAbis.firstWhere((abi) => supportedAbis.contains(abi));
//final file = File('${dir.path}/bin/qb-daemon-$abi');
//if(!await file.exists()) {
//await copyBinary('qb-daemon-$abi', file);
//}

final fileProc = await processManager.run(['ls', '-la', '/data/app/com.example.qb_mobile.apk']);
print(fileProc.stdout);
print(fileProc.stderr);

final file = File('');
final process = await processManager.run([file.path, '--no-ipc --std'], runInShell: true);
print(process.stderr);
process.stdout.listen((data) {
print("recv: $data");
});
} else {
throw UnimplementedError("QuixByte does not support this device (yet)!");
}

service.on("stop").listen((event) {
service.stopSelf();
Expand All @@ -75,15 +91,16 @@ void onStart(ServiceInstance service) async {
});
}

Future<void> copyBinary(File dst) async {
await dst.create(recursive: true);
final src = await rootBundle.load("assets/bin/qb-daemon");
await dst.writeAsBytes(src.buffer.asUint8List(src.offsetInBytes, src.lengthInBytes));
print(src.lengthInBytes);

final chmodProc = await processManager.run(['chmod', '+x', dst.path], runInShell: true);
print(chmodProc.stdout);

final fileProc = await processManager.run(['file', dst.path]);
print(fileProc.stdout);
}
//Future<void> copyBinary(String srcBin, File dst) async {
// await dst.create(recursive: true);
// final src = await rootBundle.load("assets/bin/$srcBin");
// await dst.writeAsBytes(src.buffer.asUint8List(src.offsetInBytes, src.lengthInBytes));
// print(src.lengthInBytes);
//
// final chmodProc = await processManager.run(['chmod', '+x', dst.path], runInShell: true);
// print(chmodProc.stdout);
// print(chmodProc.stderr);
//
// final fileProc = await processManager.run(['ls', '-la', dst.path]);
// print(fileProc.stdout);
//}
2 changes: 2 additions & 0 deletions qb-mobile/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import FlutterMacOS
import Foundation

import device_info_plus
import path_provider_foundation

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
}
45 changes: 45 additions & 0 deletions qb-mobile/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.0.8"
device_info_plus:
dependency: "direct main"
description:
name: device_info_plus
sha256: a7fd703482b391a87d60b6061d04dfdeab07826b96f9abd8f5ed98068acc0074
url: "https://pub.dev"
source: hosted
version: "10.1.2"
device_info_plus_platform_interface:
dependency: transitive
description:
name: device_info_plus_platform_interface
sha256: "282d3cf731045a2feb66abfe61bbc40870ae50a3ed10a4d3d217556c35c8c2ba"
url: "https://pub.dev"
source: hosted
version: "7.0.1"
fake_async:
dependency: transitive
description:
Expand Down Expand Up @@ -123,6 +139,11 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_web_plugins:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
leak_tracker:
dependency: transitive
description:
Expand Down Expand Up @@ -328,6 +349,30 @@ packages:
url: "https://pub.dev"
source: hosted
version: "14.2.4"
web:
dependency: transitive
description:
name: web
sha256: d43c1d6b787bf0afad444700ae7f4db8827f701bc61c255ac8d328c6f4d52062
url: "https://pub.dev"
source: hosted
version: "1.0.0"
win32:
dependency: transitive
description:
name: win32
sha256: "68d1e89a91ed61ad9c370f9f8b6effed9ae5e0ede22a270bdfa6daf79fc2290a"
url: "https://pub.dev"
source: hosted
version: "5.5.4"
win32_registry:
dependency: transitive
description:
name: win32_registry
sha256: "723b7f851e5724c55409bb3d5a32b203b3afe8587eaf5dafb93a5fed8ecda0d6"
url: "https://pub.dev"
source: hosted
version: "1.1.4"
xdg_directories:
dependency: transitive
description:
Expand Down
4 changes: 1 addition & 3 deletions qb-mobile/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ dependencies:
cupertino_icons: ^1.0.8
process: ^5.0.2
path_provider: ^2.1.4
device_info_plus: ^10.1.2

dev_dependencies:
flutter_test:
Expand All @@ -61,9 +62,6 @@ flutter:
# the material Icons class.
uses-material-design: true

assets:
- assets/bin/

# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
Expand Down

0 comments on commit 56d3606

Please sign in to comment.