Skip to content

Commit 21630b1

Browse files
committed
blutter: better handle APK files
*android: ktlint for kotlin files
1 parent b383dd8 commit 21630b1

File tree

5 files changed

+78
-21
lines changed

5 files changed

+78
-21
lines changed

android/app/build.gradle.kts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ plugins {
66
id("kotlin-android")
77
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
88
id("dev.flutter.flutter-gradle-plugin")
9+
// kt lint
10+
id("org.jmailen.kotlinter")
911
}
1012

1113
val keystoreProperties = Properties()
@@ -45,10 +47,7 @@ android {
4547
}
4648

4749
defaultConfig {
48-
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
4950
applicationId = "org.revengi.app"
50-
// You can update the following values to match your application needs.
51-
// For more information, see: https://flutter.dev/to/review-gradle-config.
5251
minSdk = flutter.minSdkVersion
5352
targetSdk = flutter.targetSdkVersion
5453
versionCode = flutter.versionCode
@@ -57,8 +56,6 @@ android {
5756

5857
buildTypes {
5958
release {
60-
// TODO: Add your own signing config for the release build.
61-
// Signing with the debug keys for now, so `flutter run --release` works.
6259
// signingConfig = signingConfigs.getByName("debug")
6360
signingConfig = signingConfigs.getByName("release")
6461
}

android/app/src/main/kotlin/org/revengi/app/MainActivity.kt

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,37 @@
11
package org.revengi.app
22

3-
import io.flutter.embedding.android.FlutterActivity
43
import android.os.Build
5-
import androidx.annotation.NonNull
4+
import io.flutter.embedding.android.FlutterActivity
65
import io.flutter.embedding.engine.FlutterEngine
76
import io.flutter.plugin.common.MethodChannel
87

98
class MainActivity : FlutterActivity() {
10-
private val CHANNEL = "flutter.native/helper"
9+
private val myChannel = "flutter.native/helper"
1110

12-
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
11+
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
1312
super.configureFlutterEngine(flutterEngine)
14-
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { call, result ->
15-
if (call.method == "getDeviceInfo") {
16-
val deviceInfo: HashMap<String, String> = getDeviceInfo()
17-
if (deviceInfo.isNotEmpty()) {
18-
result.success(deviceInfo)
19-
} else {
20-
result.error("UNAVAILABLE", "Device info not available.", null)
13+
MethodChannel(
14+
flutterEngine.dartExecutor.binaryMessenger,
15+
myChannel,
16+
).setMethodCallHandler { call, result ->
17+
when (call.method) {
18+
"getDeviceInfo" -> {
19+
val deviceInfo: HashMap<String, String> = getDeviceInfo()
20+
if (deviceInfo.isNotEmpty()) {
21+
result.success(deviceInfo)
22+
} else {
23+
result.error("UNAVAILABLE", "Device info not available.", null)
24+
}
2125
}
22-
} else {
23-
result.notImplemented()
26+
27+
else -> result.notImplemented()
2428
}
2529
}
2630
}
2731

2832
private fun getDeviceInfo(): HashMap<String, String> {
2933
val deviceInfo = HashMap<String, String>()
30-
deviceInfo["version"] = System.getProperty("os.version").toString()
34+
deviceInfo["version"] = System.getProperty("os.version")!!.toString()
3135
deviceInfo["device"] = Build.DEVICE
3236
deviceInfo["model"] = Build.MODEL
3337
deviceInfo["product"] = Build.PRODUCT

android/settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ plugins {
2020
id("dev.flutter.flutter-plugin-loader") version "1.0.0"
2121
id("com.android.application") version "8.7.0" apply false
2222
id("org.jetbrains.kotlin.android") version "1.8.22" apply false
23+
id("org.jmailen.kotlinter") version "5.1.0" apply false
2324
}
2425

2526
include(":app")

lib/screens/blutter/blutter_io.dart

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,16 @@ class _BlutterAnalysisScreenState extends State<BlutterAnalysisScreen> {
4949
final Directory directory = Directory.systemTemp;
5050
final apkPath = _apkFile!.path;
5151
final zipFile = File(apkPath);
52+
String fileEnd = "arm64-v8a/libapp.so";
53+
if (apkPath.split(Platform.pathSeparator).last.endsWith('.zip')) {
54+
fileEnd = "libapp.so";
55+
}
5256

5357
try {
5458
final archive = ZipDecoder().decodeBytes(await zipFile.readAsBytes());
5559

5660
for (final file in archive) {
57-
if (file.isFile && file.name.endsWith('libapp.so')) {
61+
if (file.isFile && file.name.endsWith(fileEnd)) {
5862
final data = file.content as List<int>;
5963
_libappFile = File('${directory.path}/libapp.so')
6064
..writeAsBytesSync(data);
@@ -226,6 +230,30 @@ class _BlutterAnalysisScreenState extends State<BlutterAnalysisScreen> {
226230
),
227231
),
228232
const SizedBox(height: 16),
233+
RichText(
234+
text: TextSpan(
235+
children: [
236+
TextSpan(
237+
text: 'Note: ',
238+
style: const TextStyle(
239+
fontSize: 14,
240+
color: Colors.orange,
241+
fontWeight: FontWeight.bold,
242+
),
243+
),
244+
TextSpan(
245+
text:
246+
'\nAPK: The app will directly handle APK files.\n'
247+
'\nZIP: Ensure ZIP files contain only the `libapp.so` for arm64 architecture. Failure to comply may result in errors.',
248+
style: const TextStyle(
249+
fontSize: 14,
250+
color: Colors.grey,
251+
),
252+
),
253+
],
254+
),
255+
),
256+
const SizedBox(height: 16),
229257
SizedBox(
230258
width: double.infinity,
231259
child: ElevatedButton.icon(

lib/screens/blutter/blutter_web.dart

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,15 @@ class _BlutterAnalysisScreenState extends State<BlutterAnalysisScreen> {
5050

5151
Future<void> _extractFiles() async {
5252
if (_fileBytes.isEmpty) return;
53+
String fileEnd = "arm64-v8a/libapp.so";
54+
if (_fileName!.endsWith('.zip')) {
55+
fileEnd = "libapp.so";
56+
}
5357
try {
5458
final archive = ZipDecoder().decodeBytes(_fileBytes);
5559

5660
for (final file in archive) {
57-
if (file.isFile && file.name.endsWith('libapp.so')) {
61+
if (file.isFile && file.name.endsWith(fileEnd)) {
5862
_libappBytes = file.content as List<int>;
5963
} else if (file.isFile && file.name.endsWith('libflutter.so')) {
6064
_libflutterBytes = file.content as List<int>;
@@ -216,6 +220,29 @@ class _BlutterAnalysisScreenState extends State<BlutterAnalysisScreen> {
216220
),
217221
),
218222
const SizedBox(height: 16),
223+
RichText(
224+
text: TextSpan(
225+
children: [
226+
TextSpan(
227+
text: 'Note: ',
228+
style: const TextStyle(
229+
fontSize: 14,
230+
color: Colors.orange,
231+
fontWeight: FontWeight.bold,
232+
),
233+
),
234+
TextSpan(
235+
text:
236+
'\nAPK: The app will directly handle APK files.\n'
237+
'\nZIP: Ensure ZIP files contain only the `libapp.so` for arm64 architecture. Failure to comply may result in errors.',
238+
style: const TextStyle(
239+
fontSize: 14,
240+
color: Colors.grey,
241+
),
242+
),
243+
],
244+
),
245+
),
219246
SizedBox(
220247
width: double.infinity,
221248
child: ElevatedButton.icon(

0 commit comments

Comments
 (0)