How to solve import org.apache.http.util cannot be resolved?

696 Views Asked by At

I changed the project build target in MainActivity- CordovaLib from android 5.1.1 to android 7.1.1. After changing the build target it shows an error in the src/CordovaResourceApi.java that the import org.apache.http.util cannot be resolved. However when i change the build target back to 5.1.1 it does not show any error. How do i solve this? Here is the build.gradle file in res/

 buildscript {
repositories {
    mavenCentral()
}

// Switch the Android Gradle plugin version requirement depending on the
// installed version of Gradle. This dependency is documented at
// http://tools.android.com/tech-docs/new-build-system/version-compatibility
// and https://issues.apache.org/jira/browse/CB-8143
if (gradle.gradleVersion >= "2.2") {
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0+'
    }
} else if (gradle.gradleVersion >= "2.1") {
    dependencies {
        classpath 'com.android.tools.build:gradle:0.14.0+'
    }
} else {
    dependencies {
        classpath 'com.android.tools.build:gradle:0.12.0+'
    }
}
  }

    apply plugin: 'android-library'

    android {
    compileSdkVersion cdvCompileSdkVersion
     buildToolsVersion cdvBuildToolsVersion
     publishNonDefault true

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_6
    targetCompatibility JavaVersion.VERSION_1_6
}

sourceSets {
    main {
        manifest.srcFile 'AndroidManifest.xml'
        java.srcDirs = ['src']
        resources.srcDirs = ['src']
        aidl.srcDirs = ['src']
        renderscript.srcDirs = ['src']
        res.srcDirs = ['res']
        assets.srcDirs = ['assets']
    }
}
   }
2

There are 2 best solutions below

0
On

Try adding the following in your gradle under android :

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

Put this value in build.gradle inside app folder

for example :-

ExampleProject/app/build.gradle <<== in this one 


ExampleProject/build.gradle <<== not in this

and it should look like this

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.2"
    useLibrary 'org.apache.http.legacy' // <<== add this

    defaultConfig {
        applicationId "com.example.project"
        minSdkVersion 14
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
    }