問題描述
有什么方法可以將 Apache 庫直接包含在 Gradle 中以使其與 Android 6.0 一起使用?
Is there is any way to include the Apache library directly in Gradle to make it work with Android 6.0 ?
我嘗試包含這樣的庫:
compile 'org.apache.httpcomponents:httpcore:4.4.1'
compile 'org.apache.httpcomponents:httpclient:4.5'
Android Studio 無法找到以下導入:
And Android Studio couldn't manage to find the following import:
import org.apache.http.auth.AuthenticationException;
import org.apache.http.auth.Credentials;
import org.apache.http.auth.MalformedChallengeException;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.impl.auth.DigestScheme;
推薦答案
這個page 討論了 Apache HTTP 類的刪除,并提出了一種解決方法:
This page discusses the removal of the Apache HTTP classes, and it suggests a workaround as well:
要繼續使用 Apache HTTP API,您必須首先在 build.gradle 文件中聲明以下編譯時依賴項:
To continue using the Apache HTTP APIs, you must first declare the following compile-time dependency in your build.gradle file:
android {
useLibrary 'org.apache.http.legacy'
}
在我的例子中,Android Studio 仍然抱怨找不到這些類,但應用確實構建并運行了.
In my case Android Studio still complained that it couldn't find these classes, but the app did build and run.
不過,該頁面確實建議您移至 HttpURLConnection.
The page does recommend you move to HttpURLConnection, though.
這篇關于與 Android 6.0 (Marshmallow) 的 Apache HTTP 連接的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!