gpt4 book ai didi

java - android studio 创建新项目失败

转载 作者:行者123 更新时间:2023-11-30 08:42:15 24 4
gpt4 key购买 nike

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

这是屏幕截图: enter image description here

最佳答案

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

HttpClient 在 sdk 23 中不再被支持。

您必须使用 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 上)从 java exra 库中删除 httpClients 库,形式如下: /Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home/jre/lib/ext

关于java - android studio 创建新项目失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34622552/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com