如何解决导入org.apache.http.util无法解决?

时间:2017-01-11 09:15:19

标签: android eclipse cordova build build-target

我将MainActivity- CordovaLib中的项目构建目标从android 5.1.1更改为android 7.1.1。更改构建目标后,它在src / CordovaResourceApi.java中显示错误,导致无法解析导入org.apache.http.util。 但是,当我将构建目标更改回5.1.1时,它不会显示任何错误。 我该如何解决这个问题?这是res /

中的build.gradle文件
 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 个答案:

答案 0 :(得分:2)

尝试在android下的gradle中添加以下内容:

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

答案 1 :(得分:0)

将此值放在app.text内的build.gradle中

例如: -

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


ExampleProject/build.gradle <<== not in 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"
    }