java.util.zip.ZipException: duplicate entry: org/apache/http/ConnectionClosedException.class - android-studio

I am getting error like this when i run the application.I am using HttpClient,HttpEntity,HttpResponse and HttpPost in my MainActivity..so i made some modifications to gradle file.After that i am getting error like this.
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/apache/http/ConnectionClosedException.class
i have also included multidex library and org.apache.http.legacy.jar in my app.but then also i am getting the same error.
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.test1"
minSdkVersion 15
targetSdkVersion 23
multiDexEnabled true
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 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
compile 'org.apache.httpcomponents:httpcore:4.4.1'
compile 'org.apache.httpcomponents:httpclient:4.5'
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.android.support:multidex:1.0.1'
compile files('libs/org.apache.http.legacy.jar')
compile 'org.apache.httpcomponents:httpmime:4.5.1'
}
I Know this question has been asked many times,but none of the solutions worked for me..
Can anyone please help me to resolve this one.

You may not use "compile 'org.apache.httpcomponents:httpcore:4.4.1'" nor "compile files('libs/org.apache.http.legacy.jar')" at the same time.

I too faced the same issue. The problem is Since you are using
compile files('libs/org.apache.http.legacy.jar') and
compile 'org.apache.httpcomponents:httpmime:4.5.1'
You need to remove the two libs which I mentioned below. Which contains duplication of the above.
if you are adding legacy and httpmime you don't need this
compile 'org.apache.httpcomponents:httpcore:4.4.1'//remove this
compile 'org.apache.httpcomponents:httpclient:4.5' // remove this too
Also add this inside android section in gradle
android {
compileSdkVersion 25
buildToolsVersion '25.0.2'
useLibrary 'org.apache.http.legacy'

Related

isuess sync gradle for some old project from git

ERROR: Could not find com.android.tools.build:gradle:3.4.1. Searched
in the following locations:
https://jcenter.bintray.com/com/android/tools/build/gradle/3.4.1/gradle-3.4.1.pom
https://jcenter.bintray.com/com/android/tools/build/gradle/3.4.1/gradle-3.4.1.jar
Required by:
project : Add Google Maven repository and sync project Open File Enable embedded Maven repository and sync project
i have try to update distributionUrl
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
and this my build gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "com.example.android.miwok"
minSdkVersion 15
targetSdkVersion 29
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'
implementation "com.android.support:appcompat-v7:$supportVersion"
implementation "com.android.support:support-v4:$supportVersion"
implementation "com.android.support:design:$supportVersion"
}
well this is not best practice to do that, first of all, run that project in android studio and update the gradle, follow one method from this link Link.

How to add linkedin sdk path in app gradle?

I had followed so many tutorials to add linkedin sdk and sync gradle in my project but unable to did that. Downloaded linked sdk from https://developer.linkedin.com/downloads#androidsdk & unziped the folder then add the sdk file to my project directory. I mean copied that to project->app->lib path.Now i am getting the error while writing LISessionManager in activity.Something like this cannot resolve symbol 'LISessionManager'
Here is my build.gradle(app module) file,
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.0"
defaultConfig {
applicationId "com.interfinet.jobtree"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
apply plugin: 'android-apt'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
compile 'com.android.support:palette-v7:24.2.1'
compile 'com.android.support:recyclerview-v7:24.2.1'
compile 'com.android.support:cardview-v7:24.2.1'
compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'com.google.android.gms:play-services-maps:8.4.0'
compile 'com.google.android.gms:play-services-location:8.4.0'
compile 'com.weiwangcn.betterspinner:library-material:1.1.0'
compile 'com.github.hotchemi:permissionsdispatcher:2.0.7'
apt 'com.github.hotchemi:permissionsdispatcher-processor:2.0.7'
compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
compile 'com.jaredrummler:material-spinner:1.1.0'
compile 'com.squareup.picasso:picasso:2.5.2'
}
Setting.gradle file is,
include ':app', ':linkedin-sdk'
You have to add linkedin-sdk folder as a module to your project:
and add this line to your app build.gradle dependencies:
compile project(':linkedin-sdk')

Decompiling a self generated jar in lib in Android Studio

apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'com.github.triplet.play'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.prototype"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
testCoverageEnabled = false
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
testCompile "org.mockito:mockito-core:1.10.19"
testCompile 'org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:0.31'
}
I have generated a jar using swagger codegen and have placed in lib folder of my app in the Android studio. It is not getting decompiled, i.e., I am not able to see classes of my jar here.
I have tried Invalidate caches/Restart. It worked sometimes before.
But it is not working anymore. Any help will be appreciated.
You probably missing in your build.gradle something like:
compile files('libs/your-jar-filename.jar')
The following worked for me :
Right-click the jar file.
Select 'Add as Library.
Do Gradle Sync.

Android Studio: Error: Error:(205, 24) error: exception handling disabled, use -fexceptions to enable

I am very new to Android Studio. I am trying to build some Sqlite3 wrapper classes (written in C++). I tried to build them with NDK using Android studio, but I am getting error that "Error:(205, 24) error: exception handling disabled, use -fexceptions to enable". I am not able to find what option should I give in gradle.build file. I have seen many posts but they all refer to some Android.mk or Application.mk file. I have pasted content of my gradle.build file below:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.asite.ndksample"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
ndk{
moduleName "myLib"
stl "gnustl_static"
}
}
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'
}
Let me know how to come out from this error using Android Studio with gradle.build file. Also let me know detail about all parameters mentioned under "ndk" section. I am not aware what all possible values can be put there.
you can use the cFlags parameter under the ndk section:
ndk{
moduleName "myLib"
stl "gnustl_static"
cFlags "-fexceptions"
}
The only other paramters you can use for this ndk configuration are ldLibs and abiFilter, to specify respectively required ndk libs (log...) and cpu architectures to compile for (x86, armeabi-v7a, x86_64...).

Unable to resolve Robotium Dependency Android Studio

I am trying to use Robotium for writing test cases in Android Studio and I am having a hard time configuring things.
Following is my build.gradle inside the app.
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
defaultConfig {
minSdkVersion 11
targetSdkVersion 19
versionCode 1
versionName '1.0'
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
lintOptions {
abortOnError false
}
productFlavors {
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':library')
androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.1'
androidTestCompile 'junit:junit:4.11'
}
When I clean the project, I get the following error:
Error:A problem occurred configuring project ':NativeSDK'.
Could not resolve all dependencies for configuration ':NativeSDK:_debugTestCompile'.
Could not find com.jayway.android.robotium:robotium-solo:5.1.
Required by:
InAppSDK:NativeSDK:unspecified
Could not find junit:junit:4.11.
Required by:
InAppSDK:NativeSDK:unspecified
Any help on how to resolve this?
I hope that in your top level build.gradle you have the repositories{mavenCentral()} or repositories{jcenter()} in your buildscript{}
When you provide the reference to an artifact in mavenCentral() or jCenter() you need to sync the project after disabling the offline work at least once under studio>preference>gradle>offline work.
Having this will solve the issue. Its just the local cache of the studio has not been updated as per my understanding. You can check the available library version in mavenCentral() or jcenter() in your case its 5.1 for robotium. (better to use 5.2.1 which is the newest as of today)
make sure that you don't have the robotium jar in your libs folder as you are compiling libs file tree. If you have the jar file when compiling it will throw a UNEXPECTED_TOP_LEVEL exception.

Resources