【问题标题】:Flutter compiler error when installing location 2.3.5 package安装位置 2.3.5 包时出现 Flutter 编译器错误
【发布时间】:2019-10-12 18:26:07
【问题描述】:

我安装了:flutter 包 - 位置 2.3.5 https://pub.dev/packages/location

当我尝试运行应用程序时出现编译错误:

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

这是完整的错误

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)

  • 我完成了安装的所有步骤。
  • 我只是用这个位置包创建了一个新项目
  • 我跑:flutter clear
  • 我将 Flutter 更新到了最新版本
  • 我将 android studio 更新到最新版本
  • 我更新了安卓 SDK

没有任何帮助

这是我的 android/build.gradle 文件:

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
}

这是我的 android/gradle.properties 文件:

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

这是我的 android/app/src/build.gradle 文件:

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"
}

这是我的 root/pubspec.yaml 文件:

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

可能是什么问题?

我该如何解决?

【问题讨论】:

  • 这个问题是一个月前的问题了,你还没找到解决办法吗?我也面临同样的问题

标签: android flutter dart androidx


【解决方案1】:

我有一个非常相似的问题。 Flutter 不会停止使用我的一个包的过时版本。 我试过了:

flutter clean
flutter pub cache repair

但颤振仍在使用旧包,我仍然得到编译错误。 当我运行flutter run -v 时,我可以看到版本号 包错误,与 pubspec 不同步。

我终于通过更改频道(再次下载 SDK)让它工作

那就试试吧:

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

这应该可以解决问题。

【讨论】:

    【解决方案2】:

    回复第一个问题报告“找不到符号 import androidx.annotation.NonNull;" 不仅仅是与未找到非空符号相关的任何其他问题。这可能是与您机器中安装的 java 版本有关的问题。当您使用最新的 java 版本时可能会发生这种情况 11或者您正在使用非常旧的依赖项。

    我正在回复一般问题,以添加新的依赖项并在颤振中编译相关问题而不是定位。希望能帮助到你。

    【讨论】:

      猜你喜欢
      • 2014-04-11
      • 2020-05-06
      • 1970-01-01
      • 1970-01-01
      • 2015-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-03
      相关资源
      最近更新 更多