简体   繁体   English

useLibrary 'org.apache.http.legacy' 不起作用

[英]useLibrary 'org.apache.http.legacy' does not work

I am using Android 1.5 (Win 8.1 x64), I forked the DrKLO/Telegram repository on GitHub and cloned it on my local machine.我使用的是Android 1.5 (Win 8.1 x64),我在GitHub分叉了DrKLO/Telegram存储库并将其克隆到我的本地机器上。 Now whenever I try to sync Gradle or clean/build project, the Gradle sync fails with this message:现在,每当我尝试同步 Gradle 或清理/构建项目时,Gradle 同步都会失败并显示以下消息:

Warning:Unable to find optional library: org.apache.http.legacy警告:找不到可选库:org.apache.http.legacy

build.gradle (Project: Telegram) [ DrKLO/Telegram/blob/master/build.gradle ] build.gradle (项目: Telegram) [ DrKLO/Telegram/blob/master/build.gradle ]

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.1'
    }
}

build.gradle (Module: TMessagesProj) [ DrKLO/Telegram/blob/master/TMessagesProj/build.gradle ] build.gradle (模块: TMessagesProj) [ DrKLO/Telegram/blob/master/TMessagesProj/build.gradle ]

apply plugin: 'com.android.application'

repositories {
    mavenCentral()
}

dependencies {
    compile 'com.android.support:support-v4:23.1.+'
    compile 'com.google.android.gms:play-services:3.2.+'
    compile 'net.hockeyapp.android:HockeySDK:3.6.+'
    compile 'com.googlecode.mp4parser:isoparser:1.0.+'
}

android {
    compileSdkVersion 23
    buildToolsVersion '23.0.2'

    useLibrary 'org.apache.http.legacy'

    ...
}

I know there are many questions here, on StackOverflow, about this issue.我知道在 StackOverflow 上有很多关于这个问题的问题。 But non of them have worked with me.但他们都没有和我一起工作过。 I even tried some alternatives like copying the org.apache.http.legacy.jar file from %USERPROFILE%\\AppData\\Local\\Android\\sdk\\platforms\\android-23\\optional to the libs directory, and added it to the dependencies我什至尝试了一些替代方法,例如将org.apache.http.legacy.jar文件从%USERPROFILE%\\AppData\\Local\\Android\\sdk\\platforms\\android-23\\optional复制到libs目录,并将其添加到依赖项

compile files('libs/org.apache.http.legacy.jar')

Although, I really dislike this solution, but it didn't work either and Gradle still fails ...虽然,我真的不喜欢这个解决方案,但它也没有用,而且 Gradle 仍然失败......

  1. Locate your org.apache.http.legacy.jar file, usually it is in your SDK's platforms\\android-xx\\optional找到你的org.apache.http.legacy.jar文件,通常它在你的 SDK'splatforms\\android-xx\\optional
  2. Create optional.json创建optional.json
  3. Paste the following:粘贴以下内容:

     [ { "name": "org.apache.http.legacy", "jar": "org.apache.http.legacy.jar", "manifest": false } ]

I don't think the jar is available from mavenCentral() instead try using jcenter()我不认为 jar 可以从mavenCentral()而是尝试使用jcenter()

repositories {
    mavenCentral()
    jcenter()
}

Also you should try updating to the latest android gradle plugin你也应该尝试更新到最新的 android gradle 插件

buildscript {
    repositories {
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.0.0-alpha1'
    }
}

1.Create a Text file and name it as optional,file type as .json and add the following content: 1.创建一个Text文件,命名为optional,文件类型为.json,添加如下内容:

[
  {
"name": "org.apache.http.legacy",
"jar": "org.apache.http.legacy.jar",
"manifest": false
  }
]

2.Add 2.添加

android.useDeprecatedNdk=true

in Gradle.properties file of your project.在项目的 Gradle.properties 文件中。

ONLY FOR THOSE WHO ARE LOOKING SOLUTION ON Android API 28!仅适用于在 Android API 28 上寻找解决方案的人!

useLibrary 'org.apache.http.legacy' does not work on Android v9.0 API28. useLibrary 'org.apache.http.legacy'在 Android v9.0 API28 上不起作用。 App crashes upon calling below lines..调用以下行时应用程序崩溃..

`DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
HttpResponse httpResponse = httpClient.execute(httpPost);`

Just follow 2 simple steps只需遵循 2 个简单步骤

  1. Put inside your AndroidManifest.xml the next line under tag将下一行放在你的 AndroidManifest.xml 标签下

    <uses-library android:name="org.apache.http.legacy" android:required="false" />

  2. Change your url from 'http' to 'https' which needs to be invoke将您的网址从“http”更改为需要调用的“https”

This worked for me.. even in the mid of 2020!这对我有用..即使在 2020 年年中!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在build.gradle中编译具有useLibrary&#39;org.apache.http.legacy&#39;的项目时出现&#39;app:transformClassesWithDexForDebug&#39;错误 - Getting 'app:transformClassesWithDexForDebug' error on compiling the project having useLibrary 'org.apache.http.legacy' in build.gradle org.apache.http.legacy 不适用于 API 28 - org.apache.http.legacy doesn't work on API 28 在Android 9中使用org.apache.http.legacy - Using org.apache.http.legacy in Android 9 如何使org.apache.http.legacy与ProGuard(天蓝色移动服务)一起工作? - How to make org.apache.http.legacy work with ProGuard (azure mobile services)? Android:无法找到可选库:org.apache.http.legacy - Android: Unable to find optional library: org.apache.http.legacy 无法找到可选库:org.apache.http.legacy - Unable to find optional library: org.apache.http.legacy 为什么警告:无法找到可选库:org.apache.http.legacy发生? - Why Warning:Unable to find optional library: org.apache.http.legacy occurs? 谁能告诉我如何处理&gt;编译:org.apache.http.legacy在Linux中的此错误? - Can anyone tell me how to handle >compile: org.apache.http.legacy this error in linux? SDk更新后,Android Studio无法找到org.apache.http.legacy - Android Studio not able to find org.apache.http.legacy after SDk update 警告:无法找到可选库:目标21中出现org.apache.http.legacy - Warning:Unable to find optional library: org.apache.http.legacy occurs in target 21
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM