2

这是我的 build.gradle 文件

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
    }
}

apply plugin: 'android'

allprojects {
    repositories {
        mavenCentral()
    }
}

dependencies {
    repositories {
        mavenCentral()
    }

    // Google Play Services
    compile 'com.google.android.gms:play-services:3.2.25'

    // Support Libraries
    compile 'com.android.support:support-v4:18.0.0'
    compile 'com.android.support:gridlayout-v7:18.0.0'
    compile 'com.android.support:support-v13:18.0.0'

    // Note: these libraries require the "Google Repository" and "Android Repository"
    //       to be installed via the SDK manager.

    compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
    compile 'com.nineoldandroids:library:2.4.0'

    compile 'org.apache.httpcomponents:httpmime:4.3'
}

android {
    compileSdkVersion 18
    buildToolsVersion "18.0.1"

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 18
    }

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

项目构建成功,没有错误没有警告。

:preBuild UP-TO-DATE                                  
:preDebugBuild UP-TO-DATE  
:preReleaseBuild UP-TO-DATE  
:prepareComActionbarsherlockActionbarsherlock440Library UP-TO-DATE  
:prepareComAndroidSupportGridlayoutV71800Library UP-TO-DATE  
:prepareComGoogleAndroidGmsPlayServices3225Library UP-TO-DATE  
:prepareDebugDependencies             
:compileDebugAidl UP-TO-DATE  
:compileDebugRenderscript UP-TO-DATE  
:generateDebugBuildConfig UP-TO-DATE  
:mergeDebugAssets UP-TO-DATE  
:mergeDebugResources UP-TO-DATE  
:processDebugManifest UP-TO-DATE  
:processDebugResources UP-TO-DATE  
:generateDebugSources UP-TO-DATE  
:nativeLibsToJar UP-TO-DATE  
:compileDebug UP-TO-DATE  
:dexDebug UP-TO-DATE  
:processDebugJavaRes UP-TO-DATE  
:validateDebugSigning             
:packageDebug UP-TO-DATE  
:assembleDebug UP-TO-DATE  
:prepareReleaseDependencies             
:compileReleaseAidl             
:compileReleaseRenderscript             
:generateReleaseBuildConfig UP-TO-DATE  
:mergeReleaseAssets UP-TO-DATE  
:mergeReleaseResources UP-TO-DATE  
:processReleaseManifest UP-TO-DATE  
:processReleaseResources UP-TO-DATE  
:generateReleaseSources             
:compileRelease             
:dexRelease             
:processReleaseJavaRes UP-TO-DATE  
:packageRelease             
:assembleRelease             
:assemble             
:check UP-TO-DATE  
:build             

BUILD SUCCESSFUL

Total time: 39.311 secs

但是当我在模拟器或 USB 设备上运行项目时,我得到了错误NoClassDefFoundError: org.apache.http.entity.mime.MultipartEntityBuilder

这个问题只出现在 org.apache.httpcomponents:httpmime:4.3 和其他库,比如 com.actionbarsherlock:actionbarsherlock:4.4.0@aar 没问题

4

1 回答 1

3

Google 在 android SDK (v18) 中有原生 httpcore 包,这个包是httpcore:4.2.x. 为了org.apache.httpcomponents:httpmime正常工作,它必须与原生版本相同,httpcoreorg.apache.httpcomponents:httpmime:4.2.1

我将httpclient-4.2.1.jar httpmime-4.2.1.jar库下载到该<project>/libs文件夹​​中。

build在制作项目之前删除文件夹。
这个配置解决了我使用 httpmime 的所有问题:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
    }
}

apply plugin: 'android'

allprojects {
    repositories {
        mavenCentral()
    }
}

dependencies {
    repositories {
        mavenCentral()
    }

    // Google Play Services
    compile 'com.google.android.gms:play-services:3.2.25'

    // Support Libraries
    compile 'com.android.support:support-v4:18.0.0'
    compile 'com.android.support:gridlayout-v7:18.0.0'
    compile 'com.android.support:support-v13:18.0.0'

    compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'

    compile fileTree(dir: "libs", include: '*.jar')
}

android {
    compileSdkVersion 18
    buildToolsVersion "18.0.1"

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 18
    }

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

        debug.setRoot('debug')
    }
}
于 2013-10-15T12:03:04.927 回答