0

I am making an android app which features navigation drawer. I remember that I used some features that requires sdk version to be 24 so compileSdkVersion needs to be 24 as well as the targetSdkVersion, but my android phone is only 19 so I don't see the app downloaded on my phone, it is opened once I finished running the project but when I close the tab on my phone, I cannot open it again. So I tried to change the compileSdkVersion and targetSdkVersion to 19 but I'm having this error: Unable to find optional library: org.apache.http.legacy

build.gradle:

apply plugin: 'com.android.application'

android {
compileSdkVersion 19
buildToolsVersion "25.0.0"
defaultConfig {
    applicationId "com.marivel.cruz.threatmapping"
    minSdkVersion 17
    targetSdkVersion 19
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    multiDexEnabled true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
signingConfigs {}
buildTypes {}

useLibrary 'org.apache.http.legacy'
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:19.+'
compile 'com.android.support:support-v4:19.1.0'
compile 'com.google.android.gms:play-services-maps:9.8.0'
compile 'com.android.support:multidex:1.0.0'
compile 'com.google.android.gms:play-services:9.8.0'
testCompile 'junit:junit:4.12'
}
camille
  • 17
  • 10

1 Answers1

0

This might seem like a workaround, but try commenting out the use library line and add the following under dependencies in your gradle build file :

dependencies {
compile files('libs/httpclient-4.4.jar')  
compile files('libs/httpcore-4.4.jar')
compile files('libs/httpmime-4.3.6.jar')
}

You will have to download those files from apache and add them to your libs directory. This has worked for me before, but as I said, it feels a bit like a workaround.

You can find those jar files here:

Httpclient

Httpcore

Httpmime

Janpan
  • 2,164
  • 3
  • 27
  • 53
  • I'm sorry, do I have to download those files separately on the web? – camille Dec 01 '16 at 21:27
  • @camille You will have to download those files from apache and add them to your libs directory. I have added links to the correct download locations for each. Let me k ow if it worked. – Janpan Dec 01 '16 at 21:29
  • I've placed the files here on libs directory and it shows error: No such property: compile for class: org.gradle.api.internal.file.collections.DefaultConfigurableFileCollection – camille Dec 01 '16 at 21:44
  • @camille , thats weird. Have you added the lines below the part that reads "compile fileTree(dir: 'libs', include: ['*.jar']) " – Janpan Dec 01 '16 at 21:56
  • You could try grabbing these from Maven Central by using these dependencies: `compile 'org.apache.httpcomponents:httpclient:4.5.13'`, `compile 'org.apache.httpcomponents:httpcore:4.4.14'`, `compile 'org.apache.httpcomponents:httpmime:4.5.13'` (changing versions as necessary). However, this gave me warnings about conflicts with internal versions provided by Android. – user149408 Jul 10 '21 at 13:53