transistorsoft / flutter_background_geolocation

Sophisticated, battery-conscious background-geolocation & geofencing with motion-detection
https://www.transistorsoft.com/shop/products/flutter-background-geolocation
Other
645 stars 239 forks source link

Flutter App crashes When Adding flutter_backgroun_geolaction to pubspec.yaml file #1090

Closed MatthewGerges closed 1 year ago

MatthewGerges commented 1 year ago

Your Environment

The following line prevents the package from being accidentally published to

pub.dev using flutter pub publish. This is preferred for private packages.

publish_to: 'none' # Remove this line if you wish to publish to pub.dev

The following defines the version and build number for your application.

A version number is three numbers separated by dots, like 1.2.43

followed by an optional build number separated by a +.

Both the version and the builder number may be overridden in flutter

build by specifying --build-name and --build-number, respectively.

In Android, build-name is used as versionName while build-number used as versionCode.

Read more about Android versioning at https://developer.android.com/studio/publish/versioning

In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion.

Read more about iOS versioning at

https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html

In Windows, build-name is used as the major, minor, and patch parts

of the product and file versions while build-number is used as the build suffix.

version: 1.0.0+1

environment: sdk: '>=2.18.2 <3.0.0'

Dependencies specify other packages that your package needs in order to work.

To automatically upgrade your package dependencies to the latest versions

consider running flutter pub upgrade --major-versions. Alternatively,

dependencies can be manually updated by changing the version numbers below to

the latest version available on pub.dev. To see which dependencies have newer

versions available, run flutter pub outdated.

dependencies: flutter: sdk: flutter

firebase_core: ^2.10.0 rflutter_alert: ^2.0.4

The following adds the Cupertino Icons font to your application.

Use with the CupertinoIcons class for iOS style icons.

cupertino_icons: ^1.0.2 google_fonts: firebase_auth: ^4.4.2 cloud_firestore: ^4.5.3 persistent_bottom_nav_bar: any dropdown_button2: ^2.1.0 mongo_dart: ^0.8.2 chips_choice_null_safety: ^2.0.6 font_awesome_flutter: ^10.4.0 google_sign_in: ^6.1.0 flutter_polyline_points: ^1.0.0 google_maps_flutter: ^2.2.6 location: ^4.4.0 flutter_svg: ^2.0.5 geolocator: ^9.0.2 google_maps_webservice: ^0.0.19 url_launcher: ^6.1.11 http: ^0.13.6

flutter_geofence: ^0.4.4

flutter_local_notifications: ^14.1.1 background_fetch: ^1.1.6 flutter_background_geolocation: ^4.8.1 shared_preferences: ^2.1.2

dev_dependencies: flutter_test: sdk: flutter

The "flutter_lints" package below contains a set of recommended lints to

encourage good coding practices. The lint set provided by the package is

activated in the analysis_options.yaml file located at the root of your

package. See that file for information about deactivating specific lint

rules and activating additional ones.

flutter_lints: ^2.0.0

For information on the generic Dart part of this file, see the

following page: https://dart.dev/tools/pub/pubspec

The following section is specific to Flutter packages.

flutter:

The following line ensures that the Material Icons font is

included with your application, so that you can use the icons in

the material Icons class.

uses-material-design: true

To add assets to your application, add an assets section, like this:

assets:

- images/a_dot_burr.jpeg

- images/a_dot_ham.jpeg

An image asset can refer to one or more resolution-specific "variants", see

https://flutter.dev/assets-and-images/#resolution-aware

For details regarding adding assets from package dependencies, see

https://flutter.dev/assets-and-images/#from-packages

To add custom fonts to your application, add a fonts section here,

in this "flutter" section. Each entry in this list should have a

"family" key with the font family name, and a "fonts" key with a

list giving the asset and other descriptors for the font. For

example:

fonts:

- family: Schyler

fonts:

- asset: fonts/Schyler-Regular.ttf

- asset: fonts/Schyler-Italic.ttf

style: italic

- family: Trajan Pro

fonts:

- asset: fonts/TrajanPro.ttf

- asset: fonts/TrajanPro_Bold.ttf

weight: 700

#

For details regarding fonts from package dependencies,

see https://flutter.dev/custom-fonts/#from-packages

This is how my android/build.gradle looks:

buildscript { ext.kotlin_version = '1.6.10' ext { compileSdkVersion = 33 // or latest targetSdkVersion = 31 // or latest appCompatVersion = "1.4.2" // or latest } repositories { google() mavenCentral() }

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

}

allprojects { repositories { google() mavenCentral() maven { // [required] background_fetch url "${project(':background_fetch').projectDir}/libs" } } }

rootProject.buildDir = '../build' subprojects { project.buildDir = "${rootProject.buildDir}/${project.name}" } subprojects { project.evaluationDependsOn(':app') }

task clean(type: Delete) { delete rootProject.buildDir }

This is how my android/app/build.gradle file looks:

def localProperties = new Properties() def localPropertiesFile = rootProject.file('local.properties') if (localPropertiesFile.exists()) { localPropertiesFile.withReader('UTF-8') { reader -> localProperties.load(reader) } }

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) { flutterVersionCode = '1' }

def flutterVersionName = localProperties.getProperty('flutter.versionName') 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 { // compileSdkVersion flutter.compileSdkVersion compileSdkVersion rootProject.ext.compileSdkVersion ndkVersion flutter.ndkVersion

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
    jvmTarget = '1.8'
}

sourceSets {
    main.java.srcDirs += 'src/main/kotlin'
}

defaultConfig {
    // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
    applicationId "com.example.flutter_login_6"
    // You can update the following values to match your application needs.
    // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
    minSdkVersion 21
    // targetSdkVersion flutter.targetSdkVersion
    targetSdkVersion rootProject.ext.targetSdkVersion
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
}

buildTypes {
    release {
        // TODO: Add your own signing config for the release build.
        // Signing with the debug keys for now, so `flutter run --release` works.
        signingConfig signingConfigs.debug
    }
}

}

flutter { source '../..' }

dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation "com.squareup.okhttp3:okhttp:4.9.3" }

This is how my AndroidManifest.xml file looks:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
package="com.example.meetamor">

<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:minSdkVersion="34" android:name="android.permission.USE_EXACT_ALARM" />

<application tools:replace="android:label"
android:label="meetamor" android:name="${applicationName}" android:icon="@mipmap/ic_launcher"> <activity android:name=".MainActivity" android:exported="true" android:launchMode="singleTop" android:theme="@style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize">

        <meta-data
          android:name="io.flutter.embedding.android.NormalTheme"
          android:resource="@style/NormalTheme"
          />
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
    <!-- Don't delete the meta-data below.
         This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
    <meta-data
        android:name="flutterEmbedding"
        android:value="2" />
         <meta-data android:name="com.google.android.geo.API_KEY" android:value="AIzaSyCBuVa-xL_maCbcc7DSFV-TL_hLo1nldpk" />
    <receiver android:name="com.intivoto.flutter_geofence.GeofenceBroadcastReceiver"
        android:enabled="true" android:exported="true"/>
    <service android:name="com.intivoto.flutter_geofence.FlutterGeofencePlugin"
        android:permission="android.permission.BIND_JOB_SERVICE" android:exported="true"/>
</application>


## Expected Behavior
My app should be able to start. All I have done so far was add the flutter_background_geolocation inside my pubspec.yaml dependencies and I got the crash log below. My goal with flutter_background_geolocation is to track a user's coordinates every time they move (even when the app is killed or in the background) and write it to MongoDB. If this bug is simple to solve, please kindly direct me to the next resource where I could learn how to do so

## Actual Behavior
Instead of the app being able to start (please note that all I did was add the dependency in my pubspec.yaml file, I did not even import it in any of my dart files), it crashes. Also if I remove the flutter_background_geolocation from my .yaml file, the app works fine with no problems. I tried searching up this error in multiple places online but none of the solutions I tried work. If you look at the code from my files above, you'll notice that I tried following the Android setup (https://github.com/transistorsoft/flutter_background_fetch/blob/master/help/INSTALL-ANDROID.md) but I ended up getting the same error. Even Stack Overflow (https://stackoverflow.com/questions/76305745/flutter-could-not-find-any-matches-for-com-transistorsofttsbackgroundfetch) gave me the solution to add a maven URL to my android/build.gradle which is what I did as you can see above. I am confused, I am just trying to run the app on my Windows machine without publishing it to the app store, web, or google play store. Am I supposed to buy a license key for this to work or can I test it without a license key?

## Steps to Reproduce
You can simply perform a flutter pub add flutter_background_geolocation in a new flutter project and try running the app

## Context
<!--- What were you trying to do? -->

## Debug logs

Launching lib\main.dart on sdk gphone x86 in debug mode... main.dart:1 Parameter format not correct -

FAILURE: Build failed with an exception.

BUILD FAILED in 10s Exception: Gradle task assembleDebug failed with exit code 1 Exited (sigterm)



As a side note, would this plugin work with flutter web? Because I can't imagine background locations would work with a web app. Thanks!
christocracy commented 1 year ago

This issue “Could not find any matches for com.transistorsoft:tslocationmanager:+” has been posted dozens of times. Go to the readme and carefully follow the setup instructions.

there’s far more involved to installing this plug-in than simply adding to pubspec.yaml

christocracy commented 1 year ago

Duplicate #947