Error: java.util.zip.ZipException: duplicate entry - android-studio

I'm trying to add a library to my project, right now my current build.gradle is:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
repositories {
mavenCentral()
}
defaultConfig {
applicationId "com.example.guycohen.cheaters"
minSdkVersion 11
targetSdkVersion 21
versionCode 1
versionName "1.0"
// Enabling multidex support.
multiDexEnabled true
}
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:21.0.3'
compile 'com.facebook.android:facebook-android-sdk:4.0.0'
compile 'com.android.support:multidex:1.0.0'
compile 'com.parse.bolts:bolts-android:1.+'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.whl.handytabbar:library:1.0.4'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.daimajia.easing:library:1.0.1#aar'
compile 'com.daimajia.androidanimations:library:1.1.3#aar'
}
When I add a new library
compile 'com.github.navasmdc:PhoneTutorial:1.+#aar'
I get this error:
Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
> java.util.zip.ZipException: duplicate entry: android/support/v4/print/PrintHelperKitkat$2$1.class
I've tried to fix this issue by adding
configurations { all*.exclude group: 'com.android.support', module: 'support-v4' }
I couldn't find a duplicate class in my project.
I'm sure whether if I could delete the duplicate entry it would run perfectly, but I'm not sure how I'd find it.

compile 'com.android.support:support-v4:22.1.1'
compile ('com.android.support:appcompat-v7:22.1.1') {
exclude module: 'support-v4'
}
compile ('com.facebook.android:facebook-android-sdk:4.2.0') {
exclude module: 'support-v4'
}
compile ('com.github.navasmdc:PhoneTutorial:1.+#aar') {
exclude module: 'support-v4'
}

I use this to replace all support libraries versions with the latest one that i use in gradle file:
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support') {
if (!requested.name.startsWith("multidex")) {
details.useVersion "26.0.1"
}
}
}
}

Try using this versions in build.gradle file.
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:recyclerview-v7:23.4.0'
compile 'com.android.support:cardview-v7:23.4.0'

Your Error:
java.util.zip.ZipException: duplicate entry: android/support/v4/print/PrintHelperKitkat$2$1.class
Step 1:
In this case main hint is android/support/v4/print/PrintHelperKitkat$2$1.class
Step 2: Searching for the class, in your case the "PrintHelperKitkat.class" (in AndroidStudio just hit Ctrl+N on Windows or CMD-O on Mac)
Step 3: See which jar contains it - Android Studio will write it in the popup.
Step 4: Exclude it from all builds,
for example:
com.android.support:support-v4:_____
compile('your_conflicted_dependency')
{
exclude module: 'support-v4'
}
In my case my one dependency also included in my another AAR. So I
deleted that dependency

I was faced the same issue. I solved it by,
Make sure that in all imported project's build.gradle file should have same compileSdkVersion and dependencies versions like in your project's build.gradle file.
It will remove this error.

Related

Android studio APK buil error transformClassesWithJarMergingForDebug

I'm trying to build APK, but there is an error when I try to make it.
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/gcm/PendingCallback.class
Following is my build.gradle(Module:app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "jordan.personicle"
minSdkVersion 19
targetSdkVersion 25
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile files('libs/ajt-2.9.jar', 'libs/javaml-0.1.7.jar')
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.android.gms:play-services:11.0.1'
compile 'com.google.firebase:firebase-database:10.2.1'
compile 'com.google.firebase:firebase-core:10.0.1'
compile 'com.google.firebase:firebase-messaging:10.0.1'
compile 'com.firebase:firebase-jobdispatcher:0.6.0'
compile 'org.jsoup:jsoup:1.7.3'
compile 'com.android.support:multidex:1.0.0'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
This is my build.gradle (Project)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I think there is no duplication for gcm. What is the problem?
Thanks,
Make sure you use the same version in all your google play services libs:
compile 'com.google.android.gms:play-services:11.0.4'
compile 'com.google.firebase:firebase-database:11.0.4'
compile 'com.google.firebase:firebase-core:11.0.4'
compile 'com.google.firebase:firebase-messaging:11.0.4'
See https://stackoverflow.com/a/42610163/1370087

Android Studio cannot resolve dependency

I use Android studio to create a blank project, but cannot compile.
below is its error:
Error:A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration':app:_debugUnitTestApkCopy'.
> Could not resolve junit:junit:4.12.
Required by:
project :app
> Could not resolve junit:junit:4.12.
> Could not get resource 'https://jcenter.bintray.com/junit/junit/4.12/junit-4.12.pom'.
> Could not GET 'https://jcenter.bintray.com/junit/junit/4.12/junit-4.12.pom'.
> jcenter.bintray.com:443 failed to respond
I tried to use a proxy
and checked proxy settings with the failed url 'https://jcenter.bintray.com/junit/junit/4.12/junit-4.12.pom'
and it show me success
but when I compile the project, it's still the same error.
this is my gradle.properties file:
systemProp.http.proxyHost=127.0.0.1
systemProp.http.proxyPort=1080
systemProp.https.proxyHost=127.0.0.1
systemProp.https.proxyPort=1080
this is project build.gradle file:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
this is app build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
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:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'
testCompile 'junit:junit:4.12'
}
finally, I solved my question
the proxy I use is a sockts5 proxy
the autogenerate gradle.properties file use a http proxy
after I change the gradle.properties it's worked
this is my new gradle.properties:
org.gradle.jvmargs=-Xmx1536m -DsocksProxyHost=127.0.0.1 -DsocksProxyPort=1080

Failed to resolve Junit:Junit:12

I am getting following error when I tried to run my first app in android studio
Error:A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugUnitTestCompile'.
> Could not resolve junit:junit:4.12.
Required by:
Hellow_World:app:unspecified
> Could not resolve junit:junit:4.12.
> Could not get resource 'https://jcenter.bintray.com/junit/junit/4.12/junit-4.12.pom'.
> Could not GET 'https://jcenter.bintray.com/junit/junit/4.12/junit-4.12.pom'.
> jcenter.bintray.com
Following is my Gradle.script(Module)
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.example.administrator.hellow_world"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
}
Following is my Gradle.script(Hellow_World)
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Can somebody help me fixing this mess?
Please follow the below mentioned path:
Right click on your application/project ->
open module settings->
Go to "Dependencies" tab ->
you'll find "junit:junit:4.12" ->
select it and right click and choose remove option -> ok
Now again try to build your application.
Remove the below line in your code
testCompile 'junit:junit:4.12'
then compile it .

Gradle project sync failed. Basic functionality will not work properly

I updated to Android Studio 1.2 and now have a two errors.
When I first open my project I get this error at the top of the screen.
"Gradle project sync failed. Basic functionality will not work properly."
In the Messages Gradle Sync I get
My gradle files are:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
and
apply plugin: 'com.android.application'
android
{
signingConfigs {
config {
keyAlias 'ScoularAndroidKey'
keyPassword 'password'
storeFile file('C:/Users/bschmiedeler/.AndroidStudio/scoularkeystore.jks')
storePassword 'password'
}
}
name="Scoular"
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.scoular.scoular"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
}
debug{
debuggable true
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile files('libs/commons-lang-2.3.jar')
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:support-v4:21.0.3'
compile 'com.google.android.gms:play-services:6.5.87'
compile files('src/main/assets/library-1.0.10.jar')
}
By looking through Stack Overflow I have found some potential solutions.
I have tried File ==> Invalidate and Restart and removing the files that you are supposed to. I am just stuck. Any help would be greatly appreciated.
This is a confirmed bug with Android Studio 1.2:
https://code.google.com/p/android/issues/detail?id=160899
The main solution is to wait for their fix.
I have had luck re-importing the project, but I have to do it every time I open the project.

Plugin with id 'crashlytics' not found issue with Android studio latest plugin

For the following gradle build configuration, I am facing Error:(11, 0) Plugin with id 'crashlytics' not found error.
buildscript {
repositories {
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
}
}
apply plugin: 'android'
apply plugin: 'crashlytics'
apply plugin: 'hugo'
repositories {
maven { url 'http://download.crashlytics.com/maven' }
}
android {
compileSdkVersion 19
buildToolsVersion '20.0.0'
defaultConfig {
applicationId "com.wiznsystems.android"
minSdkVersion 15
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/smartconfiglib.jar')
// You must install or update the Support Repository through the SDK manager to use this dependency.
compile 'com.crashlytics.android:crashlytics:1.+'
compile 'com.android.support:support-v4:19.+'
compile 'com.google.android.gms:play-services:4.2.42'
compile 'com.jakewharton.hugo:hugo-runtime:1.1.0'
compile 'com.squareup.retrofit:retrofit:1.+'
compile 'com.android.support:appcompat-v7:19.+'
compile 'com.jakewharton:butterknife:5.+'
compile 'de.greenrobot:eventbus:2.2.1'
compile 'fr.avianey:facebook-android-api:+#aar'
compile 'com.squareup.picasso:picasso:2.+'
compile 'de.keyboardsurfer.android.widget:crouton:1.8.4'
compile project(':apptentiveandroidsdk')
}
Am I doing something wrong? or Is there any workaround for making it build?
I had the same issue. What I ended up doing was putting the order of the commands inline with what Crashlytics provided. I had something similar to yours and it didn't work. Once it changed it to the exact order of there docs it worked. Here is what mine looks like now. Hope this helps.
buildscript {
repositories {
mavenCentral()
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
}
}
apply plugin: 'android'
apply plugin: 'crashlytics'
repositories {
mavenCentral()
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:19.+'
compile 'com.android.support:support-v4:19.0.+'
compile 'com.squareup.picasso:picasso:2.3.2'
compile 'com.joanzapata.android:android-iconify:1.0.6'
compile 'com.github.hotchemi:android-rate:0.3.1'
compile 'com.loopj.android:android-async-http:1.4.5'
compile 'com.github.satyan:sugar:1.3'
compile 'com.crashlytics.android:crashlytics:1.+'
}
android {
compileSdkVersion 19
buildToolsVersion "20"
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
Try informing the classpath dependency:
buildscript {
repositories {
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
}
}
After battling with this error for hours, I ended up deleting the ".gradle" folder on my home directory, and the issue vanished! So, if you are getting this issue, try deleting the .gradle folder first, then rebuild your project.

Resources