android工作室创建新项目失败

android studio failed to create new project

我是 android 应用程序开发的新手,这个月我在 android 工作室工作。之前,我创建了很多项目都没有任何问题。这两天我在新建项目的时候收到了这个奇怪的错误:

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.

我也卸载了 android studio 并重新安装,但仍然无法正常工作,而且我之前的项目也无法在这个新的 android studio 上运行。

这是我的 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: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 {
}

这是屏幕截图:

我想,您正在尝试使用已经不受支持的库

SDK 23 不再支持

HttpClient

您必须使用 URLConnection 或降级到 sdk 22 (compile 'com.android.support:appcompat-v7:22.2.0')

如果您需要 SDK 版本 23,请将其添加到您的 build.gradle:

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

您也可以尝试下载并包含 HttpClient jar directly into your project or use OkHttp

如果您需要更多信息,请同时查看相关主题:

  • Android libraries not found

编辑:根据How to exclude libraries from all dependencies in Gradle

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

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

检查这个:android studio: gradle dependency error

希望对您有所帮助

基于这些解释,解决方案是从 java exra 库中删除 httpClients 库(在 mac 上),形式如下: /Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home/jre/lib/ext