1

After opening an old project with the latest updated android studio, I am having this error for the build.gradle file. What should I change?

Having error for the appcompact-v7 dependency: All com.android.support libraries must use the exact same version specification. Found version 26.1.0, 19.1.0.

apply plugin: 'com.android.application'

android {
compileSdkVersion 19
buildToolsVersion '27.0.3'

defaultConfig {
    applicationId "X"
    minSdkVersion 15
    targetSdkVersion 19
    versionCode 7
    versionName "name"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:19.1.0'
    compile 'com.google.android.gms:play-services-ads:12.0.1'
}
BOOnZ
  • 828
  • 2
  • 15
  • 35

3 Answers3

1

Do this :-

apply plugin: 'com.android.application'

android {
compileSdkVersion 27
buildToolsVersion '27.0.3'

defaultConfig {
    applicationId "X"
    minSdkVersion 15
    targetSdkVersion 27
    versionCode 7
    versionName "name"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:27.0.3'
    compile 'com.google.android.gms:play-services-ads:12.0.1'
}
Abhinav Gupta
  • 2,225
  • 1
  • 14
  • 30
  • I have set my targetSdkVesion to 19 as it is using the old camera api.. So limit users who are on older android versions to see this. In that case it will give me an error on using support libraries higher than the targetSdkVersion. Is there a workaround? – BOOnZ Apr 04 '18 at 09:27
  • @user776914 no it will not give error it will show you warning that’s it – Abhinav Gupta Apr 04 '18 at 09:29
0

Like the error tell you just change your version of the library just like this :

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:27.1.0' //19.1.0 to 27.1.0
    compile 'com.google.android.gms:play-services-ads:12.0.1'
}
Itoun
  • 3,713
  • 5
  • 27
  • 47
  • In that case it will give me an error on using support libraries higher than the targetSdkVersion. Is there a workaround? – BOOnZ Apr 04 '18 at 09:28
0
compile 'com.android.support:appcompat-v7:27.1.0'
compile 'com.google.android.gms:play-services-ads:12.0.1'

NOTE

If you get

Error:Failed to resolve: com.android.support:appcompat-v7:27.1.0'

Then use google() in your PROJECT LEVEL build.gradle section.

buildscript {

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


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

Finally

Module Level build.gradle will be

apply plugin: 'com.android.application'

android {
compileSdkVersion 27
buildToolsVersion '27.0.3'

defaultConfig {
    applicationId "X"
    minSdkVersion 15
    targetSdkVersion 27
    versionCode 7
    versionName "name"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:27.1.0'
    compile 'com.google.android.gms:play-services-ads:12.0.1'
}

Then Clean-Rebuild-Run

IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
  • I have set my targetSdkVesion to 19 as it is using the old camera api.. So limit users who are on older android versions to see this. In that case it will give me an error on using support libraries higher than the targetSdkVersion. Is there a workaround? – BOOnZ Apr 04 '18 at 09:28
  • It will throw warning just. – IntelliJ Amiya Apr 04 '18 at 09:31
  • By same version, do you mean 19.1.0 for the appcompact dependency? – BOOnZ Apr 04 '18 at 09:40
  • @user776914 No no.. Its `27` – IntelliJ Amiya Apr 04 '18 at 09:41
  • I have changed it, now during compiling it has thrown a lot of android style/TextAppearance.Material not found. – BOOnZ Apr 04 '18 at 09:46
  • @user776914 ok. Show exact error. by the by..have a look https://stackoverflow.com/questions/32075498/error-retrieving-parent-for-item-no-resource-found-that-matches-the-given-name – IntelliJ Amiya Apr 04 '18 at 09:47
  • 1
    Thanks for the link! Previously I assumed that the compileSdkVersion has to be kept the same as the targetSdkVersion. Changing it to 27 but retaining the targetSdkVersion at 19 (which I need it to filter) works! – BOOnZ Apr 04 '18 at 10:00
  • @user776914 glad to hear.Move ahead! – IntelliJ Amiya Apr 04 '18 at 10:04