Abubakr Hago Abubakr Hago - 9 months ago 65
Android Question

Gradle Conflict in release build variant only

I am having an issue with Gradle building my project:

Using Gradle 2.2.3

compileSdkVersion 23

buildToolsVersion '23.0.2'

targetSdkVersion 23

apply plugin: 'com.android.application'

android {
signingConfigs {
release {
keyAlias '--alias--'
storeFile file('--Location--')
keyPassword '--password--'
storePassword '--password--'
}
}
compileSdkVersion 24
buildToolsVersion '24.0.3'

def versionPropsFile = file('version.properties')
def versionBuild
def versionMajor
def versionMinor
def versionBugFix

/*Setting default value for versionBuild which is the last incremented value stored in the file */
if (versionPropsFile.canRead()) {
def Properties versionProps = new Properties()
versionProps.load(new FileInputStream(versionPropsFile))
versionBuild = versionProps['VERSION_BUILD'].toInteger()
versionMajor = versionProps['MAJOR_REVISION'].toInteger()
versionMinor = versionProps['MINOR_REVISION'].toInteger()
versionBugFix = versionProps['BUG_FIX'].toInteger()
} else {
throw new GradleException("Could not read version.properties!")
}

/*Wrapping inside a method avoids auto incrementing on every gradle task run. Now it runs only when we build apk*/
ext.autoIncrementBuildNumber = {

if (versionPropsFile.canRead()) {
def Properties versionProps = new Properties()
versionProps.load(new FileInputStream(versionPropsFile))
/* increment build version */
versionBuild = versionProps['VERSION_BUILD'].toInteger() + 1
versionProps['VERSION_BUILD'] = versionBuild.toString()
versionProps.store(versionPropsFile.newWriter(), null)
/* END */

/* increment major revision when new UI or new features */
// versionMajor = versionProps['MAJOR_REVISION'].toInteger() + 1
// versionMajor['MAJOR_REVISION'] = versionBuild.toString()
// versionMajor.store(versionPropsFile.newWriter(), null)
/* END */

/* increment minor revision when change to a feature or 1 added feature or collection of bug fixes */
// versionMinor = versionProps['MINOR_REVISION'].toInteger() + 1
// versionMinor['MINOR_REVISION'] = versionBuild.toString()
// versionMinor.store(versionPropsFile.newWriter(), null)
/* END */

/* increment bug fix*/
// versionBugFix = versionProps['BUG_FIX'].toInteger() + 1
// versionBugFix['BUG_FIX'] = versionBuild.toString()
// versionBugFix.store(versionPropsFile.newWriter(), null)
/* END */

} else {
throw new GradleException("Could not read version.properties!")
}
}

defaultConfig {
applicationId 'com.LionOrshid.universitybook'
minSdkVersion 16
targetSdkVersion 24
multiDexEnabled true
versionCode 1
versionName versionMajor + "." + versionMinor + "." + versionBugFix + "." + versionBuild
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
// minifyEnabled true
shrinkResources true
zipAlignEnabled true
// multiDexEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}

gradle.taskGraph.whenReady { taskGraph ->
if (taskGraph.hasTask(assembleDebug)) { /* when run debug task */
autoIncrementBuildNumber()
}
}

configurations.all {
resolutionStrategy {
// force 'groupId:artifactId:desiredVersion'
failOnVersionConflict()
}
}

configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
// all*.exclude group: 'com.android.support', module: 'support-v7'
all*.exclude group: 'com.android.support', module: 'support-annotations'
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.0.0'
compile 'com.android.support:design:24.0.0'
compile 'com.android.support:cardview-v7:24.0.0'
compile 'com.android.support:recyclerview-v7:24.0.0'
// compile 'com.google.firebase:firebase-messaging:10.0.1'
// compile 'com.google.firebase:firebase-core:9.8.0'
// compile 'com.facebook.android:facebook-android-sdk:4.15.0' has cardView v7 library in it's build.gradle file
compile 'com.github.clans:fab:1.6.4'
// compile 'com.wdullaer:materialdatetimepicker:3.1.3' has design library in it's build.gradle file
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.google.android.gms:play-services-auth:10.0.1'
compile 'com.google.android.gms:play-services-drive:10.0.1'
compile 'com.parse:parse-android:1.13.1'
compile 'com.google.android.gms:play-services-ads:10.0.1'
compile 'com.google.android.gms:play-services:10.0.1'
// compile 'com.nononsenseapps:filepicker:3.1.0' has appcompat v7 in it's build.gradle file
// compile 'com.parse:parseinterceptors:0.0.2' has parse 1.12.0 in it's build.gradle file
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'


I did try all in that is in the code:


-I have added the dependencies one by one and the conflict is in android support library v4 and v7.

-I excluded them from cardView and appcompat with no luck

-all*.exclude group: 'com.android.support', module: 'support-v7' doesn't do the trick

-and failOnVersionConflict() is throwing: {Error:A conflict was found between the following modules:
- com.android.support:cardview-v7:25.1.0
- com.android.support:cardview-v7:23.4.0}
-after commenting cardView this: {Error:A conflict was found between the following modules:
- com.android.support:support-v4:25.1.0
- com.android.support:support-v4:23.4.0
- com.android.support:support-v4:24.2.1
- com.android.support:support-v4:24.0.0}
- without failOnVersionConflict() in debug build variant there are no errors but in release mode i get: {Error:Execution failed for task ':app:transformClassesWithJarMergingForRelease'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v7/appcompat/R$anim.class}

Answer Source

I think your are using two version of the same library, you should maybe let the latest version and remove the oldest one.

failOnVersionConflict() "In case of conflict, Gradle by default uses the newest of conflicting versions."

EDIT:

build.gradle of your third party lib "com.nononsenseapps:filepicker:3.1.0" use a version of support library older than your version of support library

Change your third party lib or use the exact same version of the support library define in the buil.gradle.

Try this to use the 23.4.0 instead of 25.1.0

compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:cardview-v7:23.4.0'
compile 'com.android.support:recyclerview-v7:23.4.0'

Hope this helps.

Sorry for my english .