Taher
Taher

Reputation: 1245

Android studio pulls wrong version of sdk to compile project

I want to compile my project using sdk version 22 however android studio uses version 23, so it gives some error. I use Android studio 1.3 and I don't want to use sdk 23(I have some deprecated methods which I don't want to replace them at this time). This is my gradle file:

apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
    applicationId "ir.mhealth.healthnotation"
    minSdkVersion 16
    targetSdkVersion 22
    versionCode 2
    versionName "1.0.0.1"
}
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:22.2.0'
compile 'com.android.support:recyclerview-v7:22.2.0'
compile 'com.jjoe64:graphview:4.+'
compile 'com.afollestad:material-dialogs:0.7.+'
compile 'com.google.android.gms:play-services-analytics:7.8.0'
}

When I run gradle dependency report I get this response:

    ------------------------------------------------------------
Project :app
------------------------------------------------------------

_debugAndroidTestApk - ## Internal use, do not manually configure ## No dependencies

_debugAndroidTestCompile - ## Internal use, do not manually configure ## No dependencies

_debugApk - ## Internal use, do not manually configure ##
+--- com.android.support:appcompat-v7:22.2.0 -> 23.0.0
|    \--- com.android.support:support-v4:23.0.0
|         \--- com.android.support:support-annotations:23.0.0
+--- com.android.support:recyclerview-v7:22.2.0 -> 23.0.0
|    +--- com.android.support:support-annotations:23.0.0
|    \--- com.android.support:support-v4:23.0.0 (*)
+--- com.jjoe64:graphview:4.+ -> 4.0.1
|    \--- com.android.support:support-v4:21.0.3 -> 23.0.0 (*)
+--- com.afollestad:material-dialogs:0.7.+ -> 0.7.9.1
|    +--- com.android.support:support-v4:23.0.0 (*)
|    +--- com.android.support:appcompat-v7:23.0.0 (*)
|    +--- com.android.support:recyclerview-v7:23.0.0 (*)
|    \--- com.android.support:support-annotations:23.0.0
\--- com.google.android.gms:play-services-analytics:7.8.0
     \--- com.google.android.gms:play-services-base:7.8.0
          \--- com.android.support:support-v4:22.2.0 -> 23.0.0 (*)

debugCompile - ## Internal use, do not manually configure ##
+--- com.android.support:appcompat-v7:22.2.0 -> 23.0.0
|    \--- com.android.support:support-v4:23.0.0
|         \--- com.android.support:support-annotations:23.0.0
+--- com.android.support:recyclerview-v7:22.2.0 -> 23.0.0
|    +--- com.android.support:support-annotations:23.0.0
|    \--- com.android.support:support-v4:23.0.0 (*)
+--- com.jjoe64:graphview:4.+ -> 4.0.1
|    \--- com.android.support:support-v4:21.0.3 -> 23.0.0 (*)
+--- com.afollestad:material-dialogs:0.7.+ -> 0.7.9.1
|    +--- com.android.support:support-v4:23.0.0 (*)
|    +--- com.android.support:appcompat-v7:23.0.0 (*)
|    +--- com.android.support:recyclerview-v7:23.0.0 (*)
|    \--- com.android.support:support-annotations:23.0.0
\--- com.google.android.gms:play-services-analytics:7.8.0
     \--- com.google.android.gms:play-services-base:7.8.0
          \--- com.android.support:support-v4:22.2.0 -> 23.0.0 (*)

-debugUnitTestApk - ## Internal use, do not manually configure ## 
no dependencies

-debugUnitTestCompile - ## Internal use, do not manually configure ## 
no dependencies

_releaApk - ## Internal use, do not manually configure ##
+--- com.android.support:appcompat-v7:22.2.0 -> 23.0.0
|    \--- com.android.support:support-v4:23.0.0
|         \--- com.android.support:support-annotations:23.0.0
+--- com.android.support:recyclerview-v7:22.2.0 -> 23.0.0
|    +--- com.android.support:support-annotations:23.0.0
|    \--- com.android.support:support-v4:23.0.0 (*)
+--- com.jjoe64:graphview:4.+ -> 4.0.1
|    \--- com.android.support:support-v4:21.0.3 -> 23.0.0 (*)
+--- com.afollestad:material-dialogs:0.7.+ -> 0.7.9.1
|    +--- com.android.support:support-v4:23.0.0 (*)
|    +--- com.android.support:appcompat-v7:23.0.0 (*)
|    +--- com.android.support:recyclerview-v7:23.0.0 (*)
|    \--- com.android.support:support-annotations:23.0.0
\--- com.google.android.gms:play-services-analytics:7.8.0
     \--- com.google.android.gms:play-services-base:7.8.0
          \--- com.android.support:support-v4:22.2.0 -> 23.0.0 (*)

-releaseCompile - ## Internal use, do not manually configure ##
+--- com.android.support:appcompat-v7:22.2.0 -> 23.0.0
|    \--- com.android.support:support-v4:23.0.0
|         \--- com.android.support:support-annotations:23.0.0
+--- com.android.support:recyclerview-v7:22.2.0 -> 23.0.0
|    +--- com.android.support:support-annotations:23.0.0
|    \--- com.android.support:support-v4:23.0.0 (*)
+--- com.jjoe64:graphview:4.+ -> 4.0.1
|    \--- com.android.support:support-v4:21.0.3 -> 23.0.0 (*)
+--- com.afollestad:material-dialogs:0.7.+ -> 0.7.9.1
|    +--- com.android.support:support-v4:23.0.0 (*)
|    +--- com.android.support:appcompat-v7:23.0.0 (*)
|    +--- com.android.support:recyclerview-v7:23.0.0 (*)
|    \--- com.android.support:support-annotations:23.0.0
\--- com.google.android.gms:play-services-analytics:7.8.0
     \--- com.google.android.gms:play-services-base:7.8.0
          \--- com.android.support:support-v4:22.2.0 -> 23.0.0 (*)


.
.
.


wearApp - Link to a wear app to embed for object 'main'.
No dependencies

BUILD SUCCESSFUL

Why it tries to replace sdk 22 with 23??? How can I fix it?

(I should mention that I didn't have any problems until I decided to update my android studio to version 1.4. After updating, it downloaded sdk 23 and while I hadn't change my gradle file, android studio tried to compile project with sdk 23 as you can see. I uninstall android studio and install old version but the problem didn't solve. I knew version 1.4 use sdk 23 for new project, but my project was not new. Also I use old version of android studio now and it didn't solve my problem)

Upvotes: 0

Views: 1962

Answers (1)

Gabriele Mariotti
Gabriele Mariotti

Reputation: 363825

You are using some libraries that have dependency with the support libraries v23.

For example:

com.afollestad:material-dialogs:0.7.+ -> 0.7.9.1
|    +--- com.android.support:support-v4:23.0.0 (*)
|    +--- com.android.support:appcompat-v7:23.0.0 (*)
|    +--- com.android.support:recyclerview-v7:23.0.0 (*)

Using the support libraries v23, you have to compile with api23, while you are using api22.
It is the reason of your issue.

You can:

  • compile with API23 changing your build.gradle using compileSdkVersion 23

  • exclude the support libraries v23 in the other libs.

You can use somenthing like this.

  compile('com.afollestad:material-dialogs:0.7.+') {
          exclude group: 'com.android.support'
        }

Pay attention. It can cause problems with this library!

Upvotes: 2

Related Questions