Category Archives: android-6.0-marshmallow

Replacement for deprecated org.apache.http.conn.scheme.SchemeRegistry, ThreadSafeClientConnManager class etc

I am porting my code to android 6.0. Since apache classes have already been deprecated and removed in API 23, I cant find a exact match for my previous code to make a HTTPS connection. Following is my code

try {


        SchemeRegistry schemeRegistry = new SchemeRegistry();
        schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
        schemeRegistry.register(new Scheme("https",new CustomSSLSocketFactory(), 443));// new CustomSSLSocketFactory().newSslSocketFactory(context.getResources()), 443));

        HttpParams httpParameters = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(httpParameters, 120000);
        ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(httpParameters, schemeRegistry);
        httpClient = new DefaultHttpClient(cm, httpParameters);
        setHttpClient(httpClient);

        AbstractMediator.setServerTime(System.currentTimeMillis());
        httpResponse = httpClient.execute(request);

        serviceResponseObject.setResponseCode(httpResponse.getStatusLine().getStatusCode());
        serviceResponseObject.setMessage(httpResponse.getStatusLine().getReasonPhrase());
        serviceResponseObject.setAllHeader(httpResponse.getAllHeaders());


        Header[] header = httpResponse.getAllHeaders();

    }catch (UnknownHostException e){
        Utility.printStackTrace(e);
        serviceResponseObject.setResponseBody("");
        return responseWithErrorCode(NETWORK_ERROR_CODE101, serviceResponseObject);
    }  catch (IOException e) {
        Utility.printStackTrace(e);
        return responseWithErrorCode(NETWORK_ERROR_CODE100, serviceResponseObject);
    } catch (Exception e) {
        Utility.printStackTrace(e);
        return responseWithErrorCode(NETWORK_ERROR_CODE100, serviceResponseObject);
    }

I have read this link Deprecated: org.apache.http.conn.scheme.scheme is deprecated. It do mention about scheme class new constructor, but not about rest of the methods. My app min API level is 14 and would be glad if any substitute method do respect it.

I have read this 'org.apache.http.HttpEntity' is deprecated. How to solve this error in android studio? which talks about using apache legacy and the other solution regarding Marek Sebera's new Apache HttpClient package for Android, but that does not serve my purpose.

I cant use libraries like Volley, Retrofit, OKHttp as i have web services in Soap XML format

I want to migrate away from apache completely. My concern is to know what all methods in HttpsUrlConnection class can be used for replacement. I would appreciate if i get a code regarding this which do exactly what i am doing above but with new API methods. I came to know about classes like Registry, PoolingHttpClientConnectionManager but i cant understand how to use them to attain above results

Not able to import apache HttpClient in Android 6.0 Marshmallow API 23 [duplicate]

This question already has an answer here:

I am having trouble in converting my simple project from buildtool version 19 to 23.... the app was running on 19 without any error.. i included all apache httpclient jar files from apache site n gave proper path too.. still don't know what's wrong. the reason m trying convert is m unable to include material components i.e. com.android.support:appcompat-v7:23.0.1 hence i have to upgrade buildtool version

this is build.gradle for project

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion '23.0.2'
    useLibrary 'org.apache.http.legacy'
    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
    }
    defaultConfig {
        applicationId "reminder.simpleaccountapp"
        minSdkVersion 14
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.1'
    compile files('libs/activation.jar')
    compile files('libs/additionnal.jar')
    compile files('libs/mail.jar')
    compile 'com.google.android.gms:play-services-appindexing:8.1.0'
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.android.support:design:23.0.1'
}

this is build.gradle for module app

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

buildscript {
    repositories {
        jcenter()
        /*mavenCentral()
        maven{
            url 'http://repository.codehaus.org'
        }*/
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'

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

allprojects {
    repositories {
        jcenter()
    }
}

this is output message

Information:Gradle tasks [:app:assembleDebug]
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72301Library UP-TO-DATE
:app:prepareComAndroidSupportDesign2301Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42301Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesAppindexing810Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesBasement810Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:processDebugJavaRes UP-TO-DATE
:app:compileDebugJavaWithJavac UP-TO-DATE
:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources UP-TO-DATE
:app:preDexDebug UP-TO-DATE
:app:dexDebug
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lorg/apache/http/client/HttpClient;
    at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:579)
    at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:535)
    at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:517)
    at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:164)
    at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
    at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:504)
    at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
    at com.android.dx.command.dexer.Main.run(Main.java:277)
    at com.android.dx.command.dexer.Main.main(Main.java:245)
    at com.android.dx.command.Main.main(Main.java:106)
Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_80\bin\java.exe'' finished with non-zero exit value 2
Information:BUILD FAILED
Information:Total time: 59.486 secs
Information:1 error
Information:0 warnings
Information:See complete output in console