我安装了Andorid Studio,并且第一次启动一个新项目。 在编译时出现以下错误:“连接被拒绝:连接”
我尝试设置代理,也尝试使用本地gradle,但这没有帮助。
org.gradle.api.ProjectConfigurationException: A problem occurred configuring root project 'MyApplication2'.
[...]
Caused by: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all artifacts for configuration ':classpath'.
[...]
Caused by: org.gradle.internal.resolve.ModuleVersionResolveException: Could not resolve com.android.tools.build:gradle:3.3.1.
Required by:
project :
[...]
Caused by: org.gradle.internal.resolve.ModuleVersionResolveException: Could not resolve com.android.tools.build:gradle:3.3.1.
[...]
Caused by: org.gradle.api.resources.ResourceException: Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.3.1/gradle-3.3.1.pom'.
[...]e
Caused by: org.gradle.internal.resource.transport.http.HttpRequestException: Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.3.1/gradle-3.3.1.pom'.
[...]
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to xx.xxx.xx.xx:8080 [/xx.xxx.xx.xx] failed: Connection refused: connect
[...]
Caused by: java.net.ConnectException: Connection refused: connect
[...]
答案 0 :(得分:0)
问题可能是由于代理人造成的, 或者,下载Gradle发行版,并在 gradle-wrapper.properties 中提供该zip文件的路径。
extension Observable {
/// handle the network response and map to JSON
/// - returns: Observable<JSON>
func handleResponseMapJSON() -> Observable<Result<JSON, ORMError>> {
return self.map { representor in
guard let response = representor as? Moya.Response else {
return .failure(ORMError.ORMNoRepresentor)
}
guard ((200...299) ~= response.statusCode) else {
return .failure(ORMError.ORMNotSuccessfulHTTP)
}
guard let json = JSON.init(rawValue: response.data),
json != JSON.null,
let code = json["code"].int else {
return .failure(ORMError.ORMParseJSONError)
}
guard code == BizStatus.BizSuccess.rawValue else {
let message: String = {
let json = JSON.init(data: response.data)
guard let msg = json["status"].string else { return "" }
return msg
}()
log(message, .error)
return .failure(ORMError.ORMBizError(resultCode: "\(code)", resultMsg: message))
}
return .success(json["result"])
}
}
/// JSON map to object
/// - returns: Observable<T>
func jsonMapObject<T: Mappable>(type: T.Type) -> Observable<Result<T, ORMError>> {
return self.map { rawResult in
guard let result = rawResult as? Result<JSON, ORMError> else {
return .failure(ORMError.ORMParseJSONError)
}
switch result {
case let .success(json):
guard json != JSON.null,
let dict = json.dictionaryObject else {
return .failure(ORMError.ORMParseJSONError)
}
guard let object = Mapper<T>().map(JSON: dict) else {
return .failure(ORMError.ORMCouldNotMakeObjectError)
}
return .success(object)
case let .failure(error):
return .failure(error)
}
}
}
/// JSON map to object array
/// - returns: Observable<[T]>
func jsonMapArray<T: Mappable>(type: T.Type) -> Observable<Result<[T], ORMError>> {
return self.map { rawResult in
guard let result = rawResult as? Result<JSON, ORMError> else {
return .failure(ORMError.ORMParseJSONError)
}
switch result {
case let .success(json):
guard json != JSON.null,
let jsonArray = json.array else {
return .failure(ORMError.ORMParseJSONError)
}
let dictArray = jsonArray.map { $0.dictionaryObject! }
return .success(Mapper<T>().mapArray(JSONArray: dictArray))
case let .failure(error):
return .failure(error)
}
}
}
}
答案 1 :(得分:0)
它显示为:
原因:
org.apache.http.conn.HttpHostConnectException
:连接到xx.xxx.xx.xx:8080 [/xx.xxx.xx.xx]失败:连接被拒绝:连接
似乎是本地存储库或本地代理服务器出错。
检查buildscript
存储库和代理设置。