Category Archives: android-m

Apache HTTP connection with Android 6.0 (Marshmallow)

Is there is any way to include the Apache library directly in Gradle to make it work with Android 6.0 ?

I've tried to include the libraries like that:

compile 'org.apache.httpcomponents:httpcore:4.4.1'
compile 'org.apache.httpcomponents:httpclient:4.5'

And Android Studio couldn't manage to find the following import:

import org.apache.http.auth.AuthenticationException;
import org.apache.http.auth.Credentials;
import org.apache.http.auth.MalformedChallengeException;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.impl.auth.DigestScheme;

org.apache.http.legacy not being imported into project

I have an app with two modules. One module acts as a library and uses the Apache HTTP. Now I must compile it with MNC-Preview but, as known, this framework is no longer part of SDK framework. Being that the case, I read that it is possible to import org.apache.http.legacyas a lib to make it work.

So, basically I have this in my module gradle:

android {
    useLibrary 'org.apache.http.legacy'
    compileSdkVersion 'android-MNC'
    buildToolsVersion "23.0.0 rc3"
    (...)
}

And in the main gradle I have

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

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

allprojects {
    repositories {
        jcenter()
    }
}

I followed this and this but still getting the error that the apache package does not exist.

org.apache.http.legacy not being imported into project

I have an app with two modules. One module acts as a library and uses the Apache HTTP. Now I must compile it with MNC-Preview but, as known, this framework is no longer part of SDK framework. Being that the case, I read that it is possible to import org.apache.http.legacyas a lib to make it work.

So, basically I have this in my module gradle:

android {
    useLibrary 'org.apache.http.legacy'
    compileSdkVersion 'android-MNC'
    buildToolsVersion "23.0.0 rc3"
    (...)
}

And in the main gradle I have

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

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

allprojects {
    repositories {
        jcenter()
    }
}

I followed this and this but still getting the error that the apache package does not exist.

UPDATE: Seems that the code compiles, my bad. However the code in the IDE is marked as not found, I get a lot of errors and no auto complete. Did anyone went thru this?

How to add Apache HTTP API (legacy) as compile-time dependency to build.grade?

As mentioned here, Android M will not support the Apache HTTP API. The docs state to:

use the HttpURLConnection class instead.

or

To continue using the Apache HTTP APIs, you must first declare the following compile-time dependency in your build.gradle file:

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

I have converted much of my project's usage of HttpClient to HttpURLConnection, however, I still need to use the HttpClient in a few areas. Hence, I am trying to declare 'org.apache.http.legacy' as a compile-time dependency but am getting an error in build.gradle:

Gradle DSL method not found: 'useLibrary()'

My question is: how do I declare 'org.apache.http.legacy' as a compile-time dependency in my project?

Any help is much appreciated. Thanks