dependencies in Module build.gradle are
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'
compile 'com.android.support:design:26.+'
compile 'org.apache.flink:flink-streaming-java_2.11:1.4.0'
}
but whenever I compile the code it gave me the following error
FAILURE: Build failed with an exception.
* What went wrong: Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK reference.conf File1: /Users/amar/.gradle/caches/modules-2/files-2.1/com.typesafe.akka/akka-actor_2.11/2.4.20/251b1d970698b81dad5aa8b84eec3eea835259d2/akka-actor_2.11-2.4.20.jar File2: /Users/amar/.gradle/caches/modules-2/files-2.1/org.apache.flink/flink-runtime_2.11/1.4.0/c55676f3ca4c7edd82374659471e98b2384868a8/flink-runtime_2.11-1.4.0.jar File3: /Users/amar/.gradle/caches/modules-2/files-2.1/com.typesafe.akka/akka-stream_2.11/2.4.20/7545a4f86cbb372c337dbdb2846110df86a8cc70/akka-stream_2.11-2.4.20.jar File4: /Users/amar/.gradle/caches/modules-2/files-2.1/com.typesafe/ssl-config-core_2.11/0.2.1/3d2e6a36a7427d6f9d3921c91d6ac1f57dc47b57/ssl-config-core_2.11-0.2.1.jar
This problem was solved by following these steps
step # 1 using the dependency from https://mvnrepository.com instead of https://search.maven.org.
step # 2 Also, I found out that as these files are large which crosses the limit of 64K classes that can be included in DEX files, so I have to configure for Multidex details of which are given here
step # 3 most of the issue was being created by Jacktoolchain, so we can disable that and replace it with retro-lambda for which you can follow this tutorial. Make sure to disable Jacktoolchain by commenting or deleting as shown below
// jackOptions { enabled true }
// dexOptions { incremental true }
step # 4 Exclude these packages from packagingOptions as shown below
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/license.txt'
exclude 'META-INF/LGPL2.1'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/notice.txt'
}
step # 5 You may find it weird, but this hack works like
compile group: 'org.apache.flink', name: 'link-java', version: '1.4.0'
was not working and was giving some error, but it worked when compile is replaced by provided. I don't know why, please let me know if you know
provided group: 'org.apache.flink', name: 'flink-java', version: '1.4.0'
Luckily flink-streaming-java_2.11 library already had provided mentioned in https://mvnrepository.com
provided group: 'org.apache.flink', name: 'flink-streaming-java_2.11', version: '1.4.0'
Final Module build.gradle has these contents
apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'
repositories {
mavenCentral()
}
android {
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/license.txt'
exclude 'META-INF/LGPL2.1'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/notice.txt'
}
configurations.all {
// Enforces Gradle to only compile the version number you state for all dependencies, no matter which version number the dependencies have stated.
resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
}
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
// jackOptions { enabled true }
// dexOptions { incremental true }
multiDexEnabled true
applicationId "com.example.amar.testing"
minSdkVersion 26
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
customDebugType {
debuggable true
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
// not sure if adding compatibility is required here
sourceCompatibility = 1.7
targetCompatibility = 1.7
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'
compile 'com.android.support:design:26.+'
testCompile 'junit:junit:4.12'
// for multidex
compile 'com.android.support:multidex:1.0.0'
// for CEP
provided group: 'org.apache.flink', name: 'flink-java', version: '1.4.0'
provided group: 'org.apache.flink', name: 'flink-streaming-java_2.11', version: '1.4.0'
}
Final Application build.gradle has these contents
// 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 'me.tatarka:gradle-retrolambda:3.2.3'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
sourceCompatibility = 1.7
targetCompatibility = 1.7
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
Related
When I build my app, I got this error .
Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
More than one file was found with OS independent path 'META-INF/DEPENDENCIES'
I don't know how to solve this error. I googled this for hours but it still doesn't work
My project gradle:
// Top-level build file where you can add configuration options common
to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
} }
allprojects {
repositories {
google()
jcenter()
} }
task clean(type: Delete) {
delete rootProject.buildDir
}
My app gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
multiDexEnabled true
applicationId "com.example.tingyu.receivedatajson"
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/rxjava.properties'
}
dependencies {
compile 'com.android.support:multidex:1.0.1'}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation files('src/main/java/com/example/tingyu/receivedatajson/httpclient-4.5.jar')
implementation files('src/main/java/com/example/tingyu/receivedatajson/httpclient-win-4.5.jar')
implementation files('src/main/java/com/example/tingyu/receivedatajson/httpcore-4.4.1.jar')
implementation files('src/main/java/com/example/tingyu/receivedatajson/json-simple-1.1.jar')
implementation files('src/main/java/com/example/tingyu/receivedatajson/utils-json-common-3.0.0.jar')
implementation files('src/main/java/com/example/tingyu/receivedatajson/utils-json-handler-2.0.0.jar')
implementation files('src/main/java/com/example/tingyu/receivedatajson/org.osgi.foundation-1.0.0.jar')
implementation files('src/main/java/com/example/tingyu/receivedatajson/java-json.jar')
implementation files('src/main/java/com/example/tingyu/receivedatajson/org.json.jar')
implementation files('src/main/java/com/example/tingyu/receivedatajson/org.json.simple-0.3-incubating-sources.jar')
implementation files('src/main/java/com/example/tingyu/receivedatajson/commons-lang-2.1.jar')
implementation files('src/main/java/com/example/tingyu/receivedatajson/apache-collections-commons-collections-3.1.jar')
implementation files('src/main/java/com/example/tingyu/receivedatajson/ezmorph-1.0.3.jar')
implementation files('src/main/java/com/example/tingyu/receivedatajson/jsonplugin-0.33.jar')
implementation files('src/main/java/com/example/tingyu/receivedatajson/json-lib-2.1-jdk15.jar')
implementation files('src/main/java/com/example/tingyu/receivedatajson/commons-beanutils-core-1.7.0.jar')
}
I try this:
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
}
then got error :
Error:Execution failed for task
':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
put this in you build.gradle .
then Clean and rebuild project
android{
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
}
}
After adding the Google Translate API compile 'com.google.cloud:google-cloud-translate:0.18.0-beta' to my project, I have been getting a strange error
Error:Execution failed for task ':ParseStarterProject:transformResourcesWithMergeJavaResForDebug'.
com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK project.properties
File1: .gradle/caches/modules-2/files-2.1/com.google.cloud/google-cloud-translate/0.18.0-beta/9cac04f2bb48f76f352bf65d782506e4aa18406c/google-cloud-translate-0.18.0-beta.jar
File2: /.gradle/caches/modules-2/files-2.1/com.google.cloud/google-cloud-core/1.0.2/ff451b4b785369093bd91d277c22576fc9c1da3a/google-cloud-core-1.0.2.jar
There are other SO posts which mention "Duplicate files copied in APK META_INF", or "Duplicate files copied in APK LICENSE.txt", etc
However, I have not seen anyone else encounter the error "duplicate files copied in APK project.properties"
Adding these to my gradle does not work
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/io.netty.versions.properties'
exclude 'META-INF/INDEX.LIST'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
Is there something else I can add to my gradle to fix this error? Or is there another way to fix this error by removing "FILE2" as shown in the error logs?
GRADLE
apply plugin: 'com.android.application'
android {
useLibrary 'org.apache.http.legacy'
packagingOptions {
// exclude 'META-INF/LICENSE'
//exclude 'META-INF/io.netty.versions.properties'
//exclude 'META-INF/INDEX.LIST'
}
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
multiDexEnabled true
applicationId "com.package.name"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 41
versionName "2.1"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
disable 'MissingTranslation'
disable 'ExtraTranslation'
}
dexOptions {
javaMaxHeapSize "4g"
}
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.firebase:firebase-core:10.2.0'
compile 'com.google.firebase:firebase-messaging:10.2.0'
//noinspection GradleCompatible
compile 'com.google.cloud:google-cloud-translate:0.18.0-beta'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.parse.bolts:bolts-tasks:1.3.0'
compile 'com.parse:parse-android:1.13.0'
compile 'com.android.support:multidex:1.0.1'
//noinspection GradleDynamicVersion
compile 'com.facebook.android:facebook-android-sdk:[4,5)'
//noinspection GradleCompatible
compile 'com.google.android.gms:play-services-ads:10.2.0'
// compile 'com.onesignal:OneSignal:3.4.3#aar'
}
}
apply plugin: 'com.google.gms.google-services'
dependencies {
compile 'com.android.support.constraint:constraint-layout:1.0.1'
}
in my case,
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/io.netty.versions.properties'
exclude 'META-INF/INDEX.LIST'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'project.properties' <------------------------here
}
Remove the google cloud core dependancy
While adding translate dependancy do this
compile ('com.google.cloud:google-cloud-translate:0.5.0') {
exclude group: 'io.grpc', module: 'grpc-all'
exclude group: 'com.google.protobuf', module: 'protobuf-java'
exclude group: 'com.google.api-client', module: 'google-api-client-
appengine'
}
In my android application i have to create charts, so I likes to use MPAndroidCharts for that.I saw the latest release on that is v3.0.1 but i can configure it on gradle correctly.I got below error when i use its gradle configuration.
Error:Gradle: A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugCompile'.
> Could not find com.github.PhilJay:MPAndroidChart:v3.0.1.
Searched in the following locations:
https://jcenter.bintray.com/com/github/PhilJay/MPAndroidChart/v3.0.1/MPAndroidChart-v3.0.1.pom
https://jcenter.bintray.com/com/github/PhilJay/MPAndroidChart/v3.0.1/MPAndroidChart-v3.0.1.jar
file:/usr/local/lib/android-sdk-linux/extras/android/m2repository/com/github/PhilJay/MPAndroidChart/v3.0.1/MPAndroidChart-v3.0.1.pom
file:/usr/local/lib/android-sdk-linux/extras/android/m2repository/com/github/PhilJay/MPAndroidChart/v3.0.1/MPAndroidChart-v3.0.1.jar
file:/usr/local/lib/android-sdk-linux/extras/google/m2repository/com/github/PhilJay/MPAndroidChart/v3.0.1/MPAndroidChart-v3.0.1.pom
file:/usr/local/lib/android-sdk-linux/extras/google/m2repository/com/github/PhilJay/MPAndroidChart/v3.0.1/MPAndroidChart-v3.0.1.jar
What I am doing wrong?? Below is my gradle configuration.
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '23.0.2'
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.example.myproject"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
vectorDrawables.useSupportLibrary = true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
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'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:design:23.2.0'
compile 'com.android.support:cardview-v7:23.2.0'
compile 'com.android.support:recyclerview-v7:23.2.0'
compile 'org.springframework.android:spring-android-rest-template:1.0.1.RELEASE'
compile('org.springframework.android:spring-android-auth:1.0.1.RELEASE') {
exclude module: 'spring-core'
}
compile 'org.springframework.android:spring-android-core:1.0.1.RELEASE'
compile 'org.apache.commons:commons-io:1.3.2'
compile 'com.github.PhilJay:MPAndroidChart:v3.0.1'
}
You forgot to add that in your build.gradle (Project:...):
allprojects {
repositories {
maven { url "https://jitpack.io" }
}
}
I have a android studio project contains two modules use same library (jsoup). When i compie app it will show
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/maven/org.jsoup/jsoup/pom.xml File1:
C:\Users\G.gradle\caches\modules-2\files-2.1\org.jsoup\jsoup\1.8.2\64238922c4006c3d0a9951c4c03983ecc6a1e1a0\jsoup-1.8.2.jar
File2:
C:\Users\G\AndroidStudioProjects\twrb\app\build\intermediates\exploded-aar\twrb\webviewtimetablesearcher\unspecified\jars\classes.jar
The dependencies in build.gradle of two modules as show below.
dependencies {
compile 'org.jsoup:jsoup:1.8.2'
}
And this is build.gradle of app.
dependencies {
compile project(':moduleA')
compile project(':moduleB')
}
How to fix it?? Thanks.
This is my whole build.gradle of app
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.test.tmp"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/services/javax.annotation.processing.Processor'
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'
exclude 'META-INF/maven/org.jsoup/jsoup/pom.xml'
exclude 'org/jsoup/nodes/entities-base.properties'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'me.tatarka:gradle-retrolambda:3.2.4'
}
}
// Required because retrolambda is on maven central
repositories {
mavenCentral()
}
apply plugin: 'com.android.application' //or apply plugin: 'java'
apply plugin: 'me.tatarka.retrolambda'
dependencies {
compile 'com.android.support:support-v4:23.2.1'
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:design:23.1.0'
compile 'com.android.support:cardview-v7:23.1.0'
compile 'com.android.support:recyclerview-v7:23.1.0'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'io.realm:realm-android:0.87.5'
compile 'de.greenrobot:eventbus:2.4.0'
compile 'io.reactivex:rxandroid:1.1.0'
compile 'io.reactivex:rxjava:1.1.0'
compile 'com.jakewharton.rxbinding:rxbinding:0.4.0'
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
testCompile 'junit:junit:4.12'
androidTestCompile 'junit:junit:4.12'
compile project(':moduleA')
compile project(':moduelB')
}
For resolve it you must add
android {
packagingOptions {
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
}
}
in build.gradle
My Android Studio returns this error when trying to import GSon 2.3.1 into my project:
Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_79\bin\java.exe'' finished with non-zero exit value 2
I know that this occures everytime I have some duplicates of libraries or something.I already tried to add mavenCentral() to my Repositories
My full app Gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.example.marian.stream"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
maven {
url "https://jitpack.io"
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile("org.restlet.jse:org.restlet.ext.httpclient:2.1.2") {
exclude group: 'org.restlet', module: 'jse'
exclude group: 'org.restlet.ext', module: 'ss1'
}
android {
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/ASL2.0'
exclude 'META-INF/services/org.restlet.engine.ClientHelper'
}
}
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'net.koofr:java-koofr:1.2.8'
compile 'org.apache.httpcomponents:httpclient:4.3.5'
compile 'org.restlet.jse:org.restlet.ext.jackson:2.1.2'
compile 'com.github.dmytrodanylyk.android-process-button:library:1.0.3'
compile 'com.rengwuxian.materialedittext:library:1.8.3'
compile 'com.github.navasmdc:MaterialDesign:1.+#aar'
compile 'com.google.android.gms:play-services:7.0.0'
compile 'com.android.support:recyclerview-v7:21.0.+'
compile project(':..:vector-compat-master:library')
compile 'com.baoyz.pullrefreshlayout:library:1.0.1'
compile('com.mikepenz:materialdrawer:3.0.9#aar') {
transitive = true
}
compile 'com.github.bmelnychuk:atv:1.2.+'
compile 'com.google.code.gson:gson:2.3.1'
}
Could you try adding this to your Gradle:
android {
....
dexOptions {
jumboMode = true
}
}