2017-08-01 40 views
0

我在我的項目中多個模塊,並添加以下依賴於我的項目級別build.gradle文件使用整個項目HTTP客戶端庫:無法找到HTTP客戶端庫 - Android電子

compile "cz.msebera.android:httpclient:4.4.1.2" 

我創建了一個新的模塊,我想使用上面提到的庫。因此,這裏是我在build.gradle做該模塊:

android { 
    compileSdkVersion 25 
    buildToolsVersion "26.0.0" 
    useLibrary 'cz.msebera.android.httpclient' 

    defaultConfig { 
     minSdkVersion 16 
     targetSdkVersion 25 
     versionCode 1 
     versionName "1.0" 

     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 

} 

我一直在關注this post。試圖同步項目時,我得到以下錯誤:

Error: Unable to find optional library: cz.msebera.android.httpclient

我不明白這裏出了什麼問題。請幫我整理一下。

+0

重複的https://stackoverflow.com/questions/32676049/the-import-org-apache-http-client-cannot-be-resolved-error-when-i-update-sdk-to/35211175#35211175 –

+0

可能重複[導入org.apache.http.client無法解析錯誤,當我更新sdk到M](https://stackoverflow.com/questions/32676049/the-import-org-apache-http-client-解決錯誤時,我更新SDK - ) –

回答

0

使用

compile 'org.apache.httpcomponents:httpclient-android:4.3.5.1' 
+0

而不是'cz.msebera.android:httpclient:4.4.1.21在主要?或模塊的build.gredle? –

+0

@sayreskabir你需要寫入模塊依賴。 –

1

使用這種依賴在你的build.gradle(模塊:APP):

dependencies { 
    compile 'org.apache.httpcomponents:httpclient-android:4.3.5.1' 
} 
+0

我添加到模塊gradle,它是work.according這個網站:https://hc.apache.org/httpcomponents-client-4.5.x/android-port.html版本:'4.3.5.1'是爲Android API 22和更老的版本:'4.4.1.1'適用於Android API 23和更新版本。日Thnx。 –

+0

快樂它幫助兄弟。你能否把答案標記爲接受? – sam

1

使用本 compile group: 'cz.msebera.android', name: 'httpclient', version: '4.4.1.1',或者您可以使用庫直接從HERE並粘貼到您lib文件夾,並選擇添加爲庫右鍵單擊該庫後粘貼。

+0

我用這樣的:編譯組:'cz.msebera.android',名稱:'httpclient',版本:'4.4.1.2' –

+0

但DefaultHttpClient已被棄用! –

+0

比你只需要做的事情就是下載這個庫,並把你的lib文件夾 –

相關問題