Skip to content

Commit e047109

Browse files
committed
[Fixed][Android] forceAlarmManager: true can cause devices to not restart events on boot
1 parent e912b66 commit e047109

File tree

14 files changed

+89
-63
lines changed

14 files changed

+89
-63
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## Unreleased
2+
* [Fixed][Android] using `forceAlarmManager: true` fails to restart fetch events after reboot.
3+
* [Fixed] Android check `wakeLock.isHeld()` before executing `wakeLock.release()`.
4+
15
## 0.5.5 - 2020-03-24
26
* [Fixed] [iOS] bug with `start` plugin after executing `stop`.
37

android/build.gradle

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
group 'com.transistorsoft.flutter.backgroundfetch'
22
version '1.0-SNAPSHOT'
3+
4+
buildscript {
5+
repositories {
6+
google()
7+
jcenter()
8+
}
9+
}
10+
11+
rootProject.allprojects {
12+
repositories {
13+
google()
14+
jcenter()
15+
}
16+
}
17+
318
apply plugin: 'com.android.library'
419

520
def safeExtGet(prop, fallback) {
-40 KB
Binary file not shown.
25.8 KB
Binary file not shown.

example/.flutter-plugins-dependencies

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"_info":"// This is a generated file; do not edit or check into version control.","dependencyGraph":[{"name":"background_fetch","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_macos","shared_preferences_web"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]}]}
1+
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"background_fetch","path":"/Volumes/Glyph2TB/Users/chris/workspace/background-geolocation/flutter/flutter_background_fetch/","dependencies":[]},{"name":"shared_preferences","path":"/Volumes/Glyph2TB/Users/chris/development/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.6+1/","dependencies":[]}],"android":[{"name":"background_fetch","path":"/Volumes/Glyph2TB/Users/chris/workspace/background-geolocation/flutter/flutter_background_fetch/","dependencies":[]},{"name":"shared_preferences","path":"/Volumes/Glyph2TB/Users/chris/development/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.6+1/","dependencies":[]}],"macos":[{"name":"shared_preferences_macos","path":"/Volumes/Glyph2TB/Users/chris/development/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_macos-0.0.1+4/","dependencies":[]}],"linux":[],"windows":[],"web":[{"name":"shared_preferences_web","path":"/Volumes/Glyph2TB/Users/chris/development/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_web-0.1.2+3/","dependencies":[]}]},"dependencyGraph":[{"name":"background_fetch","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_macos","shared_preferences_web"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]}],"date_created":"2020-05-22 12:34:51.298676","version":"1.17.1"}

example/ios/Flutter/flutter_export_environment.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
# This is a generated file; do not edit or check into version control.
33
export "FLUTTER_ROOT=/Volumes/Glyph2TB/Users/chris/development/flutter"
44
export "FLUTTER_APPLICATION_PATH=/Volumes/Glyph2TB/Users/chris/workspace/background-geolocation/flutter/flutter_background_fetch/example"
5-
export "FLUTTER_TARGET=lib/main.dart"
5+
export "FLUTTER_TARGET=/Volumes/Glyph2TB/Users/chris/workspace/background-geolocation/flutter/flutter_background_fetch/example/lib/main.dart"
66
export "FLUTTER_BUILD_DIR=build"
77
export "SYMROOT=${SOURCE_ROOT}/../build/ios"
8+
export "OTHER_LDFLAGS=$(inherited) -framework Flutter"
89
export "FLUTTER_FRAMEWORK_DIR=/Volumes/Glyph2TB/Users/chris/development/flutter/bin/cache/artifacts/engine/ios"
910
export "FLUTTER_BUILD_NAME=1.0.0"
1011
export "FLUTTER_BUILD_NUMBER=1"
12+
export "TRACK_WIDGET_CREATION=true"

example/ios/Podfile

Lines changed: 58 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,56 +4,80 @@
44
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
55
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
66

7+
project 'Runner', {
8+
'Debug' => :debug,
9+
'Profile' => :release,
10+
'Release' => :release,
11+
}
12+
713
def parse_KV_file(file, separator='=')
814
file_abs_path = File.expand_path(file)
915
if !File.exists? file_abs_path
1016
return [];
1117
end
12-
pods_ary = []
18+
generated_key_values = {}
1319
skip_line_start_symbols = ["#", "/"]
14-
File.foreach(file_abs_path) { |line|
15-
next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
16-
plugin = line.split(pattern=separator)
17-
if plugin.length == 2
18-
podname = plugin[0].strip()
19-
path = plugin[1].strip()
20-
podpath = File.expand_path("#{path}", file_abs_path)
21-
pods_ary.push({:name => podname, :path => podpath});
22-
else
23-
puts "Invalid plugin specification: #{line}"
24-
end
25-
}
26-
return pods_ary
20+
File.foreach(file_abs_path) do |line|
21+
next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
22+
plugin = line.split(pattern=separator)
23+
if plugin.length == 2
24+
podname = plugin[0].strip()
25+
path = plugin[1].strip()
26+
podpath = File.expand_path("#{path}", file_abs_path)
27+
generated_key_values[podname] = podpath
28+
else
29+
puts "Invalid plugin specification: #{line}"
30+
end
31+
end
32+
generated_key_values
2733
end
2834

2935
target 'Runner' do
30-
# Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
31-
# referring to absolute paths on developers' machines.
32-
system('rm -rf .symlinks')
33-
system('mkdir -p .symlinks/plugins')
36+
# Flutter Pod
3437

35-
# Flutter Pods
36-
generated_xcode_build_settings = parse_KV_file('./Flutter/Generated.xcconfig')
37-
if generated_xcode_build_settings.empty?
38-
puts "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter packages get is executed first."
39-
end
40-
generated_xcode_build_settings.map { |p|
41-
if p[:name] == 'FLUTTER_FRAMEWORK_DIR'
42-
symlink = File.join('.symlinks', 'flutter')
43-
File.symlink(File.dirname(p[:path]), symlink)
44-
pod 'Flutter', :path => File.join(symlink, File.basename(p[:path]))
38+
copied_flutter_dir = File.join(__dir__, 'Flutter')
39+
copied_framework_path = File.join(copied_flutter_dir, 'Flutter.framework')
40+
copied_podspec_path = File.join(copied_flutter_dir, 'Flutter.podspec')
41+
unless File.exist?(copied_framework_path) && File.exist?(copied_podspec_path)
42+
# Copy Flutter.framework and Flutter.podspec to Flutter/ to have something to link against if the xcode backend script has not run yet.
43+
# That script will copy the correct debug/profile/release version of the framework based on the currently selected Xcode configuration.
44+
# CocoaPods will not embed the framework on pod install (before any build phases can generate) if the dylib does not exist.
45+
46+
generated_xcode_build_settings_path = File.join(copied_flutter_dir, 'Generated.xcconfig')
47+
unless File.exist?(generated_xcode_build_settings_path)
48+
raise "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter pub get is executed first"
4549
end
46-
}
50+
generated_xcode_build_settings = parse_KV_file(generated_xcode_build_settings_path)
51+
cached_framework_dir = generated_xcode_build_settings['FLUTTER_FRAMEWORK_DIR'];
52+
53+
unless File.exist?(copied_framework_path)
54+
FileUtils.cp_r(File.join(cached_framework_dir, 'Flutter.framework'), copied_flutter_dir)
55+
end
56+
unless File.exist?(copied_podspec_path)
57+
FileUtils.cp(File.join(cached_framework_dir, 'Flutter.podspec'), copied_flutter_dir)
58+
end
59+
end
60+
61+
# Keep pod path relative so it can be checked into Podfile.lock.
62+
pod 'Flutter', :path => 'Flutter'
4763

4864
# Plugin Pods
65+
66+
# Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
67+
# referring to absolute paths on developers' machines.
68+
system('rm -rf .symlinks')
69+
system('mkdir -p .symlinks/plugins')
4970
plugin_pods = parse_KV_file('../.flutter-plugins')
50-
plugin_pods.map { |p|
51-
symlink = File.join('.symlinks', 'plugins', p[:name])
52-
File.symlink(p[:path], symlink)
53-
pod p[:name], :path => File.join(symlink, 'ios')
54-
}
71+
plugin_pods.each do |name, path|
72+
symlink = File.join('.symlinks', 'plugins', name)
73+
File.symlink(path, symlink)
74+
pod name, :path => File.join(symlink, 'ios')
75+
end
5576
end
5677

78+
# Prevent Cocoapods from embedding a second Flutter framework and causing an error with the new Xcode build system.
79+
install! 'cocoapods', :disable_input_output_paths => true
80+
5781
post_install do |installer|
5882
installer.pods_project.targets.each do |target|
5983
target.build_configurations.each do |config|

example/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@
99
/* Begin PBXBuildFile section */
1010
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; };
1111
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
12-
3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; };
13-
3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
1412
47E4AB496A489D1080CEBC69 /* libPods-Runner.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CF2D0EC7246967F8526F6403 /* libPods-Runner.a */; };
15-
9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; };
16-
9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
1713
9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 9740EEB21CF90195004384FC /* Debug.xcconfig */; };
1814
978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */; };
1915
97C146F31CF9000F007C117D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 97C146F21CF9000F007C117D /* main.m */; };
@@ -29,8 +25,6 @@
2925
dstPath = "";
3026
dstSubfolderSpec = 10;
3127
files = (
32-
3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */,
33-
9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */,
3428
);
3529
name = "Embed Frameworks";
3630
runOnlyForDeploymentPostprocessing = 0;
@@ -42,14 +36,12 @@
4236
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
4337
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
4438
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
45-
3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = "<group>"; };
4639
73B0E1CD2F9C0CD0B9863BB2 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = "<group>"; };
4740
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
4841
7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
4942
7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
5043
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = "<group>"; };
5144
9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = "<group>"; };
52-
9740EEBA1CF902C7004384FC /* Flutter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Flutter.framework; path = Flutter/Flutter.framework; sourceTree = "<group>"; };
5345
97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; };
5446
97C146F21CF9000F007C117D /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
5547
97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
@@ -64,8 +56,6 @@
6456
isa = PBXFrameworksBuildPhase;
6557
buildActionMask = 2147483647;
6658
files = (
67-
9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */,
68-
3B80C3941E831B6300D905FE /* App.framework in Frameworks */,
6959
47E4AB496A489D1080CEBC69 /* libPods-Runner.a in Frameworks */,
7060
);
7161
runOnlyForDeploymentPostprocessing = 0;
@@ -76,9 +66,7 @@
7666
9740EEB11CF90186004384FC /* Flutter */ = {
7767
isa = PBXGroup;
7868
children = (
79-
3B80C3931E831B6300D905FE /* App.framework */,
8069
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */,
81-
9740EEBA1CF902C7004384FC /* Flutter.framework */,
8270
9740EEB21CF90195004384FC /* Debug.xcconfig */,
8371
7AFA3C8E1D35360C0083082E /* Release.xcconfig */,
8472
9740EEB31CF90195004384FC /* Generated.xcconfig */,
@@ -238,7 +226,7 @@
238226
);
239227
runOnlyForDeploymentPostprocessing = 0;
240228
shellPath = /bin/sh;
241-
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" thin";
229+
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin";
242230
};
243231
9740EEB61CF901F6004384FC /* Run Script */ = {
244232
isa = PBXShellScriptBuildPhase;
@@ -282,12 +270,9 @@
282270
files = (
283271
);
284272
inputPaths = (
285-
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
286-
"${PODS_ROOT}/../.symlinks/flutter/ios/Flutter.framework",
287273
);
288274
name = "[CP] Embed Pods Frameworks";
289275
outputPaths = (
290-
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework",
291276
);
292277
runOnlyForDeploymentPostprocessing = 0;
293278
shellPath = /bin/sh;
@@ -444,6 +429,7 @@
444429
"$(PROJECT_DIR)/Flutter",
445430
);
446431
INFOPLIST_FILE = Runner/Info.plist;
432+
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
447433
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
448434
LIBRARY_SEARCH_PATHS = (
449435
"$(inherited)",
@@ -468,6 +454,7 @@
468454
"$(PROJECT_DIR)/Flutter",
469455
);
470456
INFOPLIST_FILE = Runner/Info.plist;
457+
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
471458
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
472459
LIBRARY_SEARCH_PATHS = (
473460
"$(inherited)",

example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
33
LastUpgradeVersion = "0910"
4-
version = "1.3">
4+
version = "2.0">
55
<BuildAction
66
parallelizeBuildables = "YES"
77
buildImplicitDependencies = "YES">
@@ -48,7 +48,8 @@
4848
ignoresPersistentStateOnLaunch = "NO"
4949
debugDocumentVersioning = "YES"
5050
debugServiceExtension = "internal"
51-
allowLocationSimulation = "YES">
51+
allowLocationSimulation = "YES"
52+
launchAutomaticallySubstyle = "1">
5253
<BuildableProductRunnable
5354
runnableDebuggingMode = "0">
5455
<BuildableReference

example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings

Lines changed: 0 additions & 8 deletions
This file was deleted.

example/lib/main.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ void backgroundFetchHeadlessTask(String taskId) async {
2121
String json = prefs.getString(EVENTS_KEY);
2222
if (json != null) {
2323
events = jsonDecode(json).cast<String>();
24+
2425
}
2526
// Add new event.
2627
events.insert(0, "$taskId@$timestamp [Headless]");
3 Bytes
Binary file not shown.
Binary file not shown.

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: background_fetch
22
description: Periodic callbacks in the background for both iOS and Android. Includes Android Headless implementation.
3-
version: 0.5.5
3+
version: 0.5.6
44
homepage: https://github.com/transistorsoft/flutter_background_fetch
55

66
environment:

0 commit comments

Comments
 (0)