Anil Anil - 22 days ago 18
Android Question

Android Studio Gradle build issue(Unable to run project)

I have just updated my Android Studio to latest version 2.2.2.After that need to update gradle.But after updating both I am unable to run my project which previously run very well.

Below is gradle log error:-


Warning:WARNING: Dependency xpp3:xpp3:1.1.4c is ignored for
productionDebug as it may be conflicting with the internal version
provided by Android.

Warning:WARNING: Dependency xpp3:xpp3:1.1.4c is ignored for
productionRelease as it may be conflicting with the internal version
provided by Android.

Warning:WARNING: Dependency xpp3:xpp3:1.1.4c is ignored for
stagingDebug as it may be conflicting with the internal version
provided by Android.

Warning:WARNING: Dependency xpp3:xpp3:1.1.4c is ignored for
stagingRelease as it may be conflicting with the internal version
provided by Android.

Warning:Conflict with dependency
'com.android.support:recyclerview-v7'. Resolved versions for app
(23.0.0) and test app (21.0.3) differ. See
http://g.co/androidstudio/app-test-app-conflict for details.

Warning:Conflict with dependency 'com.android.support:support-v4'.
Resolved versions for app (25.0.0) and test app (21.0.3) differ. See
http://g.co/androidstudio/app-test-app-conflict for details.

Warning:Conflict with dependency
'com.android.support:recyclerview-v7'. Resolved versions for app
(23.0.0) and test app (21.0.3) differ. See
http://g.co/androidstudio/app-test-app-conflict for details.

Warning:Conflict with dependency 'com.android.support:support-v4'.
Resolved versions for app (25.0.0) and test app (21.0.3) differ. See
http://g.co/androidstudio/app-test-app-conflict for details.

Error:Execution failed for task
':app:prepareStagingDebugAndroidTestDependencies'.Dependency Error. See console for details.


And Heres is My Build.gradle file for reference:-

buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}

dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

repositories {
maven { url 'https://maven.fabric.io/public' }
}

apply plugin: 'com.google.gms.google-services'

android {
useLibrary 'org.apache.http.legacy'
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'LICENSE.txt'
}
compileSdkVersion 23
buildToolsVersion '22.0.1'
defaultConfig {
multiDexEnabled true
applicationId 'com.qa.app'
minSdkVersion 15
targetSdkVersion 21
versionCode 28
versionName '3.5'
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}
dexOptions {
incremental true
javaMaxHeapSize "2048M"
jumboMode = true
}

productFlavors {
production {
minSdkVersion 15
targetSdkVersion 21
versionCode 28
versionName '3.5'
signingConfig signingConfigs.config
}
staging {
minSdkVersion 15
targetSdkVersion 21
versionCode 28
versionName '3.5'
signingConfig signingConfigs.config
}
}

lintOptions {
abortOnError false
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:support-v4:22.2.0'
compile 'com.android.support:cardview-v7:22.1.1'
compile 'com.android.support:recyclerview-v7:22.1.1'
compile 'com.android.support:design:22.2.1'
compile 'com.facebook.rebound:rebound:0.3.7'
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.github.castorflex.smoothprogressbar:library-circular:1.0.2'
compile 'com.facebook.android:facebook-android-sdk:4.+'
compile 'com.facebook.android:notifications:1.0.2'
// compile 'com.google.android.gms:play-services:7.5.0'
compile 'com.google.android.gms:play-services:9.6.1'
compile 'de.keyboardsurfer.android.widget:crouton:1.8.5@aar'
compile 'com.loopj.android:android-async-http:1.4.6'
compile 'de.greenrobot:eventbus:2.4.0'
compile 'com.android.support:support-annotations:25.0.0'
// compile 'com.google.android.gms:play-services:7.5.0'
compile project(':library')
androidTestCompile 'com.android.support:support-annotations:25.0.0'
// androidTestCompile 'com.android.support:support-annotations:22.2.1'
androidTestCompile 'com.android.support.test:runner:0.2'
androidTestCompile 'com.android.support.test:rules:0.2'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.1'
androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.0'
compile project(':rate-me')
compile project(':volleyNew')
compile files('libs/YouTubeAndroidPlayerApi.jar')
compile('com.paypal.sdk:paypal-android-sdk:2.15.0') {
exclude group: 'io.card'
}
compile 'org.igniterealtime.smack:smack-android-extensions:4.1.0'
compile 'org.igniterealtime.smack:smack-experimental:4.1.0'
compile 'org.igniterealtime.smack:smack-tcp:4.1.0'
compile 'org.igniterealtime.smack:smack-im:4.1.0'
compile 'com.loopj.android:android-async-http:1.4.6'
compile 'com.android.support:multidex:1.0.0'
compile 'com.squareup.picasso:picasso:2.4.0'
compile('com.crashlytics.sdk.android:crashlytics:2.6.2@aar') {
transitive = true;
}
}

Answer

In your case the solution should be to add the following line to dependencies:

androidTestCompile 'com.android.support:recyclerview-v7:25.0.0'
androidTestCompile 'com.android.support:support-v4:25.0.0'

Also you should align support libraries versions. In your case all of them should be 25.0.0

Here is similar question: Resolved versions for app (22.0.0) and test app (21.0.3) differ

UPDATE: To make dependency control easier, you can define variable in which you can store current support libraries version.

So, your dependency block should be the following:

def support_version = '25.0.0'

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    // support libraries that should have the same version
    compile "com.android.support:appcompat-v7:$support_version"
    compile "com.android.support:cardview-v7:$support_version"
    compile "com.android.support:support-v4:$support_version"
    compile "com.android.support:recyclerview-v7:$support_version"
    compile "com.android.support:support-annotations:$support_version"
    compile "com.android.support:design:$support_version"

    compile project(':library')
    compile project(':rate-me')
    compile project(':volleyNew')

    compile 'com.facebook.rebound:rebound:0.3.7'
    compile 'com.google.code.gson:gson:2.3.1'
    compile 'com.github.castorflex.smoothprogressbar:library-circular:1.0.2'
    compile 'com.facebook.android:facebook-android-sdk:4.+'
    compile 'com.facebook.android:notifications:1.0.2'
    //    compile 'com.google.android.gms:play-services:7.5.0'
    compile 'com.google.android.gms:play-services:9.6.1'
    compile 'de.keyboardsurfer.android.widget:crouton:1.8.5@aar'
    compile 'com.loopj.android:android-async-http:1.4.6'
    compile 'de.greenrobot:eventbus:2.4.0'
    //    compile 'com.google.android.gms:play-services:7.5.0'
    androidTestCompile 'com.android.support.test:runner:0.2'
    androidTestCompile 'com.android.support.test:rules:0.2'
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.1'
    androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.0'
    compile files('libs/YouTubeAndroidPlayerApi.jar')
    compile('com.paypal.sdk:paypal-android-sdk:2.15.0') {
        exclude group: 'io.card'
    }
    compile 'org.igniterealtime.smack:smack-android-extensions:4.1.0'
    compile 'org.igniterealtime.smack:smack-experimental:4.1.0'
    compile 'org.igniterealtime.smack:smack-tcp:4.1.0'
    compile 'org.igniterealtime.smack:smack-im:4.1.0'
    compile 'com.loopj.android:android-async-http:1.4.6'
    compile 'com.android.support:multidex:1.0.0'
    compile 'com.squareup.picasso:picasso:2.4.0'
    compile('com.crashlytics.sdk.android:crashlytics:2.6.2@aar') {
        transitive = true;
    }

    androidTestCompile "com.android.support:recyclerview-v7:$support_version"
    androidTestCompile "com.android.support:support-v4:$support_version"
    androidTestCompile "com.android.support:support-annotations:$support_version"
}

Read more: GString, Resolving conflicts between main and test APK