Skip to content

Commit

Permalink
android: retry to load .so library if load failed. fix #4.
Browse files Browse the repository at this point in the history
  • Loading branch information
boyan01 committed Nov 20, 2020
1 parent 451c2c4 commit b87ae5a
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 55 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.8.0

* android: retry to load .so library if load failed. fix #4.

## 0.7.0
* android : decrease android gradle plugin to 3.5.0
* ios : fix wrong clock usage. https://github.com/boyan01/system_clock/issues/3
Expand Down
4 changes: 2 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ void main() {
}

DateTime _lastBootDatetime() {
final bootSinceEpoch = DateTime.now().microsecondsSinceEpoch - SystemClock.uptime().inMicroseconds;
final bootSinceEpoch = DateTime.now().microsecondsSinceEpoch - SystemClock.elapsedRealtime().inMicroseconds;
return DateTime.fromMicrosecondsSinceEpoch(bootSinceEpoch);
}

Expand Down Expand Up @@ -48,11 +48,11 @@ class _MyAppState extends State<MyApp> with SingleTickerProviderStateMixin {
children: [
ListTile(
title: Text("uptime: ${SystemClock.uptime()}"),
subtitle: Text("last boot: ${_lastBootDatetime()}"),
onTap: () {},
),
ListTile(
title: Text("elapsedRealtime: ${SystemClock.elapsedRealtime()}"),
subtitle: Text("last boot: ${_lastBootDatetime()}"),
onTap: () {},
),
],
Expand Down
78 changes: 39 additions & 39 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,58 @@ packages:
dependency: transitive
description:
name: async
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.5.0-nullsafety"
version: "2.5.0-nullsafety.1"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.0-nullsafety"
version: "2.1.0-nullsafety.1"
characters:
dependency: transitive
description:
name: characters
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.0-nullsafety.2"
version: "1.1.0-nullsafety.3"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.2.0-nullsafety"
version: "1.2.0-nullsafety.1"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.0-nullsafety"
version: "1.1.0-nullsafety.1"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.15.0-nullsafety.2"
version: "1.15.0-nullsafety.3"
cupertino_icons:
dependency: "direct main"
description:
name: cupertino_icons
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.1.3"
fake_async:
dependency: transitive
description:
name: fake_async
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.0-nullsafety"
version: "1.2.0-nullsafety.1"
flutter:
dependency: "direct main"
description: flutter
Expand All @@ -71,23 +71,23 @@ packages:
dependency: transitive
description:
name: matcher
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.12.10-nullsafety"
version: "0.12.10-nullsafety.1"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.3.0-nullsafety.2"
version: "1.3.0-nullsafety.3"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.8.0-nullsafety"
version: "1.8.0-nullsafety.1"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -97,65 +97,65 @@ packages:
dependency: transitive
description:
name: source_span
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.8.0-nullsafety"
version: "1.8.0-nullsafety.2"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.10.0-nullsafety"
version: "1.10.0-nullsafety.1"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.0-nullsafety"
version: "2.1.0-nullsafety.1"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.0-nullsafety"
version: "1.1.0-nullsafety.1"
system_clock:
dependency: "direct main"
description:
path: ".."
relative: true
source: path
version: "0.7.0"
version: "0.8.0"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.2.0-nullsafety"
version: "1.2.0-nullsafety.1"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.2.19-nullsafety"
version: "0.2.19-nullsafety.2"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.3.0-nullsafety.2"
version: "1.3.0-nullsafety.3"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.0-nullsafety.2"
version: "2.1.0-nullsafety.3"
sdks:
dart: ">=2.10.0-0.0.dev <2.10.0"
dart: ">=2.10.0-110 <2.11.0"
flutter: ">=1.20.0 <2.0.0"
25 changes: 12 additions & 13 deletions lib/system_clock.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:ffi';
import 'dart:io';
import 'dart:math';

typedef _ClockFunction = int Function();

Expand All @@ -12,19 +13,17 @@ DynamicLibrary _openLibrary() {
try {
return DynamicLibrary.open("libsystemclock.so");
} catch (_) {
if (Platform.isAndroid) {
// On some (especially old) Android devices, we somehow can't dlopen
// libraries shipped with the apk. We need to find the full path of the
// library (/data/data/<id>/lib/xxx.so) and open that one.
// For details, see https://github.com/simolus3/moor/issues/420
final appIdAsBytes = File('/proc/self/cmdline').readAsBytesSync();

// app id ends with the first \0 character in here.
final endOfAppId = max(appIdAsBytes.indexOf(0), 0);
final appId = String.fromCharCodes(appIdAsBytes.sublist(0, endOfAppId));

return DynamicLibrary.open('/data/data/$appId/lib/libsystemclock.so');
}
// On some (especially old) Android devices, we somehow can't dlopen
// libraries shipped with the apk. We need to find the full path of the
// library (/data/data/<id>/lib/xxx.so) and open that one.
// For details, see https://github.com/simolus3/moor/issues/420
final appIdAsBytes = File('/proc/self/cmdline').readAsBytesSync();

// app id ends with the first \0 character in here.
final endOfAppId = max(appIdAsBytes.indexOf(0), 0);
final appId = String.fromCharCodes(appIdAsBytes.sublist(0, endOfAppId));

return DynamicLibrary.open('/data/data/$appId/lib/libsystemclock.so');
}
}
if (Platform.isWindows) {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: system_clock
description: Flutter timekeeping facilities. Powered by ffi
version: 0.7.0
version: 0.8.0
author: yangbinyhhbn@gmail.com
homepage: https://github.com/boyan01/system_clock

Expand Down

0 comments on commit b87ae5a

Please sign in to comment.