flutter使用flutter_local_notifications和位置包出现错误“ Android依赖关系'androidx.core:core'具有不同的版本”

Are*_*tar 5 android gradle flutter

美好的一天,我尝试制作一个带有android和ios通知的简易天气应用程序,为此,我们使用基础flutter应用程序和库flutter_local_notifications: ^0.5.1+2以及location: ^2.0.0,但同时使用它们会出现错误:

Launching lib\main.dart on SM A520F in debug mode...
Initializing gradle...
Resolving dependencies...
Gradle task 'assembleDebug'...

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:preDebugBuild'.
> Android dependency 'androidx.core:core' has different version for the compile (1.0.0-rc01) and runtime (1.0.1) classpath. You should manually set the same version via DependencyResolution

* 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
Finished with error: Gradle task assembleDebug failed with exit code 1
Run Code Online (Sandbox Code Playgroud)

颤振医生输出:

C:\src\flutter\bin\flutter.bat doctor --verbose
[?] Flutter (Channel stable, v1.0.0, on Microsoft Windows [Version 10.0.17134.590], locale ru-RU)
    • Flutter version 1.0.0 at C:\src\flutter
    • Framework revision 5391447fae (3 months ago), 2018-11-29 19:41:26 -0800
    • Engine revision 7375a0f414
    • Dart version 2.1.0 (build 2.1.0-dev.9.4 f9ebf21297)

[?] Android toolchain - develop for Android devices (Android SDK 28.0.3)
    • Android SDK at C:\Users\zande\AppData\Local\Android\sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)
    • All Android licenses accepted.

[?] Android Studio (version 3.3)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 32.0.1
    • Dart plugin version 182.5124
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)

[!] VS Code (version 1.31.0)
    • VS Code at C:\Users\zande\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension not installed; install from
      https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[?] Connected device (1 available)
    • SM A520F • 5200291746c1b485 • android-arm64 • Android 8.0.0 (API 26) (emulator)

! Doctor found issues in 1 category.
Process finished with exit code 0
Run Code Online (Sandbox Code Playgroud)

我的pubspec.yaml:

name: flutter_app
description: A new Flutter application.

# 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.
# Read more about versioning at semver.org.
version: 1.0.0+1

environment:
  sdk: ">=2.0.0-dev.68.0 <3.0.0"

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.2
  flutter_local_notifications: ^0.5.1+2
  location: ^2.0.0

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:
  #  - 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.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: 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.io/custom-fonts/#from-packages
Run Code Online (Sandbox Code Playgroud)

我的main.dart:

Launching lib\main.dart on SM A520F in debug mode...
Initializing gradle...
Resolving dependencies...
Gradle task 'assembleDebug'...

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:preDebugBuild'.
> Android dependency 'androidx.core:core' has different version for the compile (1.0.0-rc01) and runtime (1.0.1) classpath. You should manually set the same version via DependencyResolution

* 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
Finished with error: Gradle task assembleDebug failed with exit code 1
Run Code Online (Sandbox Code Playgroud)

我的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.flutterapp"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "android.support.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
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

Run Code Online (Sandbox Code Playgroud)

我尝试使用其他地理位置库,但经常出现类似以下错误

D8: Program type already present: android.support.v4.os.ResultReceiver$MyResultReceiver
Run Code Online (Sandbox Code Playgroud)

用于geo_location_finder

要么 WARNING: This version of device_info will break your Android build if it or its dependencies aren't compatible with AndroidX.

用于地理定位器

我应该做些什么来制作我的天气应用程序?

小智 16

别开玩笑,我最近遇到了同样的问题(并且我对AndroidX的各种依赖项(带有-rc01版本结尾)的抱怨越来越多),并且强制解决策略的各种解决方案都行不通。

我通过升级android / build.gradle文件中的gradle依赖关系来解决它:classpath'com.android.tools.build:gradle:3.3.1'(我以前使用的是3.2.1版)


Mr *_*ial 9

我遇到了来自androidX兼容性的相同问题。错误消息看起来像:

android dependency 'androidx.core:core' has different version for the compile (1.0.0) and runtime (1.0.1) classpath
Run Code Online (Sandbox Code Playgroud)

我将其修复如下(如果相同,请忽略它):

  1. android / gradle / wrapper / gradle-wrapper.properties中,更改以distributionUrl开头的行,如下所示:

distributionUrl = https://services.gradle.org/distributions/gradle-4.10.2-all.zip

  1. android / build.gradle中

依赖项{classpath'com.android.tools.build:gradle:3.3.0'}

  • buildscript {下(如果包含kotlin)

ext.kotlin_version ='1.3.0'

  1. android / gradle.properties中,追加

android.enableJetifier = true

android.useAndroidX = true

  1. android / app / build.gradle中

在android {下,确保compileSdkVersion和targetSdkVersion至少为28。

...

testInstrumentationRunner“ androidx.test.runner.AndroidJUnitRunner”

根据依赖{

androidTestImplementation'androidx.test:runner:1.1.1'

androidTestImplementation'androidx.test.espresso:espresso-core:3.1.1'

实现'com.android.support:multidex:1.0.3'

在defaultConfig {

multiDexEnabled是

希望这会有所帮助!!!

  • 这非常有帮助。正如 Prakhar 在另一个答案中所说,解决方案的关键可能是 `com.android.tools.build:gradle:3.3.1` 版本。 (2认同)