0

我将 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']
    }
}
   }
4

2 回答 2

2

尝试在 gradle 下添加以下内容android

android {
    useLibrary 'org.apache.http.legacy'
}
于 2017-01-11T09:25:20.510 回答
0

将此值放在 app 文件夹内的 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"
    }
于 2017-01-12T03:35:06.203 回答