Android依赖项'com.android.support:support-v4'对于编译(26.1.0)和运行时(27.1.1)类路径错误具有不同的版本

时间:2018-12-08 16:33:49

标签: android firebase gradle flutter admob

我在应用程序中添加了Firebase admob,并且在应用程序文件夹中添加了google sevices文件。它显示此错误。请帮助我解决此问题。平台不流畅。

运行:

flutter run
Using hardware rendering with device SM G615F. If you get graphics 
artifacts, consider enabling software rendering with "--enable-software- 
rendering".
Launching lib/main.dart on SM G615F in debug mode...
Initializing gradle...                                       3.0s
Resolving dependencies...                                   10.2s
Gradle task 'assembleDebug'...
registerResGeneratingTask is deprecated, use 
registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use 
registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use 
registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use 
registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use 
registerGeneratedResFolders(FileCollection)

   FAILURE: Build failed with an exception.

   * What went wrong:
   Execution failed for task ':app:preDebugBuild'.
   > Android dependency 'com.android.support:support-v4' has different version 
   for the compile (26.1.0) and runtime (27.1.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 8s
   Gradle task 'assembleDebug'... Done                          8.9s
   Gradle task assembleDebug failed with exit code 1

build.gradle:

buildscript {
 repositories {
    google()
    jcenter()
  }

dependencies {
    classpath 'com.android.tools.build:gradle:3.2.1'
    classpath 'com.google.gms:google-services:4.2.0' // google-services 
plugin

   }
  }

 allprojects {
  repositories {
      google()
     jcenter()
     maven {
         url "https://maven.google.com"
     }
   }
   }

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

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

pubspec.yaml:

 name: avengersquiz
 description: A new Flutter project.

# 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             #comment these 2 in case issues

 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
 share: ^0.5.3
 flutter_webview_plugin: ^0.3.0+2
 launch_review: ^1.0.1
 material_design_icons_flutter: ^2.7.94
 shared_preferences: ^0.4.3
 dio: ^1.0.6
 flutter_downloader: ^1.0.6
 path_provider: ^0.4.1
 simple_permissions: ^0.1.9                #oreo fix
 http: ^0.12.0
 fluttertoast: ^2.1.3
 flutter_staggered_grid_view: ^0.2.4       #any
 flutter_local_notifications: ^0.4.2
 url_launcher: any                          
 flutter_custom_tabs: ^0.4.0
 vibrate: ^0.0.4
 splashscreen: ^1.1.0
 nima: ^1.0.0
 flare_flutter: ^1.0.0
 firebase_admob: ^0.7.0   #0.5.2
 firebase_analytics: ^1.0.6





dev_dependencies:
flutter_test:
   sdk: flutter

build.gradle / app:

 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"

def keystorePropertiesFile = rootProject.file("key.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))


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.package"
    minSdkVersion 16         //21
    targetSdkVersion 28
    versionCode 1
    versionName "1.1"
    testInstrumentationRunner 
 "android.support.test.runner.AndroidJUnitRunner"
  }

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


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.release
      }
  }
 }

 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'

在将其添加到我的项目/成绩之后:

subprojects {
project.configurations.all {
    resolutionStrategy.eachDependency { details ->
        if (details.requested.group == 'com.android.support'
                && !details.requested.name.contains('multidex') ) {
            details.useVersion "26.1.0"
        }
      }
     }
     }

我收到此错误:

Execution failed for task ':app:preDebugBuild'.
> Android dependency 'android.arch.lifecycle:runtime' has different version 
for the compile (1.0.0) and runtime (1.1.0) 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 27s
Gradle task 'assembleDebug'... Done                         28.3s
Gradle task assembleDebug failed with exit code 1

2 个答案:

答案 0 :(得分:2)

在build.gradle中-结束-之后-

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

添加-

 subprojects {
    project.configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'com.android.support'
                    && !details.requested.name.contains('multidex') ) {
                details.useVersion "26.1.0"
            }
        }
    }
}

答案 1 :(得分:0)

当我包含flutter_downloader时,我发现了相同的错误,将其删除,该错误消失了。

  

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