android studio无法创建新项目

时间:2016-01-05 22:40:41

标签: java android android-studio android-gradle new-project

我是Android应用程序开发的新手,这个月我正在使用android studio。之前,我创建了很多项目没有任何问题。这是我在创建新项目时遇到这个奇怪错误的两天:

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

我也卸载了android studio并再次安装它但仍然不能正常工作,而且我以前的项目也不能使用这个新的android工作室。

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

这是屏幕截图: enter image description here

1 个答案:

答案 0 :(得分:2)

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

在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包含在您的项目中,或使用OkHttp代替。

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

编辑:根据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

希望有所帮助

根据这些解释,解决方案是从我的(在Mac上)表格后面的dir中删除java exra库中的httpClients库:     /Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home/jre/lib/ext