Updated Android Studio, receiving DuplicateFileException - android

I just updated Android Studio and I cannot build my app after doing so. I receive an exception looking like this:
Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/LICENSE
File1: /Users/andersvincentlund/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-core/2.2.2/d20be6a5ddd6f8cfd36ebf6dea329873a1c41f1b/jackson-core-2.2.2.jar
File2: /Users/andersvincentlund/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-databind/2.2.2/3c8f6018eaa72d43b261181e801e6f8676c16ef6/jackson-databind-2.2.2.jar
File3: /Users/andersvincentlund/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-annotations/2.2.2/285cb9c666f0f0f3dd8a1be04e1f457eb7b15113/jackson-annotations-2.2.2.jar
I have googled this type of error and have been suggested to add:
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude '...'
}
in the android clause in gradle. This changes nothing(except makes my build potentially illegal since I would be ignoring licensing for OS code?). Does anyone have an idea on how to solve this? I was hoping an update would not break the code.
EDIT:
I got a comment regarding gradle file so I am posting the entire thing below:
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
android {
packagingOptions {
exclude 'META-INF/NOTICE' // will not include NOTICE file
exclude 'META-INF/LICENSE' // will not include LICENSE file
exclude 'META-INF/notice'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license'
exclude 'META-INF/license.txt'
}
signingConfigs {
config {
keyPassword 'XXXXX'
storeFile file('/XXXXX/XXXXX/XXXXX/android.keystore')
storePassword 'XXXXX'
keyAlias 'XXXXX'
}
}
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "XXXXX"
minSdkVersion 21
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
signingConfig signingConfigs.config
}
}
testOptions {
unitTests.returnDefaultValues = true
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.9.5'
apt 'com.google.dagger:dagger-compiler:2.5'
provided 'javax.annotation:jsr250-api:1.0'
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.google.android.gms:play-services-auth:9.4.0'
compile 'com.google.dagger:dagger:2.5'
compile 'com.google.firebase:firebase-core:9.4.0'
compile 'com.google.firebase:firebase-database:9.4.0'
compile 'com.google.firebase:firebase-auth:9.4.0'
compile 'com.firebaseui:firebase-ui:0.3.1'
compile 'com.firebase:firebase-client-android:2.4.0'
compile group: 'com.google.guava', name: 'guava', version: '19.0'
}
apply plugin: 'com.google.gms.google-services'

Just Remove:
compile fileTree(include: ['*.jar'], dir: 'libs')
from
dependencies {}
The jackson-core-2.2.2.jaris already present in your libs/ but another dependency is trying to add it again externally.

Please add below line
packagingOptions {
exclude 'META-INF/maven/com.belerweb/pinyin4j/pom.xml'
exclude 'META-INF/maven/com.belerweb/pinyin4j/pom.properties'}

Related

Update plugin error

I'm new to android, so please bear with me if my question is stupid.
I have an android project built in older version of gradle. The app works fine when modifying code in existing activities, but whenever I create a new activity, I get the following error:
Error:(77, 13) Failed to resolve: com.android.support.constraint:constraint-layout:1.0.2
Upgrade plugin to version 3.0.1 and sync project
Show in File
Show in Project Structure dialog
This is the content of app level gradle file:
apply plugin: 'com.android.application'
android {
signingConfigs {
config {
keyAlias ''
keyPassword ''
storeFile file('')
storePassword ''
}
}
compileSdkVersion 27
buildToolsVersion "23.0.2"
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}
defaultConfig {
applicationId ""
minSdkVersion 15
targetSdkVersion 22
multiDexEnabled true
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
repositories {
jcenter()
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
dexOptions {
incremental true
}
productFlavors {
}
}
dependencies {
//compile fileTree(include: ['*.jar'], dir: 'libs')
//Fast and simple data storage library for Android
// compile project(':squarecamera')
// compile 'com.github.boxme:squarecamera:1.1.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.amazonaws:aws-android-sdk-s3:2.2.6'
compile 'se.emilsjolander:stickylistheaders:2.7.0'
compile 'com.squareup.picasso:picasso:2.4.0'
compile 'io.paperdb:paperdb:0.9'
compile 'com.fabiendevos:nanotasks:1.1.0'
compile 'com.flipboard:bottomsheet-core:1.5.0'
compile 'com.flipboard:bottomsheet-commons:1.5.0'
compile 'com.android.support:design:23.1.1'
compile 'com.squareup.okhttp:okhttp:1.6.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:1.6.0'
compile 'com.squareup.retrofit:retrofit:2.0.0-beta2'
compile 'com.squareup.retrofit:converter-jackson:2.0.0-beta2'
compile 'com.getbase:floatingactionbutton:1.10.1'
compile project(':squarecamera')
compile 'com.android.support.constraint:constraint-layout:1.0.2'
}
This is my project level gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
}
}
allprojects {
repositories {
jcenter()
}
}
And my android studio version is 3.0.1.
When I update the plugin, I get a lot of compatibility issues.
Please help me resolve this. Thanks in advance!

android studio: duplicating files even when using exclude fix

I am having trouble building my app all of a sudden.
the error:
Error:Execution failed for task
Duplicate files copied in APK lib/x86_64/libogg.so
File1: C:\Users\name\.android\build-cache\72c018be052ae391eef4ab43483d6a04be10a818\output\jni
File2: C:\Users\name\.android\build-cache\425f82e82c18acce2ff0ced2ade670804d31a815\output\jni
I have attempted to fix using packaging options:
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LGPL2.1'
}
entire file
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LGPL2.1'
}
defaultConfig {
applicationId "myappsid"
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
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:26.0.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:design:26.0.1'
compile 'com.android.support:support-v4:26'
compile 'com.android.support:support-vector-drawable:26'
compile 'org.apache.commons:commons-io:1.3.2'
compile 'com.google.android.gms:play-services-ads:11.0.4'
compile 'com.ibm.watson.developer_cloud:android-sdk:0.4.2'
compile 'com.ibm.watson.developer_cloud:java-sdk:3.9.1'
testCompile 'junit:junit:4.12'
compile project(':library-release')
}
any help is greatly appreciated. I have tried longer exclude options as well in other posts that I have found but that didn't help either.
You can try using pickFirst in packagingOptions. You need to get the correct package name of libogg.so from File1 or File2:
packagingOptions {
pickFirst 'com/library/name/lib/x86_64/libogg.so'
...
}
UPDATE:
There is a conflicted dependencies:
compile 'com.ibm.watson.developer_cloud:android-sdk:0.4.2'
compile 'com.ibm.watson.developer_cloud:java-sdk:3.9.1'
From the Watson Developer Cloud Java SDK documentation you can find the following:
The Android SDK utilizes the Java SDK while making some
Android-specific additions. This repository can be found here. It
depends on OkHttp and gson.
which is pointing to the first library. So, you should only use:
compile 'com.ibm.watson.developer_cloud:android-sdk:0.4.2'

Android error when adding plugin com.google.gms.google-services

I am working with Firebase in my Android project. When I add
apply plugin: 'com.google.gms.google-services'
in gradle, it gives me an error. logcat says:
Error:Execution failed for task ':app:mergeDebugResources'.
> [string/google_api_key] E:\android\Workspace\FireGuard\app\src\main\res\values\strings.xml [string/google_api_key] E:\android\Workspace\FireGuard\app\build\generated\res\google-services\debug\values\values.xml: Error: Duplicate resources
I searched a lot, but no luck. How to remove this error? Please help.
below is my gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "com.example.pc.fireguard"
minSdkVersion 16
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner"android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
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.2.1'
testCompile 'junit:junit:4.12'
compile 'com.android.volley:volley:1.0.0'
compile 'com.mikhaellopez:circularimageview:3.0.2'
compile 'com.android.support:support-v13:24.0.0'
compile 'com.android.support:recyclerview-v7:24.0.0'
compile 'com.google.android.gms:play-services:9.6.1'
compile project(':date4j')
compile project(':simple-crop-image-lib')
compile 'com.squareup.picasso:picasso:2.3.2'
compile project(':httpclient-4.3.4')
compile project(':httpmime-4.3.4')
compile project(':httpcore-4.3.2')
compile 'com.paypal.sdk:paypal-android-sdk:2.15.1'
}
apply plugin: 'com.google.gms.google-services'
Strings.xml in your app is having same name as of values.xml of google services library!
Since this answer has helped you in sorting out the issue, I am posting the same comment as an answer.

Error during Building an APK file in Android Studio 2.1.1

Couple of days ago, I upgraded my Android Studio, and now I am facing a problem.
Actually I am trying to build an APK file from my project to test my app on a real device and when I click at Build--> Build Apk then I receive couple of errors in Message Gradle Build. I don't know why these errors are coming please elaborate on the reason as well.
Errors
Error:Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Lcom/android/volley/VolleyError;
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_51\bin\java.exe'' finished with non-zero exit value 2
build.gradle file
apply plugin: 'com.android.application'
android {
signingConfigs {
}
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.dovezeal.gapp"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.0.1'
//compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:support-v4:23.3.0'
compile 'com.android.support:design:23.0.1'
compile 'com.android.support:design:23.1.1'
// Volley
compile 'com.android.volley:volley:1.0.0'
//compile 'com.mcxiaoke.volley:library:1.0.+'
/* compile files('libs/com.mcxiaoke.volley library-1.0.0.jar')*/
// RecyclerView
compile 'com.android.support:recyclerview-v7:23.0.+'
// A simple way to define and render UI specs on top of your Android UI.
compile 'org.lucasr.dspec:dspec:0.1.1'
compile files('libs/library-1.0.0.jar')
// YouTube Player
compile files('libs/YouTubeAndroidPlayerApi.jar')
// GOSN
/* compile files('libs/gson-2.2.3.jar')*/
}
Edit - 1
As janki gadhiya said in her comment below, to change minifyEnabled true and try adding multiDexEnabled true under defaultConfig
with these changes both errors above are gone, but now this following error is coming up.
Error:Execution failed for task:app:transformClassesWithJarMergingForDebug'
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/android/volley/Request$Priority.class
build.gradle file
apply plugin: 'com.android.application'
android {
signingConfigs {
}
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.dovezeal.gapp"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/license.txt'
exclude 'META-INF/notice.txt'
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt')
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.0.1'
//compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:support-v4:23.3.0'
compile 'com.android.support:design:23.0.1'
compile 'com.android.support:design:23.1.1'
// as you already compiled gradle for volley here
compile 'com.android.volley:volley:1.0.0'
// RecyclerView
compile 'com.android.support:recyclerview-v7:23.0.+'
compile 'org.lucasr.dspec:dspec:0.1.1'
// you don't need this so comment the below line.
//compile files('libs/library-1.0.0.jar')
// YouTube Player
compile files('libs/YouTubeAndroidPlayerApi.jar')
}
Edit : Explanations
Your errors 1 - 2 : mean you are having more than 65,000 methods in your project, so I told you to set multiDexEnable true.
Your error 3 : means you're having more than one library having the implementation for the class Request$Priority.class, so the compiler is confused which to choose. So it is showing the error Duplicate entry. This will be solved by packaging options, this will let you use duplicate files.
Add this in your build gradle
dexOptions {
incremental true
javaMaxHeapSize "4g"
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}
I am also getting the same error. When adding the
compile 'com.google.firebase:firebase-ads:10.2.0'
but it is removed when i do as follow:
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.google.firebase:firebase-ads:10.2.0'
}
apply plugin: 'com.google.gms.google-services'**
and in BuildVarient use debugging mode.
I think it will help you.
while updating firebase any google play services then try to update all the libraries. this worked for me. hope it works in some cases.
Bit late to answer but I faced the same issue.
I was able to rectify it using multiDexEnabled -> true
and used packaging options in build.gradle, post the changes .apk got installed successfully.
Syntax:
defaultConfig {
....
....
multiDexEnabled true
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/license.txt'
exclude 'META-INF/notice.txt'
}
buildTypes {
...
...
}
Hope it helps.

duplicate entry AbsHListView in my Android Project

I am working on one android application, where i am using two libraries ( Aviary android sdk and PrintIO sdk)
Getting conflict in libraries and getting this error each time when compiling project :
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: it/sephiroth/android/library/widget/AbsHListView$1.class
I have not used such library anywhere in my project as well as i also checked in both libraries, but not found anything.
Please anyone suggest me anything why i am getting this conflict in my project?
EDIT :
Here is my build.gradle file :
apply plugin: 'com.android.application'
repositories {
mavenCentral()
jcenter()
mavenLocal()
maven {
name 'maven.aviary.com'
url uri("http://maven.aviary.com/repo/release")
}
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
}
}
android {
compileSdkVersion 23
buildToolsVersion "22.0.1"
lintOptions {
disable 'MissingTranslation'
}
defaultConfig {
applicationId "XXXXX.XXXXX"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
renderscriptTargetApi 18
renderscriptSupportModeEnabled true
multiDexEnabled true
}
packagingOptions {
exclude 'lib/armeabi-v7a/librsjni.so'
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile files('libs/httpclient-4.0.1.jar')
compile files('libs/httpcore-4.0.1.jar')
compile project(':MaterialDialog')
compile files('libs/universal-image-loader-1.9.1.jar')
compile project(':StaggeredGrid')
compile project(':CustomFloatingButtonLibrary')
compile files('libs/dropbox-android-sdk.jar')
compile files('libs/gcm.jar')
compile project(':image_select_lib')
compile files('libs/json-simple-1.1.1.jar')
compile project(':chipsLib')
compile files('libs/aws-android-sdk-1.4.3-s3.jar')
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.instabug.library:instabugsupport:1.+'
// compile 'com.aviary.android.feather.sdk:aviary-sdk:3.6.3'
compile 'com.yalantis:phoenix:1.2.3'
compile 'com.squareup.picasso:picasso:2.3.2'
compile 'com.google.android.gms:play-services-location:7.5.0'
compile project(':Aviary-SDK')
compile project(':SwipyLib')
compile project(':printio')
}
EDIT 2 :
I searched for library (AbsHListView) using CTRL + N and it result in following :
I did a google search for the class it/sephiroth/android/library/widget/AbsHListView$1.class and found out it is used by the library here.
Looks like one of your dependencies is using this library. If you are on Windows press CTRL + N and enter this AbsHListView and search. You will find the conflicting class.
EDIT:
Change your dependency like this:
compile project(':printio') {
exclude group: 'it.sephiroth.android.library.widget'
}

Categories

Resources