Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android dependency 'com.android.support:support-v4' has different version

I just upgraded to Dart 2 and the latest version of Flutter and now I can't get my app to build. I've looked around on the Internet but still don't understand why this is happening.

The error I get is:

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.0) classpath. You should manually set the same version via DependencyResolution

Project build.grade:

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'com.google.gms:google-services:3.2.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
}

pubspec.yaml:

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^0.1.2
  google_sign_in: ^3.0.2
  firebase_auth: ^0.5.5
  firebase_database: ^0.4.5
  firebase_core: ^0.2.3

  flutter_blue: ^0.3.3

dev_dependencies:
  flutter_test:
    sdk: flutter


# 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

I have updated my packages to the latest versions and I'm running the latest version of Dart and Flutter.

I don't really understand what is happening that is causing this error.

Can anybody help?

like image 706
jgv115 Avatar asked Apr 20 '18 04:04

jgv115


4 Answers

Add the following to the Android Project level build.gradle file's 'subprojects' section (as also mentioned in the link provided by Günter Zöchbauer in the comment):

   subprojects {

    project.evaluationDependsOn(':app')
//[PART TO ADD START]
    project.configurations.all {

        resolutionStrategy.eachDependency { details ->

            if (details.requested.group == 'com.android.support'
                    && !details.requested.name.contains('multidex') ) {
                details.useVersion "27.1.0"
            }
        }
    }
//[PART TO ADD END]
    }
like image 54
Kartik Avatar answered Oct 04 '22 13:10

Kartik


I was having the same problem while I was making a "QR scanner App" in Flutter, I have just changed the "minSdkVersion 21" in demoapp->android->app->build.gradle->minSdkVersion, it worked perfectly. this has happened because some dependency in flutter doesn't support minSdk below 21.

defaultConfig {
    // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
    applicationId "com.example"
    minSdkVersion 21
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
like image 36
Gaurang Goda Avatar answered Oct 04 '22 12:10

Gaurang Goda


Open your project level build.gradle file & add the following snippet.

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

After adding this, your project level build.gradle file will look like this:

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.1'


        // NOTE: Do not place your application dependencies here; they belong
       // in the individual module build.gradle files
    }
}

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

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

Solution provided by Günter Zöchbauer. link. It works for me. Hope it helps.

like image 33
Riajur Rahman Avatar answered Oct 04 '22 13:10

Riajur Rahman


try this Open your project in the android studio and wait for it to sync then,

Update build.gradile to this add google() in repositories under build scripts so it looks like this

repositories {
        jcenter()
        google()
    }
update classpath
classpath 'com.android.tools.build:gradle:3.1.1'
Update distributionUrl in gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

implementation "com.android.support:support-v4:27.1.1"  // In case your targetting. 
like image 26
Raj008 Avatar answered Oct 04 '22 13:10

Raj008