Android依赖项'com.google.android.gms:play-services-tasks'对于编译(16.0.1)和运行时(17.0.0)类路径具有不同的版本

时间:2019-08-23 19:30:12

标签: flutter

我尝试调试应用程序,但出现此错误

任务':app:preDebugBuild'的执行失败。

  

Android依赖项'com.google.android.gms:play-services-tasks'对于编译(16.0.1)和运行时(17.0.0)类路径具有不同的版本。您应该通过DependencyResolution手动设置相同的版本

\ android \ build.gradle

buildscript {
    ext.kotlin_version = '1.2.51'
    repositories {
        google()
        jcenter()
    }

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

allprojects {
    repositories {
        google()
        jcenter()
        maven {
            url "https://maven.google.com" // Google's Maven repository
        }
    }
}

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

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

\ android \ app \ 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 plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

   def keystoreProperties = new Properties()
   def keystorePropertiesFile = rootProject.file('key.properties')
   if (keystorePropertiesFile.exists()) {
       keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
   }

   android {
    compileSdkVersion 28
    buildToolsVersion "27.0.3"

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

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

       signingConfigs {
       release {
           keyAlias keystoreProperties['keyAlias']
           keyPassword keystoreProperties['keyPassword']
           storeFile file(keystoreProperties['storeFile'])
           storePassword keystoreProperties['storePassword']
       }
   }
   buildTypes {
       release {
           signingConfig signingConfigs.release
       }
   }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    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'
}

\ plugins \ google_maps_flutter \ android \ build.gradle

def PLUGIN = "google_maps_flutter";
def ANDROIDX_WARNING = "flutterPluginsAndroidXWarning";
gradle.buildFinished { buildResult ->
    if (buildResult.failure && !rootProject.ext.has(ANDROIDX_WARNING)) {
        println '         *********************************************************'
        println 'WARNING: This version of ' + PLUGIN + ' will break your Android build if it or its dependencies aren\'t compatible with AndroidX.'
        println '         
        println '         This warning prints for all Android build failures. The real root cause of the error may be unrelated.'
        println '         *********************************************************'
        rootProject.ext.set(ANDROIDX_WARNING, true);
    }
}

group 'io.flutter.plugins.googlemaps'
version '1.0-SNAPSHOT'

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0'
    }
}

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

apply plugin: 'com.android.library'

android {
    compileSdkVersion 28

    defaultConfig {
        minSdkVersion 16
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    lintOptions {
        disable 'InvalidPackage'
    }

    dependencies {
        implementation 'com.google.android.gms:play-services-maps:17.0.0'
    }
}

有人可以帮助我吗?谢谢

2 个答案:

答案 0 :(得分:2)

只需添加以下依赖项应用returnVal = null

build.gradle

答案 1 :(得分:1)

我通过将其添加到应用程序构建gradle中来解决此问题

implementation 'com.google.android.gms:play-services-tasks:17.0.0'

但它也跟随另一个错误,并通过使用此方法解决了

implementation 'com.google.android.gms:play-services-base:17.0.0'
implementation 'com.google.android.gms:play-services-basement:17.0.0'

也许还有另一种方法可以将所有播放服务版本设置为17.0.0