1

I installed the: flutter package - location 2.3.5 https://pub.dev/packages/location

And when I try to run the application I get a compilation error:

* What went wrong:
Execution failed for task ':location:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

And here is the full error

Launching lib\main.dart on Android SDK built for x86 in debug mode...

C:\flutter\.pub-cache\hosted\pub.dartlang.org\location-2.3.5\android\src\main\java\com\lyokone\location\LocationPlugin.java:15: error: cannot find symbol
import androidx.annotation.MainThread;

                          ^
  symbol:   class MainThread
  location: package androidx.annotation

C:\flutter\.pub-cache\hosted\pub.dartlang.org\location-2.3.5\android\src\main\java\com\lyokone\location\LocationPlugin.java:16: error: cannot find symbol
import androidx.annotation.NonNull;
                          ^
  symbol:   class NonNull

  location: package androidx.annotation
C:\flutter\.pub-cache\hosted\pub.dartlang.org\location-2.3.5\android\src\main\java\com\lyokone\location\LocationPlugin.java:17: error: cannot find symbol
import androidx.annotation.Nullable;

                          ^
  symbol:   class Nullable
  location: package androidx.annotation

C:\flutter\.pub-cache\hosted\pub.dartlang.org\location-2.3.5\android\src\main\java\com\lyokone\location\LocationPlugin.java:18: error: package androidx.core.app does not exist
import androidx.core.app.ActivityCompat;
                        ^

C:\flutter\.pub-cache\hosted\pub.dartlang.org\location-2.3.5\android\src\main\java\com\lyokone\location\LocationPlugin.java:19: error: package androidx.core.content does not exist
import androidx.core.content.ContextCompat;
                            ^

C:\flutter\.pub-cache\hosted\pub.dartlang.org\location-2.3.5\android\src\main\java\com\lyokone\location\LocationPlugin.java:357: error: cannot find symbol
        this.locationPermissionState = ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION);
                                       ^
  symbol:   variable ActivityCompat

  location: class LocationPlugin

C:\flutter\.pub-cache\hosted\pub.dartlang.org\location-2.3.5\android\src\main\java\com\lyokone\location\LocationPlugin.java:362: error: cannot find symbol
        ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION},

        ^
  symbol:   variable ActivityCompat
  location: class LocationPlugin

C:\flutter\.pub-cache\hosted\pub.dartlang.org\location-2.3.5\android\src\main\java\com\lyokone\location\LocationPlugin.java:367: error: cannot find symbol
        return ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.ACCESS_FINE_LOCATION);
               ^
  symbol:   variable ActivityCompat
  location: class LocationPlugin

C:\flutter\.pub-cache\hosted\pub.dartlang.org\location-2.3.5\android\src\main\java\com\lyokone\location\LocationPlugin.java:405: error: cannot find symbol
                public void onFailure(@NonNull Exception e) {
                                       ^
  symbol: class NonNull
C:\flutter\.pub-cache\hosted\pub.dartlang.org\location-2.3.5\android\src\main\java\com\lyokone\location\LocationPlugin.java:438: error: cannot find symbol

                    public void onFailure(@NonNull Exception e) {
                                           ^
  symbol: class NonNull
10 errors



FAILURE: Build failed with an exception.


* What went wrong:
Execution failed for task ':location:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.


* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org


BUILD FAILED in 2s

*******************************************************************************************

The Gradle failure may have been because of AndroidX incompatibilities in this Flutter app.
See for more information on the problem and how to fix it.
*******************************************************************************************

Gradle task assembleDebug failed with exit code 1

Exited (sigterm)

  • I did all the steps of the installation.
  • I created a new project just with this location package
  • I run: flutter clear
  • I updated flutter to the latest version
  • I updated android studio to the latest version
  • I updated android SDK

Nothing helped

Here is my android/build.gradle file:

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.0'
        classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.50'        
        classpath 'com.google.gms:google-services:4.2.0'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

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

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

Here is my android/gradle.properties file:

org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true

Here is my android/app/src/build.gradle file:

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 from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 28

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.flutter_course"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    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
        }
    }
    configurations.all {
        resolutionStrategy.force 'com.android.support:support-compat:27.1.1'
        resolutionStrategy.force 'com.android.support:appcompat-v7:27.1.1'
        resolutionStrategy.force 'com.android.support:support-v4:27.1.1'
    }
}

flutter {
    source '../..'
}

dependencies {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
    implementation "com.android.support:support-v4:27.1.1"
}

Here is my root/pubspec.yaml file:

name: flutter_course
description: A new Flutter project.

dependencies:
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.0
  scoped_model: ^1.0.1
  http: ^0.12.0+2
  shared_preferences: ^0.5.2+1
  rxdart: ^0.22.0
  map_view: ^0.0.14
  location: ^2.3.5

dev_dependencies:
  flutter_test:
    sdk: flutter


# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec

# The following section is specific to Flutter.
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:
    - assets/food.jpg
    - assets/background.jpg
  #  - images/a_dot_ham.jpeg

  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.io/assets-and-images/#resolution-aware.

  # For details regarding adding assets from package dependencies, see
  # https://flutter.io/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: Oswald
      fonts:
        - asset: assets/Oswald-Bold.ttf
          weight: 700
  #       - 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.io/custom-fonts/#from-packages

What can be the problem?

And how can I fix it?

Dushy
  • 375
  • 3
  • 13
  • well this question was a month ago, haven't you found the solution yet? i'm facing the same issue – evals Jul 23 '19 at 09:55

2 Answers2

0

replying to first issue reported "cannot find symbol import androidx.annotation.NonNull;" not just it any other issue related to non null symbol not found. It could be a issue related to java version that is installed in your machine. It might occur when you are using latest java version such 11 or you are are using very old dependency.

I am replying issue general to adding new dependency and compile related issue in flutter not to location. Hope it helps.

0

I had a very Similar Issue. Flutter would just not stop using an outdated version of one of my packages. I tried:

flutter clean
flutter pub cache repair

But flutter was still using the old package and I still get compile errors. When I was running flutter run -v I could see the version number of the the package was wrong and not in sync with the pubspec.

I finally got it working by changing the channel (which downloads the SDK again)

So try:

flutter channel beta
flutter upgrade
flutter channel stable
flutter run -v 

That should fix the problem.

Ride Sun
  • 2,145
  • 3
  • 18
  • 41