【问题标题】:Execution failed for task ':app:preDebugBuild'.in Flutter任务':app:preDebugBuild'.in Flutter执行失败
【发布时间】:2019-04-08 23:45:33
【问题描述】:

Android 依赖 'com.android.support:support-media-compat' 对于编译 (26.1.0) 和运行时 (27.1.1) 类路径有不同的版本。您应该通过 DependencyResolution 手动设置相同的版本

我在我的 Flutter 应用中添加了插件列表

dependencies:
  flutter:
    sdk: flutter
  connectivity:
  rxdart:
  validate: ^1.7.0
  image_picker: ^0.4.10
  shared_preferences: "^0.4.2"
  firebase_auth: ^0.6.2+1
  google_sign_in:

Dart 和 Flutter 版本:Dart 2.1.0-dev.3.1.flutter-760a9690c2

这是我的安卓应用 - 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.")
}

apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 27

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.standardappstructure"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        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'
}
apply plugin: 'com.google.gms.google-services'

Destribution Gradle 版本:

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

项目级别:gradle

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.0'
        classpath 'com.google.gms:google-services:4.0.1'
    }
}

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
}

如果我将 gradle 类路径更改为

 classpath 'com.android.tools.build:gradle:3.2.1'

它给我看

Android 依赖 'android.arch.lifecycle:runtime' 对于编译 (1.0.0) 和运行时 (1.1.0) 类路径有不同的版本。您应该通过 DependencyResolution 手动设置相同的版本

【问题讨论】:

  • 你的buildToolsVersion 是什么?在 app gradle 中找不到它的声明。
  • 默认情况下我没有添加 buildToolsVersion 但我尝试使用 buildToolsVersion '27.0.3' 和 '27.1.1' 但仍然出现同样的错误。

标签: android dart flutter flutter-dependencies


【解决方案1】:

您可以通过在 android>build.gradle 中更改以下代码来解决此错误

如果您的项目使用 kotlin 配置,那么

   ext.kotlin_version = '1.2.71'

     replace with new version

   ext.kotlin_version = '1.3.0'

dependencies {classpath 'com.android.tools.build:gradle:3.2.1'}
                    replace with new version
dependencies {classpath 'com.android.tools.build:gradle:3.3.0'}

如果你的例外是,你可能会遇到障碍

出了什么问题: 任务“:app:preDebugBuild”执行失败。 Android 依赖 'androidx.exifinterface:exifinterface' 对于编译 (1.0.0-rc01) 和运行时 (1.0.0) 类路径有不同的版本。您应该通过 DependencyResolution 手动设置相同的版本

【讨论】:

【解决方案2】:

我将 implementation("com.android.support:support-v4:latest_version_number") 添加到我的 build.gradle 中,它工作正常。希望这会有所帮助。

【讨论】:

  • 我使用了 implementation("com.android.support:support-v4:28.0.0") 并且成功了,谢谢 ;-)
【解决方案3】:
cloud_firestore: ^0.8.2+3
firebase_auth: ^0.6.5
image_picker: 0.4.0

这对我有用

【讨论】:

    猜你喜欢
    • 2019-08-15
    • 1970-01-01
    • 2022-07-29
    • 2021-02-06
    • 2021-09-25
    • 2023-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多