2

I am new in android app development, and this a month that I am working with android studio. Before, I created lots of project without any problem. This is two days that I received this strange error when I create a new project:

Error:Unable to find method 'org.apache.http.impl.client.DefaultHttpClient.setRedirectStrategy(Lorg/apache/http/client/RedirectStrategy;)V'.
Possible causes for this unexpected error include:<ul><li>Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
<a href="syncProject">Re-download dependencies and sync project (requires network)</a></li><li>The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.

<a href="stopGradleDaemons">Stop Gradle build processes (requires restart)</a></li><li>Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.

</li></ul>In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

enter image description here

I also uninstall android studio and install it again but still doesn't work well, and also my previous projects don't work with this new android studio.

this is how my build.gradle looks like:

// 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.5.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
}

android {
compileSdkVersion 22
buildToolsVersion '19.1.0'
defaultConfig {
    minSdkVersion 21
    targetSdkVersion 21
}
productFlavors {
}
}
dependencies {
}

and this is the screen shot: enter image description here

rahim
  • 107
  • 1
  • 10
  • Do you have any android studio project ? I solved this problem by open my previous project . After that it can create new project – Tony Jan 06 '16 at 01:20
  • I have, and I opened them, they were working well, but there was still problem with new projects. Now, I re-install the android studio, even my previous projects don't work. I think the problem is with ".idea" folders which are added automatically. Before, I didn't have these files in my projects. is there any way to remove .idea files to be created automatically? – rahim Jan 07 '16 at 04:19

1 Answers1

2

I suppose that, you're trying to use already unsupported library

HttpClient is not supported any more in sdk 23.

You have to use URLConnection or downgrade to sdk 22 (compile 'com.android.support:appcompat-v7:22.2.0')

If you need SDK version 23, add this to your build.gradle:

android {
    useLibrary 'org.apache.http.legacy'
}

You also may try to download and include HttpClient jar directly into your project or use OkHttp instead.

If you need more information, please check also related topics:


EDIT: According to How to exclude libraries from all dependencies in Gradle

configurations {
 compile.exclude group:'ch.qos.logback'
}

or

 configurations {
    // to avoid double inclusion of support libraries
    all*.exclude group: 'com.android.support', module: 'support-v4'
}

Check this: android studio: gradle dependency error

Hope it help

Based on these explanations, the solution is to remove httpClients libraries from java exra libraries for me (on mac) form following dir: /Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home/jre/lib/ext

Community
  • 1
  • 1
piotrek1543
  • 19,130
  • 7
  • 81
  • 94
  • the problem is that I don't want to use this (HttpClient) in my projects. I think somethings going on in the default settings of a new project. Do you have any idea how I can remove that from default setting? – rahim Jan 05 '16 at 22:53
  • I've edited my post. Hope it help. If still have problems please add to dependencies the code above (starts with `useLibrary`) and forget ;-) Hope it help. Wish you good night – piotrek1543 Jan 05 '16 at 23:10
  • sorry, but I cannot help you more – piotrek1543 Jan 06 '16 at 01:21
  • 1
    Finally, I found the solution. Since I am working with Eclipse, I added some extra libraries to my java libraries. I removed the httpClient libraries and now it works fine. Thanks for your answer, it helps to find the solution. – rahim Jan 07 '16 at 17:08