Skip to content

KODO-22033 解除platform_info和system2的依赖,以修复Android平台小概率崩溃问题 #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Jun 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 137 additions & 0 deletions .github/workflows/build-example.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
name: Build example app and upload to artifact file

on:
push:
pull_request: { branches: [master] }

jobs:
build-android:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./flutter/example
steps:
- uses: nelonoel/branch-name@v1.0.1
- uses: benjlevesque/short-sha@v1.2
id: short-sha
with: { length: 7 }

- uses: actions/checkout@v4
- uses: subosito/flutter-action@v2
with: { channel: stable, cache: true }
- name: 🏗️ Build Apk (arm64,x64,arm)
run: flutter build apk --split-per-abi --target-platform android-arm64,android-x64,android-arm

- name: Upload armeabi-v7a apk artifact File
uses: actions/upload-artifact@v4
with:
name: example-app-${{ env.SHA }}-app-armeabi-v7a-release.apk
path: flutter/example/build/app/outputs/flutter-apk/app-armeabi-v7a-release.apk

- name: Upload arm64-v8a apk artifact File
uses: actions/upload-artifact@v4
with:
name: example-app-${{ env.SHA }}-app-arm64-v8a-release.apk
path: flutter/example/build/app/outputs/flutter-apk/app-arm64-v8a-release.apk

- name: Upload x86_64 apk artifact File
uses: actions/upload-artifact@v4
with:
name: example-app-${{ env.SHA }}-app-x86_64-release.apk
path: flutter/example/build/app/outputs/flutter-apk/app-x86_64-release.apk

build-windows:
runs-on: windows-latest
defaults:
run:
working-directory: ./flutter/example
steps:
- uses: nelonoel/branch-name@v1.0.1
- uses: benjlevesque/short-sha@v1.2
id: short-sha
with: { length: 7 }

- uses: actions/checkout@v4

- uses: subosito/flutter-action@v2
with: { channel: stable, cache: true }

- run: |
flutter config --enable-windows-desktop
flutter pub get
flutter build windows

- name: Upload Windows build file
uses: actions/upload-artifact@v4
with:
name: example-app-${{ env.SHA }}-windows-x86_64.zip
path: flutter/example/build/windows/x64/runner/Release

build-ios:
runs-on: macos-latest
defaults:
run:
working-directory: ./flutter/example
steps:
- uses: actions/checkout@v4
- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: latest-stable

- uses: subosito/flutter-action@v2
with: { channel: stable, cache: true }

- name: 🏗️ Build iOS
run: flutter build ios --no-codesign

build-macos:
runs-on: macos-latest
defaults:
run:
working-directory: ./flutter/example
steps:
- uses: nelonoel/branch-name@v1.0.1
- uses: benjlevesque/short-sha@v1.2
id: short-sha
with: { length: 7 }
- uses: actions/checkout@v4

- uses: subosito/flutter-action@v2
with: { channel: stable, cache: true }

# Building
- name: Build macOS
run: |
flutter config --enable-macos-desktop
flutter pub get
flutter build macos --release

- name: Upload web File
uses: actions/upload-artifact@v4
with:
name: example-app-${{ env.SHA }}-macos.zip
path: flutter/example/build/macos/Build/Products/Release

build-web:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./flutter/example
steps:
- uses: nelonoel/branch-name@v1.0.1
- uses: benjlevesque/short-sha@v1.2
id: short-sha
with: { length: 7 }

- uses: actions/checkout@v4
- uses: subosito/flutter-action@v2
with: { channel: stable, cache: true }
- run: |
flutter pub get
flutter build web --no-source-maps --no-native-null-assertions --release

- name: Upload web File
uses: actions/upload-artifact@v4
with:
name: example-app-${{ env.SHA }}-web.zip
path: flutter/example/build/web
1 change: 1 addition & 0 deletions base/lib/src/storage/config/host.dart
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ class DefaultHostProviderV2 extends HostFreezer {
if (_query != null) {
return _query!;
}

_query = await _group.doGroup(
'',
() async => BucketRegionsQuery.create(
Expand Down
28 changes: 7 additions & 21 deletions base/lib/src/util/user_agent/user_agent/app.dart
Original file line number Diff line number Diff line change
@@ -1,28 +1,14 @@
import 'dart:io';

import 'package:qiniu_sdk_base/qiniu_sdk_base.dart';
import 'package:system_info2/system_info2.dart';
import 'package:platform_info/platform_info.dart';

// 这个函数无论如何都不应该抛出异常,即使内部依赖的第三方库不支持目标运行平台
String getDefaultUserAgent() {
final components = <String>['QiniuDart/v$currentVersion'];

try {
platform.when(
iOS: () {
components.add('iOS');
},
orElse: () {
// SystemInfo2 只支持android/linux/macos/windows
components.addAll([
'(${SysInfo.kernelName}; ${SysInfo.kernelVersion}; ${SysInfo.kernelArchitecture})',
'(${SysInfo.operatingSystemName}; ${SysInfo.operatingSystemVersion})',
]);
},
);
} catch (e) {
// 其他任何报错
components.add('UnknownPlatform');
}
final components = <String>[
'QiniuDart/v$currentVersion', // SDK版本
'(${Platform.operatingSystem}; ${Platform.operatingSystemVersion})', // OS 版本
'(${Platform.version})', // Dart版本
];

// 有的操作系统(如Windows)名称可能会返回中文,这里把所有非ascii字符都过滤掉,防止设置User-Agent时产生报错
return String.fromCharCodes(
Expand Down
2 changes: 1 addition & 1 deletion base/lib/src/version.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import 'package:version/version.dart';

final Version currentVersion = Version.parse('0.7.1');
final Version currentVersion = Version.parse('0.7.2');
6 changes: 2 additions & 4 deletions base/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: qiniu_sdk_base
version: 0.7.1
version: 0.7.2
homepage: https://github.com/qiniu/dart-sdk
description: The sdk basic of Qiniu products

Expand All @@ -22,9 +22,7 @@ dependencies:
convert: ^3.1.1
singleflight: ^1.0.2
mutex: ^3.1.0
platform_info: ^4.0.0 # 用于实现平台相关feature的判断逻辑

system_info2: ^4.0.0 # web平台不支持,需要特殊处理
platform_info: ^4.0.0

dev_dependencies:
test: any
Expand Down
4 changes: 4 additions & 0 deletions flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.7.2

* 移除 SystemInfo2 依赖,仅使用标准库 Platform 获取平台信息,修复 Android 平台的兼容性问题

## 0.7.1

* 修复由于 SystemInfo2 引入导致的 Web/iOS/Windows 平台的不兼容问题
Expand Down
3 changes: 1 addition & 2 deletions flutter/example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
/build/

# Web related
lib/generated_plugin_registrant.dart

# Symbolication related
app.*.symbols
Expand All @@ -45,4 +44,4 @@ app.*.map.json
/android/app/profile
/android/app/release

pubspec.lock
pubspec.lock
1 change: 1 addition & 0 deletions flutter/example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:label="qiniu_flutter_sdk_example"
android:name="${applicationName}"
Expand Down
14 changes: 14 additions & 0 deletions flutter/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import 'package:file_picker/file_picker.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:qiniu_flutter_sdk/qiniu_flutter_sdk.dart';
import 'package:qiniu_sdk_base/src/util/user_agent/user_agent.dart';

import 'utils/uint.dart';
import 'widgets/app.dart';
import 'widgets/console.dart';
Expand Down Expand Up @@ -291,6 +293,18 @@ class BaseState extends State<Base> with DisposableState {
padding: EdgeInsets.all(8.0),
child: Console(),
),
Padding(
padding: const EdgeInsets.all(20),
child: Row(
children: [
TextButton(
onPressed: () {
printToConsole('成功获取上传UA: ${getDefaultUserAgent()}');
},
child: Text('获取UA'))
],
),
),
]);
}
}
2 changes: 1 addition & 1 deletion flutter/lib/src/version.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:version/version.dart';

/// 当前SDK版本号
final Version currentVersion = Version.parse('0.7.1');
final Version currentVersion = Version.parse('0.7.2');
4 changes: 2 additions & 2 deletions flutter/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: qiniu_flutter_sdk
description: Qiniu Flutter sdk
version: 0.7.1
version: 0.7.2
homepage: https://github.com/qiniu/dart-sdk/tree/master/flutter

environment:
Expand All @@ -11,7 +11,7 @@ dependencies:
device_info_plus: ^11.3.0
flutter:
sdk: flutter
qiniu_sdk_base: ^0.7.1
qiniu_sdk_base: ^0.7.2
version: ^3.0.2

dev_dependencies:
Expand Down
Loading