Skip to content

Commit d94eb34

Browse files
authored
chore: Android build (#545)
* refactors * new build style for android * global melos * simplify * correct path
1 parent cfc4838 commit d94eb34

File tree

19 files changed

+103
-212
lines changed

19 files changed

+103
-212
lines changed

.github/workflows/analysis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ jobs:
99
- uses: axel-op/dart-package-analyzer@v3
1010
with:
1111
# Required:
12-
githubToken: ${{ secrets.GITHUB_TOKEN }}
12+
githubToken: ${{ secrets.GITHUB_TOKEN }}
13+
relativePath: workmanager/

.github/workflows/examples.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ jobs:
2020

2121
- name: build
2222
run: |
23+
dart pub global activate melos
24+
melos bootstrap
2325
cd example && flutter build apk --debug
2426
2527
example_ios:
@@ -32,4 +34,6 @@ jobs:
3234

3335
- name: build
3436
run: |
37+
dart pub global activate melos
38+
melos bootstrap
3539
cd example && flutter build ios --debug --no-codesign

.github/workflows/format.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ jobs:
4747

4848
- name: publish checks
4949
run: |
50+
dart pub global activate melos
51+
melos bootstrap
5052
cd workmanager
5153
flutter pub get
5254
flutter pub publish -n

ANDROID_SETUP.md

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
# Update build.gradle
2-
3-
Make sure that your kotlin_version to `1.8.0` or greater:
4-
5-
```
6-
buildscript {
7-
ext.kotlin_version = '1.8.0+'
8-
repositories {
9-
google()
10-
mavenCentral()
11-
}
12-
// ...
13-
```
14-
151
# Check your AndroidManifest.xml
162

173
Check if you have the following in your `AndroidManifest.xml` file.

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -176,16 +176,16 @@ Workmanager().registerProcessingTask(
176176
```
177177

178178
### Background App Refresh permission
179+
179180
On iOS user can disable `Background App Refresh` permission anytime, hence background tasks can only run if user has granted the permission.
180-
With `Workmanager.checkBackgroundRefreshPermission` you can check whether background app refresh is enabled. If it is not enabled you might ask
181-
the user to enable it in app settings.
182181

183-
```dart
184-
if (Platform.isIOS) {
185-
final hasPermission = await Workmanager().checkBackgroundRefreshPermission();
186-
if (hasPermission != BackgroundRefreshPermissionState.available){
187-
// Inform the user that background app refresh is disabled
188-
}
182+
Use `permision_handler` to check for the permission:
183+
184+
``` dart
185+
final status = await Permission.backgroundRefresh.status;
186+
if (status != PermissionStatus.granted) {
187+
_showNoPermission(context, status);
188+
return;
189189
}
190190
```
191191

example/android/app/build.gradle

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
plugins {
2+
id "com.android.application"
3+
id "kotlin-android"
4+
id "dev.flutter.flutter-gradle-plugin"
5+
}
6+
17
def localProperties = new Properties()
28
def localPropertiesFile = rootProject.file('local.properties')
39
if (localPropertiesFile.exists()) {
@@ -6,10 +12,6 @@ if (localPropertiesFile.exists()) {
612
}
713
}
814

9-
def flutterRoot = localProperties.getProperty('flutter.sdk')
10-
if (flutterRoot == null) {
11-
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
12-
}
1315

1416
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
1517
if (flutterVersionCode == null) {
@@ -21,10 +23,6 @@ if (flutterVersionName == null) {
2123
flutterVersionName = '1.0'
2224
}
2325

24-
apply plugin: 'com.android.application'
25-
apply plugin: 'kotlin-android'
26-
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
27-
2826
android {
2927
sourceSets {
3028
main.java.srcDirs += 'src/main/kotlin'
@@ -74,7 +72,6 @@ flutter {
7472
}
7573

7674
dependencies {
77-
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
7875
testImplementation 'junit:junit:4.13.2'
7976
androidTestImplementation 'androidx.test:runner:1.2.0'
8077
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

example/android/build.gradle

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,3 @@
1-
buildscript {
2-
ext.kotlin_version = '1.8.10'
3-
repositories {
4-
google()
5-
mavenCentral()
6-
}
7-
8-
dependencies {
9-
classpath 'com.android.tools.build:gradle:8.1.1'
10-
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
11-
}
12-
}
13-
141
plugins {
152
id "com.github.ben-manes.versions" version "0.41.0"
163
}

example/android/settings.gradle

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
1-
include ':app'
1+
pluginManagement {
2+
def flutterSdkPath = {
3+
def properties = new Properties()
4+
file("local.properties").withInputStream { properties.load(it) }
5+
def flutterSdkPath = properties.getProperty("flutter.sdk")
6+
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
7+
return flutterSdkPath
8+
}()
29

3-
def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()
10+
includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")
411

5-
def plugins = new Properties()
6-
def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins')
7-
if (pluginsFile.exists()) {
8-
pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) }
12+
repositories {
13+
google()
14+
mavenCentral()
15+
gradlePluginPortal()
16+
}
917
}
1018

11-
plugins.each { name, path ->
12-
def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile()
13-
include ":$name"
14-
project(":$name").projectDir = pluginDirectory
19+
plugins {
20+
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
21+
id "com.android.application" version "8.1.4" apply false
22+
id "org.jetbrains.kotlin.android" version "1.9.23" apply false
1523
}
24+
25+
include ":app"

example/ios/Podfile.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ PODS:
55
- path_provider_foundation (0.0.1):
66
- Flutter
77
- FlutterMacOS
8+
- permission_handler_apple (9.3.0):
9+
- Flutter
810
- shared_preferences_foundation (0.0.1):
911
- Flutter
1012
- FlutterMacOS
@@ -15,6 +17,7 @@ DEPENDENCIES:
1517
- Flutter (from `Flutter`)
1618
- integration_test (from `.symlinks/plugins/integration_test/ios`)
1719
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`)
20+
- permission_handler_apple (from `.symlinks/plugins/permission_handler_apple/ios`)
1821
- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`)
1922
- workmanager (from `.symlinks/plugins/workmanager/ios`)
2023

@@ -25,6 +28,8 @@ EXTERNAL SOURCES:
2528
:path: ".symlinks/plugins/integration_test/ios"
2629
path_provider_foundation:
2730
:path: ".symlinks/plugins/path_provider_foundation/darwin"
31+
permission_handler_apple:
32+
:path: ".symlinks/plugins/permission_handler_apple/ios"
2833
shared_preferences_foundation:
2934
:path: ".symlinks/plugins/shared_preferences_foundation/darwin"
3035
workmanager:
@@ -34,6 +39,7 @@ SPEC CHECKSUMS:
3439
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
3540
integration_test: 13825b8a9334a850581300559b8839134b124670
3641
path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943
42+
permission_handler_apple: 9878588469a2b0d0fc1e048d9f43605f92e6cec2
3743
shared_preferences_foundation: 5b919d13b803cadd15ed2dc053125c68730e5126
3844
workmanager: 0afdcf5628bbde6924c21af7836fed07b42e30e6
3945

example/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@
190190
9705A1C41CF9048500538489 /* Embed Frameworks */,
191191
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
192192
F4A106E3067F0564F4FF488C /* [CP] Embed Pods Frameworks */,
193+
E672F4E929E3D3E957CCC34B /* [CP] Copy Pods Resources */,
193194
);
194195
buildRules = (
195196
);
@@ -353,6 +354,24 @@
353354
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
354355
showEnvVarsInLog = 0;
355356
};
357+
E672F4E929E3D3E957CCC34B /* [CP] Copy Pods Resources */ = {
358+
isa = PBXShellScriptBuildPhase;
359+
buildActionMask = 2147483647;
360+
files = (
361+
);
362+
inputPaths = (
363+
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh",
364+
"${PODS_CONFIGURATION_BUILD_DIR}/permission_handler_apple/permission_handler_apple_privacy.bundle",
365+
);
366+
name = "[CP] Copy Pods Resources";
367+
outputPaths = (
368+
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/permission_handler_apple_privacy.bundle",
369+
);
370+
runOnlyForDeploymentPostprocessing = 0;
371+
shellPath = /bin/sh;
372+
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh\"\n";
373+
showEnvVarsInLog = 0;
374+
};
356375
F4A106E3067F0564F4FF488C /* [CP] Embed Pods Frameworks */ = {
357376
isa = PBXShellScriptBuildPhase;
358377
buildActionMask = 2147483647;

0 commit comments

Comments
 (0)