Skip to content

Commit 85767f0

Browse files
authored
KODO-22033 解除platform_info和system2的依赖,以修复Android平台小概率崩溃问题 (#101)
* 对example添加UA测试 * 添加example打包ci * 更新checkout版本 * 修改ci名称 * 修复ci版本 * 每个job添加default working directory * 移除liunx ci配置 * 移除base包中的system_info2和platform_info相关依赖 * 添加platform_info * 降级platform_info * 修复错误 * 更新CI脚本 * 更新CI脚本 * Android为release模式添加网络权限 * 发布0.7.2版本 * 更新CI在PR下的上传名称
1 parent e0cfa29 commit 85767f0

File tree

11 files changed

+171
-31
lines changed

11 files changed

+171
-31
lines changed

.github/workflows/build-example.yml

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
name: Build example app and upload to artifact file
2+
3+
on:
4+
push:
5+
pull_request: { branches: [master] }
6+
7+
jobs:
8+
build-android:
9+
runs-on: ubuntu-latest
10+
defaults:
11+
run:
12+
working-directory: ./flutter/example
13+
steps:
14+
- uses: nelonoel/branch-name@v1.0.1
15+
- uses: benjlevesque/short-sha@v1.2
16+
id: short-sha
17+
with: { length: 7 }
18+
19+
- uses: actions/checkout@v4
20+
- uses: subosito/flutter-action@v2
21+
with: { channel: stable, cache: true }
22+
- name: 🏗️ Build Apk (arm64,x64,arm)
23+
run: flutter build apk --split-per-abi --target-platform android-arm64,android-x64,android-arm
24+
25+
- name: Upload armeabi-v7a apk artifact File
26+
uses: actions/upload-artifact@v4
27+
with:
28+
name: example-app-${{ env.SHA }}-app-armeabi-v7a-release.apk
29+
path: flutter/example/build/app/outputs/flutter-apk/app-armeabi-v7a-release.apk
30+
31+
- name: Upload arm64-v8a apk artifact File
32+
uses: actions/upload-artifact@v4
33+
with:
34+
name: example-app-${{ env.SHA }}-app-arm64-v8a-release.apk
35+
path: flutter/example/build/app/outputs/flutter-apk/app-arm64-v8a-release.apk
36+
37+
- name: Upload x86_64 apk artifact File
38+
uses: actions/upload-artifact@v4
39+
with:
40+
name: example-app-${{ env.SHA }}-app-x86_64-release.apk
41+
path: flutter/example/build/app/outputs/flutter-apk/app-x86_64-release.apk
42+
43+
build-windows:
44+
runs-on: windows-latest
45+
defaults:
46+
run:
47+
working-directory: ./flutter/example
48+
steps:
49+
- uses: nelonoel/branch-name@v1.0.1
50+
- uses: benjlevesque/short-sha@v1.2
51+
id: short-sha
52+
with: { length: 7 }
53+
54+
- uses: actions/checkout@v4
55+
56+
- uses: subosito/flutter-action@v2
57+
with: { channel: stable, cache: true }
58+
59+
- run: |
60+
flutter config --enable-windows-desktop
61+
flutter pub get
62+
flutter build windows
63+
64+
- name: Upload Windows build file
65+
uses: actions/upload-artifact@v4
66+
with:
67+
name: example-app-${{ env.SHA }}-windows-x86_64.zip
68+
path: flutter/example/build/windows/x64/runner/Release
69+
70+
build-ios:
71+
runs-on: macos-latest
72+
defaults:
73+
run:
74+
working-directory: ./flutter/example
75+
steps:
76+
- uses: actions/checkout@v4
77+
- uses: maxim-lobanov/setup-xcode@v1
78+
with:
79+
xcode-version: latest-stable
80+
81+
- uses: subosito/flutter-action@v2
82+
with: { channel: stable, cache: true }
83+
84+
- name: 🏗️ Build iOS
85+
run: flutter build ios --no-codesign
86+
87+
build-macos:
88+
runs-on: macos-latest
89+
defaults:
90+
run:
91+
working-directory: ./flutter/example
92+
steps:
93+
- uses: nelonoel/branch-name@v1.0.1
94+
- uses: benjlevesque/short-sha@v1.2
95+
id: short-sha
96+
with: { length: 7 }
97+
- uses: actions/checkout@v4
98+
99+
- uses: subosito/flutter-action@v2
100+
with: { channel: stable, cache: true }
101+
102+
# Building
103+
- name: Build macOS
104+
run: |
105+
flutter config --enable-macos-desktop
106+
flutter pub get
107+
flutter build macos --release
108+
109+
- name: Upload web File
110+
uses: actions/upload-artifact@v4
111+
with:
112+
name: example-app-${{ env.SHA }}-macos.zip
113+
path: flutter/example/build/macos/Build/Products/Release
114+
115+
build-web:
116+
runs-on: ubuntu-latest
117+
defaults:
118+
run:
119+
working-directory: ./flutter/example
120+
steps:
121+
- uses: nelonoel/branch-name@v1.0.1
122+
- uses: benjlevesque/short-sha@v1.2
123+
id: short-sha
124+
with: { length: 7 }
125+
126+
- uses: actions/checkout@v4
127+
- uses: subosito/flutter-action@v2
128+
with: { channel: stable, cache: true }
129+
- run: |
130+
flutter pub get
131+
flutter build web --no-source-maps --no-native-null-assertions --release
132+
133+
- name: Upload web File
134+
uses: actions/upload-artifact@v4
135+
with:
136+
name: example-app-${{ env.SHA }}-web.zip
137+
path: flutter/example/build/web

base/lib/src/storage/config/host.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ class DefaultHostProviderV2 extends HostFreezer {
210210
if (_query != null) {
211211
return _query!;
212212
}
213+
213214
_query = await _group.doGroup(
214215
'',
215216
() async => BucketRegionsQuery.create(

base/lib/src/util/user_agent/user_agent/app.dart

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,14 @@
1+
import 'dart:io';
2+
13
import 'package:qiniu_sdk_base/qiniu_sdk_base.dart';
2-
import 'package:system_info2/system_info2.dart';
3-
import 'package:platform_info/platform_info.dart';
44

55
// 这个函数无论如何都不应该抛出异常,即使内部依赖的第三方库不支持目标运行平台
66
String getDefaultUserAgent() {
7-
final components = <String>['QiniuDart/v$currentVersion'];
8-
9-
try {
10-
platform.when(
11-
iOS: () {
12-
components.add('iOS');
13-
},
14-
orElse: () {
15-
// SystemInfo2 只支持android/linux/macos/windows
16-
components.addAll([
17-
'(${SysInfo.kernelName}; ${SysInfo.kernelVersion}; ${SysInfo.kernelArchitecture})',
18-
'(${SysInfo.operatingSystemName}; ${SysInfo.operatingSystemVersion})',
19-
]);
20-
},
21-
);
22-
} catch (e) {
23-
// 其他任何报错
24-
components.add('UnknownPlatform');
25-
}
7+
final components = <String>[
8+
'QiniuDart/v$currentVersion', // SDK版本
9+
'(${Platform.operatingSystem}; ${Platform.operatingSystemVersion})', // OS 版本
10+
'(${Platform.version})', // Dart版本
11+
];
2612

2713
// 有的操作系统(如Windows)名称可能会返回中文,这里把所有非ascii字符都过滤掉,防止设置User-Agent时产生报错
2814
return String.fromCharCodes(

base/lib/src/version.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import 'package:version/version.dart';
22

3-
final Version currentVersion = Version.parse('0.7.1');
3+
final Version currentVersion = Version.parse('0.7.2');

base/pubspec.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: qiniu_sdk_base
2-
version: 0.7.1
2+
version: 0.7.2
33
homepage: https://github.com/qiniu/dart-sdk
44
description: The sdk basic of Qiniu products
55

@@ -22,9 +22,7 @@ dependencies:
2222
convert: ^3.1.1
2323
singleflight: ^1.0.2
2424
mutex: ^3.1.0
25-
platform_info: ^4.0.0 # 用于实现平台相关feature的判断逻辑
26-
27-
system_info2: ^4.0.0 # web平台不支持,需要特殊处理
25+
platform_info: ^4.0.0
2826

2927
dev_dependencies:
3028
test: any

flutter/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.7.2
2+
3+
* 移除 SystemInfo2 依赖,仅使用标准库 Platform 获取平台信息,修复 Android 平台的兼容性问题
4+
15
## 0.7.1
26

37
* 修复由于 SystemInfo2 引入导致的 Web/iOS/Windows 平台的不兼容问题

flutter/example/.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
/build/
3333

3434
# Web related
35-
lib/generated_plugin_registrant.dart
3635

3736
# Symbolication related
3837
app.*.symbols
@@ -45,4 +44,4 @@ app.*.map.json
4544
/android/app/profile
4645
/android/app/release
4746

48-
pubspec.lock
47+
pubspec.lock

flutter/example/android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
2+
<uses-permission android:name="android.permission.INTERNET"/>
23
<application
34
android:label="qiniu_flutter_sdk_example"
45
android:name="${applicationName}"

flutter/example/lib/main.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import 'package:file_picker/file_picker.dart';
55
import 'package:flutter/foundation.dart';
66
import 'package:flutter/material.dart';
77
import 'package:qiniu_flutter_sdk/qiniu_flutter_sdk.dart';
8+
import 'package:qiniu_sdk_base/src/util/user_agent/user_agent.dart';
9+
810
import 'utils/uint.dart';
911
import 'widgets/app.dart';
1012
import 'widgets/console.dart';
@@ -291,6 +293,18 @@ class BaseState extends State<Base> with DisposableState {
291293
padding: EdgeInsets.all(8.0),
292294
child: Console(),
293295
),
296+
Padding(
297+
padding: const EdgeInsets.all(20),
298+
child: Row(
299+
children: [
300+
TextButton(
301+
onPressed: () {
302+
printToConsole('成功获取上传UA: ${getDefaultUserAgent()}');
303+
},
304+
child: Text('获取UA'))
305+
],
306+
),
307+
),
294308
]);
295309
}
296310
}

flutter/lib/src/version.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import 'package:version/version.dart';
22

33
/// 当前SDK版本号
4-
final Version currentVersion = Version.parse('0.7.1');
4+
final Version currentVersion = Version.parse('0.7.2');

flutter/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: qiniu_flutter_sdk
22
description: Qiniu Flutter sdk
3-
version: 0.7.1
3+
version: 0.7.2
44
homepage: https://github.com/qiniu/dart-sdk/tree/master/flutter
55

66
environment:
@@ -11,7 +11,7 @@ dependencies:
1111
device_info_plus: ^11.3.0
1212
flutter:
1313
sdk: flutter
14-
qiniu_sdk_base: ^0.7.1
14+
qiniu_sdk_base: ^0.7.2
1515
version: ^3.0.2
1616

1717
dev_dependencies:

0 commit comments

Comments
 (0)