Skip to content
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

chore: Android build #545

Merged
merged 5 commits into from
Apr 9, 2024
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
3 changes: 2 additions & 1 deletion .github/workflows/analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ jobs:
- uses: axel-op/dart-package-analyzer@v3
with:
# Required:
githubToken: ${{ secrets.GITHUB_TOKEN }}
githubToken: ${{ secrets.GITHUB_TOKEN }}
relativePath: workmanager/
4 changes: 4 additions & 0 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ jobs:

- name: build
run: |
dart pub global activate melos
melos bootstrap
cd example && flutter build apk --debug

example_ios:
Expand All @@ -32,4 +34,6 @@ jobs:

- name: build
run: |
dart pub global activate melos
melos bootstrap
cd example && flutter build ios --debug --no-codesign
2 changes: 2 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ jobs:

- name: publish checks
run: |
dart pub global activate melos
melos bootstrap
cd workmanager
flutter pub get
flutter pub publish -n
Expand Down
14 changes: 0 additions & 14 deletions ANDROID_SETUP.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
# Update build.gradle

Make sure that your kotlin_version to `1.8.0` or greater:

```
buildscript {
ext.kotlin_version = '1.8.0+'
repositories {
google()
mavenCentral()
}
// ...
```

# Check your AndroidManifest.xml

Check if you have the following in your `AndroidManifest.xml` file.
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,16 @@ Workmanager().registerProcessingTask(
```

### Background App Refresh permission

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

```dart
if (Platform.isIOS) {
final hasPermission = await Workmanager().checkBackgroundRefreshPermission();
if (hasPermission != BackgroundRefreshPermissionState.available){
// Inform the user that background app refresh is disabled
}
Use `permision_handler` to check for the permission:

``` dart
final status = await Permission.backgroundRefresh.status;
if (status != PermissionStatus.granted) {
_showNoPermission(context, status);
return;
}
```

Expand Down
15 changes: 6 additions & 9 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
plugins {
id "com.android.application"
id "kotlin-android"
id "dev.flutter.flutter-gradle-plugin"
}

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
Expand All @@ -6,10 +12,6 @@ if (localPropertiesFile.exists()) {
}
}

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

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
Expand All @@ -21,10 +23,6 @@ if (flutterVersionName == null) {
flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand Down Expand Up @@ -74,7 +72,6 @@ flutter {
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
Expand Down
13 changes: 0 additions & 13 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
buildscript {
ext.kotlin_version = '1.8.10'
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:8.1.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

plugins {
id "com.github.ben-manes.versions" version "0.41.0"
}
Expand Down
30 changes: 20 additions & 10 deletions example/android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
include ':app'
pluginManagement {
def flutterSdkPath = {
def properties = new Properties()
file("local.properties").withInputStream { properties.load(it) }
def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
return flutterSdkPath
}()

def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()
includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")

def plugins = new Properties()
def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins')
if (pluginsFile.exists()) {
pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) }
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}

plugins.each { name, path ->
def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile()
include ":$name"
project(":$name").projectDir = pluginDirectory
plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "8.1.4" apply false
id "org.jetbrains.kotlin.android" version "1.9.23" apply false
}

include ":app"
6 changes: 6 additions & 0 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ PODS:
- path_provider_foundation (0.0.1):
- Flutter
- FlutterMacOS
- permission_handler_apple (9.3.0):
- Flutter
- shared_preferences_foundation (0.0.1):
- Flutter
- FlutterMacOS
Expand All @@ -15,6 +17,7 @@ DEPENDENCIES:
- Flutter (from `Flutter`)
- integration_test (from `.symlinks/plugins/integration_test/ios`)
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`)
- permission_handler_apple (from `.symlinks/plugins/permission_handler_apple/ios`)
- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`)
- workmanager (from `.symlinks/plugins/workmanager/ios`)

Expand All @@ -25,6 +28,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/integration_test/ios"
path_provider_foundation:
:path: ".symlinks/plugins/path_provider_foundation/darwin"
permission_handler_apple:
:path: ".symlinks/plugins/permission_handler_apple/ios"
shared_preferences_foundation:
:path: ".symlinks/plugins/shared_preferences_foundation/darwin"
workmanager:
Expand All @@ -34,6 +39,7 @@ SPEC CHECKSUMS:
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
integration_test: 13825b8a9334a850581300559b8839134b124670
path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943
permission_handler_apple: 9878588469a2b0d0fc1e048d9f43605f92e6cec2
shared_preferences_foundation: 5b919d13b803cadd15ed2dc053125c68730e5126
workmanager: 0afdcf5628bbde6924c21af7836fed07b42e30e6

Expand Down
19 changes: 19 additions & 0 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
9705A1C41CF9048500538489 /* Embed Frameworks */,
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
F4A106E3067F0564F4FF488C /* [CP] Embed Pods Frameworks */,
E672F4E929E3D3E957CCC34B /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand Down Expand Up @@ -353,6 +354,24 @@
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";
showEnvVarsInLog = 0;
};
E672F4E929E3D3E957CCC34B /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh",
"${PODS_CONFIGURATION_BUILD_DIR}/permission_handler_apple/permission_handler_apple_privacy.bundle",
);
name = "[CP] Copy Pods Resources";
outputPaths = (
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/permission_handler_apple_privacy.bundle",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh\"\n";
showEnvVarsInLog = 0;
};
F4A106E3067F0564F4FF488C /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down
12 changes: 5 additions & 7 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'dart:math';

import 'package:flutter/material.dart';
import 'package:path_provider/path_provider.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:workmanager/workmanager.dart';

Expand Down Expand Up @@ -124,11 +125,9 @@ class _MyAppState extends State<MyApp> {
child: Text("Start the Flutter background service"),
onPressed: () async {
if (Platform.isIOS) {
final hasPermission = await Workmanager()
.checkBackgroundRefreshPermission();
if (hasPermission !=
BackgroundRefreshPermissionState.available) {
_showNoPermission(context, hasPermission);
final status = await Permission.backgroundRefresh.status;
if (status != PermissionStatus.granted) {
_showNoPermission(context, status);
return;
}
}
Expand Down Expand Up @@ -352,8 +351,7 @@ class _MyAppState extends State<MyApp> {
);
}

void _showNoPermission(
BuildContext context, BackgroundRefreshPermissionState hasPermission) {
void _showNoPermission(BuildContext context, PermissionStatus hasPermission) {
showDialog(
context: context,
builder: (BuildContext context) {
Expand Down
5 changes: 3 additions & 2 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ environment:
sdk: ">=2.18.0 <4.0.0"

dependencies:
path_provider: ^2.0.11
shared_preferences: ^2.2.1
path_provider:
shared_preferences:
permission_handler:
flutter:
sdk: flutter
workmanager:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ name: workmanager_workspace
environment:
sdk: '>=2.17.0 <3.0.0'
dev_dependencies:
melos: ^3.1.0
melos: ^5.3.0
19 changes: 2 additions & 17 deletions workmanager/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
group 'dev.fluttercommunity.workmanager'
version '1.0-SNAPSHOT'

buildscript {
ext.kotlin_version = '1.8.10'
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:8.0.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

rootProject.allprojects {
repositories {
mavenCentral()
Expand All @@ -34,7 +21,7 @@ android {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
compileSdk 33
compileSdk 34
minSdkVersion 19
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -55,9 +42,7 @@ android {
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

def work_version = "2.8.1"
def work_version = "2.9.0"
implementation "androidx.work:work-runtime:$work_version"
implementation "androidx.concurrent:concurrent-futures:1.1.0"

Expand Down
26 changes: 25 additions & 1 deletion workmanager/android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1,25 @@
rootProject.name = 'workmanager'
pluginManagement {
def flutterSdkPath = {
def properties = new Properties()
file("local.properties").withInputStream { properties.load(it) }
def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
return flutterSdkPath
}()

includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")

repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}

plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "8.1.4" apply false
id "org.jetbrains.kotlin.android" version "1.9.23" apply false
}

include ":app"
Loading
Loading