Emad Omar
Emad Omar

Reputation: 768

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. Now whenever I try to sync Gradle or clean/build project, the Gradle sync fails with this message:

Warning:Unable to find optional library: org.apache.http.legacy

build.gradle (Project: 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]

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. 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

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

Although, I really dislike this solution, but it didn't work either and Gradle still fails ...

Upvotes: 2

Views: 7748

Answers (4)

Moeed Ahmed
Moeed Ahmed

Reputation: 612

ONLY FOR THOSE WHO ARE LOOKING SOLUTION ON Android API 28!

useLibrary 'org.apache.http.legacy' does not work on 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

  1. Put inside your AndroidManifest.xml the next line under tag

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

  2. Change your url from 'http' to 'https' which needs to be invoke

This worked for me.. even in the mid of 2020!

Upvotes: 0

Aleksandar Pavić
Aleksandar Pavić

Reputation: 3430

  1. Locate your org.apache.http.legacy.jar file, usually it is in your SDK's platforms\android-xx\optional
  2. Create optional.json
  3. Paste the following:

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

Upvotes: 3

Sharath
Sharath

Reputation: 691

1.Create a Text file and name it as optional,file type as .json and add the following content:

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

2.Add

android.useDeprecatedNdk=true

in Gradle.properties file of your project.

Upvotes: 0

JBirdVegas
JBirdVegas

Reputation: 11413

I don't think the jar is available from mavenCentral() instead try using jcenter()

repositories {
    mavenCentral()
    jcenter()
}

Also you should try updating to the latest android gradle plugin

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

Upvotes: 1

Related Questions