Background location tracking

This commit is contained in:
2026-03-09 22:33:35 +08:00
parent 1e1c7d9552
commit ccc1c62262
10 changed files with 371 additions and 127 deletions
+13 -1
View File
@@ -1,6 +1,12 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />
<!-- Required on Android 13+ to post notifications. Without this the system
will automatically block notifications and the user cannot enable them
@@ -57,6 +63,12 @@
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="tasq_custom_sound_channel_3" />
<!-- Override the plugin's service to add foregroundServiceType (required Android 14+) -->
<service
android:name="id.flutter.flutter_background_service.BackgroundService"
android:foregroundServiceType="location"
tools:replace="android:foregroundServiceType" />
</application>
<!-- Required to query activities that can process text, see:
https://developer.android.com/training/package-visibility and
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@mipmap/ic_launcher"
android:gravity="center" />
+41 -23
View File
@@ -2,6 +2,7 @@ import com.android.build.gradle.LibraryExtension
import org.gradle.api.tasks.Delete
import com.android.build.gradle.BaseExtension
import org.gradle.api.JavaVersion
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
allprojects {
repositories {
@@ -20,6 +21,46 @@ subprojects {
val newSubprojectBuildDir: Directory = newBuildDir.dir(project.name)
project.layout.buildDirectory.value(newSubprojectBuildDir)
}
// Force compileSdk, Java 17, and Kotlin JVM target 17 on all library subprojects.
// Must use the `subprojects {}` block (not `subprojects.forEach`) so the
// afterEvaluate callback is registered *before* evaluationDependsOn triggers.
subprojects {
afterEvaluate {
plugins.withId("com.android.library") {
val androidExt = extensions.findByName("android") as? BaseExtension
if (androidExt != null) {
try {
androidExt.compileOptions.sourceCompatibility = JavaVersion.VERSION_17
androidExt.compileOptions.targetCompatibility = JavaVersion.VERSION_17
} catch (_: Throwable) {}
try {
val sdkNum = androidExt.compileSdkVersion?.removePrefix("android-")?.toIntOrNull() ?: 0
if (sdkNum < 36) {
androidExt.compileSdkVersion("android-36")
}
} catch (_: Throwable) {}
}
// Align Kotlin JVM target with Java 17 to avoid mismatch errors
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
compilerOptions.jvmTarget.set(JvmTarget.JVM_17)
}
}
plugins.withId("com.android.application") {
val androidExt = extensions.findByName("android") as? BaseExtension
if (androidExt != null) {
try {
androidExt.compileOptions.sourceCompatibility = JavaVersion.VERSION_17
androidExt.compileOptions.targetCompatibility = JavaVersion.VERSION_17
} catch (_: Throwable) {}
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
compilerOptions.jvmTarget.set(JvmTarget.JVM_17)
}
}
}
}
subprojects {
project.evaluationDependsOn(":app")
}
@@ -46,29 +87,6 @@ subprojects.forEach { project ->
}
// Ensure Kotlin JVM target matches Java compatibility to avoid mismatches in third-party modules.
// Align Java compile options to Java 17 for Android modules so Kotlin JVM target mismatch is avoided.
subprojects.forEach { project ->
project.plugins.withId("com.android.library") {
val androidExt = project.extensions.findByName("android") as? BaseExtension
if (androidExt != null) {
try {
androidExt.compileOptions.sourceCompatibility = JavaVersion.VERSION_17
androidExt.compileOptions.targetCompatibility = JavaVersion.VERSION_17
} catch (_: Throwable) {}
}
}
project.plugins.withId("com.android.application") {
val androidExt = project.extensions.findByName("android") as? BaseExtension
if (androidExt != null) {
try {
androidExt.compileOptions.sourceCompatibility = JavaVersion.VERSION_17
androidExt.compileOptions.targetCompatibility = JavaVersion.VERSION_17
} catch (_: Throwable) {}
}
}
}
tasks.register<Delete>("clean") {
delete(rootProject.layout.buildDirectory)
}