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

0

I have an error writing this in my buil.gradle of my volley module that matters:

  

useLibrary 'org.apache.http.legacy'

Once I write that line and synchronize the project again it shows me this error:

  

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

I'm using the volley library, this is the buil.gradle of the volley module:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
    }
}

plugins {
    id "com.github.sherter.google-java-format" version "0.6"
    id "net.ltgt.errorprone" version "0.0.13"
}

googleJavaFormat {
    toolVersion = '1.5'
    options style: 'AOSP'
}

apply plugin: 'com.android.library'

repositories {
    jcenter()
}

group = 'com.android.volley'
version = '1.1.1-SNAPSHOT'

android {
    compileSdkVersion 25
    buildToolsVersion = '26.0.2'
    useLibrary 'org.apache.http.legacy'
}

apply from: 'rules.gradle'
apply from: 'bintray.gradle'

This is my Module: app :

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.enriq.examen_tareas_segundo_planp_enrique_espinosa"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

And finally my buil.gradle :

 // Top-level build file where you can add configuration options common
 to all sub-projects/modules.

 buildscript {

     repositories {
         google()
         jcenter()
     }
     dependencies {
         classpath 'com.android.tools.build:gradle:3.0.1'


         // NOTE: Do not place your application dependencies here; they belong
         // in the individual module build.gradle files
     } }

 allprojects {
     repositories {
         google()
         jcenter()
     } }

 task clean(type: Delete) {
     delete rootProject.buildDir }
    
asked by Enrique Espinosa 23.04.2018 в 20:05
source

1 answer

-1

It is important to mention that the Apache libraries are marked as obsolete , this for Android 6.0 (API 23) or later

To continue using them you must activate the "legacy mode" in your file build.gradle :

android {
    useLibrary 'org.apache.http.legacy'
    ...
    ...
}

but there is something important if you are defining:

 compileSdkVersion 26

and

targetSdkVersion 26

In fact there is no longer the option of support or legacy, to "solve" this you must change to the maximum:

compileSdkVersion 23

Actually the correct solution is to change to HttpURLConnection or use an updated version of Volley , since it's not a good idea to lower the level of the API.

On the site we have several examples of the use of this Class:

link

    
answered by 24.04.2018 в 22:53