I have seen similar responses to the below question. Sorry but i could not fixed it out trying multiple things so I am asking it again.
Whenever I am trying to build my app, the gradle build throws me the below error stating ...due to duplicate entry of javax/Inject class.
This only occurred when I am trying to put compile 'org.glassfish.jersey.containers:jersey-container-jdk-http:2.9' in my build.gradle file; This package is necessary for javax.ws.rs.* services.
I tried running the gradlew clean command in my root directory, it says that build is successful but when I am building my application again it started throwing the error again.
Can you please help on the below error:
*Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: javax/inject/Inject.class*
Below is my app gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.usfca.studentrecordsverifycation"
minSdkVersion 17
targetSdkVersion 23
versionCode 1
versionName "1.0"
// Enabling multidex support.
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
maven { url 'http://repo1.maven.org/maven2' }
maven { url 'http://maven.restlet.com' }
maven { url 'https://maven.java.net/content/repositories/releases/' }
maven { url 'http://download.java.net/maven/2/' }
maven { url 'http://download.java.net/maven/1' }
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:design:23.3.0'
compile 'com.android.support:multidex:1.0.1'
compile 'log4j:log4j:1.2.17'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.madgag:sc-light-jdk15on:1.47.0.3'
compile 'com.cloudinary:cloudinary-http44:1.4.5'
compile 'org.glassfish.jersey.containers:jersey-container-jdk-http:2.9'
compile 'commons-lang:commons-lang:2.6'
}
Below is my Project gradle:
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
}
Ok so I created a sample project with all those dependencies and I got a different error.
So if you are still getting the ZipException error, you have some jars in your lib folder that we are not aware of?
Here's the error I got:
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
If you are getting a similar error, all you need to do is add the following to your build.gradle:
android {
defaultConfig {
...
}
buildTypes {
....
}
packagingOptions {
exclude 'META-INF/LICENSE'
}
}
If this doesn't make any difference, do you have any jar libraries in your project? If so, we need to see the list.
EDIT:
I can't know for sure if it will work because I am not getting the same error. In your dependencies, change to this:
compile ('org.glassfish.jersey.containers:jersey-container-jdk-http:2.9') {
exclude group: 'javax.inject', module: 'javax.inject'
}
This error means that the class javax.inject.Inject is being included twice in your apk when the dexer runs. That is, this exact same class is coming from 2 different dependencies. One of them is probably org.glassfish.jersey.containers:jersey-container-jdk-http:2.9 because it happens after you added it.
If you CMD+O (jump to class) on Android Studio, you should be able to see the 2 versions of this class and see where they are coming from. Make sure you select the checkbox that allows it to show classes included from your dependencies. Once you open them, hover over the file tab and you'll see a tooltip with the artifact name. That is gonna be the dependency that's including that class.
Hope it makes sense.
Related
I want to integrate my app with facebook login, but when adding below dependency and syncing Gradle:
implementation 'com.facebook.android:facebook-android-sdk:[5,6)'
I got the following errors:
ERROR: Failed to resolve: legacy-support-v4
Affected Modules: app
ERROR: Failed to resolve: browser
Affected Modules: app
ERROR: Failed to resolve: legacy-support-core-utils
Affected Modules: app
ERROR: Failed to resolve: media
Affected Modules: app
My build.gradle in app-level:
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
buildscript {
repositories {
maven { url 'https://plugins.gradle.org/m2/'}
}
}
repositories { }
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.***************"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.android.support:design:28.0.0'
implementation 'com.google.firebase:firebase-analytics:17.2.1'
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
implementation 'com.github.GrenderG:Toasty:1.4.1'
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
implementation 'com.gauravk.bubblenavigation:bubblenavigation:1.0.7'
implementation 'com.tuyenmonkey:mkloader:1.4.0'
implementation 'me.riddhimanadib.form-master:form-master:1.1.0'
implementation 'com.facebook.android:facebook-android-sdk:[5,6)'
}
apply plugin: 'com.google.gms.google-services'
and build.gradle on project-level:
buildscript {
repositories {
google()
jcenter()
maven { url 'https://maven.fabric.io/public' }
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.8.2'
classpath 'com.google.gms:google-services:4.3.3'
classpath 'io.fabric.tools:gradle:1.31.2'
}
}
allprojects {
repositories {
google()
jcenter()
maven { url "https://www.jitpack.io" }
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I've searched a lot on google and StackOverflow and tested all the methods, but this problem doesn't fix. Please help me where is my problem.
First of all remove
buildscript {
repositories {
maven { url 'https://plugins.gradle.org/m2/'}
}
}
repositories { }
from your app-level Gradle file when you have repositories set in your project-level Gradle file. This causes confusion.
Use implementation 'com.facebook.android:facebook-android-sdk:5.13.0' instead of your dependency.
You can always check Maven Centeral for the latest version of libraries.
or
Use Gradle, please, just enter the library name you need and copy the result (don't forget to replace compile with implementation)
I've tested some of Facebook SDK versions, suddenly in 4.26.0 version, my Gradle was successfully built.
I've checked the release note of Facebook SDK on the next version ( 4.27.0 ) and I find this:
Modified
+ Restructured the Facebook SDK and organized it into separate libraries/modules that can depend on one another.
+ Moves GraphRequest.createOpenGraphObject(ShareOpenGraphObject) to ShareGraphRequest.createOpenGraphObject(ShareOpenGraphObject)
+ Moves FacebookSDK.[set|get]WebDialogTheme(...) to WebDialog.[set|get]WebDialogTheme(...)
+ Removes unused dimens from styles.xml
+ Removes files only used by internal tests
+ updates proguard files
Anyway, with the following line, my problem was solved:
implementation 'com.facebook.android:facebook-android-sdk:4.26.0'
It's not good news for me to use about 3 years ago package, but at this point, I don't have any Idea.
Looks like you're pointing to a library that doesn't exist.
Replace your implementation.... with:
implementation 'com.facebook.android:facebook-login:[5,6)'
(source: https://developers.facebook.com/docs/android/componentsdks/)
As Stated in this post, you need to add these two properties to gradle.properties file:
android.useAndroidX=true
android.enableJetifier=true
I'm trying to compile .aidl and generate .java but:
Error:Execution failed for task ':library:compileReleaseAidl'.
> java.lang.RuntimeException: com.android.ide.common.process.ProcessException:
Error while executing 'C:\Users\Michele\AppData\Local\Android\sdk\build-tools\25.0.0\aidl.exe'
with arguments {-pC:\Users\Michele\AppData\Local\Android\sdk\platforms\android-25\framework.aidl
-oC:\Users\Michele\workspace\AndroidLib\library\build\generated\source\aidl\release
-IC:\Users\Michele\workspace\AndroidLib\library\src
-IC:\Users\Michele\workspace\AndroidLib\library\src\release\aidl
-IC:\Users\Michele\workspace\AndroidLib\library\build\intermediates\exploded-aar\com.android.support\appcompat-v7\25.0.1\aidl
-IC:\Users\Michele\workspace\AndroidLib\library\build\intermediates\exploded-aar\com.android.support\support-v4\25.0.1\aidl
-IC:\Users\Michele\workspace\AndroidLib\library\build\intermediates\exploded-aar\com.android.support\support-fragment\25.0.1\aidl
-IC:\Users\Michele\workspace\AndroidLib\library\build\intermediates\exploded-aar\com.android.support\support-media-compat\25.0.1\aidl
-IC:\Users\Michele\workspace\AndroidLib\library\build\intermediates\exploded-aar\com.android.support\support-core-ui\25.0.1\aidl
-IC:\Users\Michele\workspace\AndroidLib\library\build\intermediates\exploded-aar\com.android.support\support-core-utils\25.0.1\aidl
-IC:\Users\Michele\workspace\AndroidLib\library\build\intermediates\exploded-aar\com.android.support\animated-vector-drawable\25.0.1\aidl
-IC:\Users\Michele\workspace\AndroidLib\library\build\intermediates\exploded-aar\com.android.support\support-vector-drawable\25.0.1\aidl
-IC:\Users\Michele\workspace\AndroidLib\library\build\intermediates\exploded-aar\com.android.support\support-compat\25.0.1\aidl
-dC:\Users\Michele\AppData\Local\Temp\aidl3070615992051288022.d
C:\Users\Michele\workspace\AndroidLib\library\src\IRemoteShortcutService.aidl}
I use this build.gradle
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
group='com.github.michelelacorte'
android {
compileSdkVersion 25
buildToolsVersion '25.0.0'
defaultConfig {
minSdkVersion 14
targetSdkVersion 25
versionCode 2
versionName "0.2.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
sourceSets {
main {
aidl.srcDirs = ['src/main/aidl']
}
}
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:25.0.1'
testCompile 'junit:junit:4.12'
compile 'com.google.code.gson:gson:2.8.0'
}
And this root build.gradle
// 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.2.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
// 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've read about issue with build tools, but I doesn't found anything about API 25
EDIT:
I've launched aidl.exe with params and it return:
aidl.exe E 2236 13884 aidl_language.cpp:224] Error while opening file for parsing: 'C:\Users\Michele\workspace\AndroidLib\library\src\IRemoteShortcutService.aidl'
EDIT 2:
Shortcut.aidl
// Shortcut.aidl
package it.michelelacorte.androidshortcuts;
parcelable Shortcuts;
IRemoteShortcutService.aidl
// IRemoteShortcutService.aidl
package it.michelelacorte.androidshortcuts;
interface IRemoteShortcutService {
void addShortcuts(int shortcutsImage, String shortcutsText);
Shortcuts getShortcuts();
}
This .aidl are located in src/main/aidl folder
Did you try to add verbose option to gradle or execute the same aidl.exe manually with the same parameters?
Probably there is an explanatory error code or message from aidl.exe that gradle does not show.
According to the error aidl can not open the file. Check if file exists there and the content is valid.
Try to change to the new default layout:
Put aidl files in /src/main/aidl
build.gradle:
...
sourceSets {
main {
aidl.srcDirs = ['src/main/aidl']
}
}
(though, in general, if file is in /src/main/aidl it is supposed to work without aidl.srcDirs entry)
Don't forget that aidl files should be under package folders like java. For example, if the package is it.michelelacorte.testaidl, the aidl file should be under src/main/aidl/it/michelelacorte/testaidl.
In recent version of Android Studio, the New/AIDL/AIDL File project menu should already place the file under correct folder, if project package is set correctly.
After refactoring java packages, the aidl files changed the packages structure also, but it missed the package in the file itself.
Assure that the aidl specifies the same package (first line in the .aidl) than the folder where it is.
please add
import it.michelelacorte.androidshortcuts.Shortcuts;
in IRemoteShortcutService.aidl file.
I have the same build's version as yours.
I just try to edit IRemoteShortcutService.aidl to import the Shortcut class.
Although, they are in the same package, then it compiles successfully.
I was facing a problem earlier this week. When I tried to do the Android release build it seemed to show the following error --
Error:Execution failed for task ':app:transformClassesWithJarMergingForRelease'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/internal/zzjm.class
I was wondering how I got this error and how to fix it. It seems as if the problem was inside the build.gradle files. Here they are --
App Level -
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.unknown.app"
minSdkVersion 13
targetSdkVersion 23
versionCode 20
versionName "2.34"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':BaseGameUtils')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.google.firebase:firebase-ads:9.0.2'
compile ('com.google.android.gms:play-services:9.0.2'){
exclude group: 'com.google.android.gms.play-services-ads'
}
compile project(path: ':BaseGameUtils')
}
apply plugin: 'com.google.gms.google-services'
Here is the top level --
// 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.1.2'
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
}
Thanks for all help. I have been having this issue for a little while. I could not find the answer in any other stack overflow questions. Thanks Again.
the error explains itself, it means that it found two libraries which are the same
compile 'com.google.android.gms:play-services:9.0.2'
compile 'com.google.android.gms:play-services-ads:9.0.2'
compile 'com.google.android.gms:play-services-identity:9.0.2'
compile 'com.google.android.gms:play-services-gcm:9.0.2'
by including com.google.android.gms:play-services:9.0.2 you are actually including all the play-service libraries, please remove it and you should be fine or remove the others "below it".
you are including the
'com.google.firebase:firebase-ads:9.0.2'
and
'com.google.android.gms:play-services-ads:9.0.2'
but firebase already includes the second library so you don't have to include this one just use the ads library from firebase
It seems as if the BaseGameUtils module was causing the problem. I am not sure why but reomving it, and replacing the BaseGameUtils for some reason did the trick, and the error did not show anymore. Thanks for all the help along the way of figuring out the issue.
hi im new in android development, i am trying to build my apk but i got this erorr. and i update my gradle and i got duplicate copy. how can i fix this error?
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/com.squareup.okhttp/okhttp/pom.properties
File1: C:\Users\Toshiba\.gradle\caches\modules-2\files-2.1\com.squareup.okhttp\okhttp\2.0.0\4c8d1536dba3812cc1592090dc20c47a4ed3c35e\okhttp-2.0.0.jar
File2: C:\Users\Toshiba\.gradle\caches\modules-2\files-2.1\com.crashlytics.android\crashlytics\1.1.13\e821eafa1bf489a26bdb71f95078c26785b37a1\crashlytics-1.1.13.jar
and here's my build.gradle is this the error comes?
buildscript {
repositories {
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'crashlytics'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.mymonas.ngobrol"
minSdkVersion 14
targetSdkVersion 20
versionCode 1
versionName "0.9.0.68"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'], exclude: 'android-support-v4.jar')
compile project('libs:floatlabel')
compile 'com.android.support:support-v4:21.0.0'
compile 'com.android.support:support-v13:21.0.0'
compile 'com.squareup.retrofit:retrofit:1.7.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'
compile 'com.squareup.okhttp:okhttp:2.0.0'
compile 'com.github.dmytrodanylyk.android-process-button:library:1.0.1'
compile 'com.google.android.gms:play-services:6.1.11'
compile 'com.viewpagerindicator:library:2.4.1#aar'
compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'
compile 'com.makeramen:roundedimageview:1.3.0'
compile 'com.andreabaccega:android-form-edittext:1.1.0#aar'
compile 'com.crashlytics.android:crashlytics:1.+'
}
I had the same or at least a very similar problem today with our React Native app. The problem was only on my Mac though. The only plausible explanation we could think of was that I updated a bunch of Android Studio tools and then gradle couldn't build properly with our dependencies. Anyways after excluding the pom.properties and pom.xml from okhttp I kept getting the same error but it turns out that I just had to exclude even more files. This is my complete packagingOptions in build.gradle:
packagingOptions {
exclude 'META-INF/maven/com.squareup.okhttp3/okhttp/pom.properties'
exclude 'META-INF/maven/com.squareup.okio/okio/pom.xml'
exclude 'META-INF/maven/com.squareup.okhttp3/okhttp/pom.xml'
exclude 'META-INF/maven/com.squareup.okio/okio/pom.properties'
}
to solve your problem please add this to your build gradle
packagingOptions {
exclude 'META-INF/pom.properties' /*OR*/ 'META-INF/maven/com.squareup.okhttp/okhttp/pom.properties
}
It seems like okhttp and crashlytics don't work together in newer gradle versions (2.10 in my case). I fixed this by updating the crashlytics to a newer version (which is now called Fabric).
packagingOptions
{
exclude 'META-INF/maven/com.squareup.okhttp/okhttp/pom.properties
exclude 'META-INF/maven/com.squareup.okhttp/okhttp/pom.xml'
}
Please check for correct path "com.squareup.okhttp/okhttp/pom.properties" in your errorlog.
My gradle execution fails with the error message listed below. I have searched a number of other answers on SO that suggest doing this:
dexOptions {
preDexLibraries = false
}
Some say it may be a memory error, some say it may be that a dependency may already include one of the dependencies I'm trying to compile. I've included the error message below along with my build.gradle file where you'll e able to see what dependencies I'm using. Any help is much appreciated!
buildscript {
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.13.3'
// The Fabric Gradle plugin uses an open ended version to react
// quickly to Android tooling updates
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion 21
buildToolsVersion '20.0.0'
defaultConfig {
applicationId "com.dreamengine.shout"
minSdkVersion 13
targetSdkVersion 21
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
dexOptions {
preDexLibraries = false
}
}
dependencies {
//compile 'com.android.support:support-v4:+'
compile files('libs/Parse-1.7.1.jar')
compile 'com.squareup.picasso:picasso:2.3.4'
compile 'com.firebase:firebase-client-android:2.0.3'
compile 'com.squareup.okio:okio:1.0.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.1.0'
compile 'com.squareup.okhttp:okhttp:2.1.0'
compile 'com.squareup.retrofit:retrofit:1.8.0'
compile 'com.android.support:appcompat-v7:21.+'
compile 'com.google.android.gms:play-services:6.5.+'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.github.asne.facebook:facebook:3.17.2'
compile 'com.braintreepayments.api:braintree:1.+'
compile "com.mixpanel.android:mixpanel-android:4.4.1#aar"
// Crashlytics Kit
compile('com.crashlytics.sdk.android:crashlytics:2.1.0#aar') {
transitive = true
}
// Twitter Kit
compile('com.twitter.sdk.android:twitter:1.1.0#aar') {
transitive = true
}
// MoPub Kit
compile('com.mopub.sdk.android:mopub:3.2.2#aar') {
transitive = true
}
//Foursquare
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':Libraries:easyFoursquare4Android')
}
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:dexDebug'.
com.android.ide.common.internal.LoggedErrorException: Failed to run command:
/Applications/Android Studio.app/sdk/build-tools/android-4.4W/dx --dex --num-threads=4 --output ...
Error Code:
137
Running of dx requires spawning a new VM. Creating fails, check if you have enough memory and/or set defaultXmx=-Xmx512m (or lower). Please also check out the answers here Android gradle build script returns error 137 in preDexDebug