0

在我的项目中,我使用了一个 .aar Android 库,我将它放在 <project-dir>/<app-dir>/libs 文件夹中。当然我想在我的项目中使用这个库,所以我更改了 build.gradle(<app-dir> 中的那个),使它看起来像这样:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 19
    buildToolsVersion "20.0.0"

    defaultConfig {
        applicationId "brgr.myapp"
        minSdkVersion 15
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:19.0.0'
    compile(name:'MapboxAndroidSDK-0.3.0', ext:'aar') {
        transitive = true
    }
    compile ('com.cocoahero.android:geojson:1.0.0@aar') {
        transitive=true
    }
}

repositories {
    mavenCentral()
    flatDir {
        dirs 'libs'
    }
}

在我的主要活动中使用库时,Android Studio 的自动完成功能可以从库中找到类。但是,在执行应用程序时,我收到以下错误:

2402-2402/brgr.myapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: brgr.myapp, PID: 2402
java.lang.NoClassDefFoundError: com.google.common.base.Strings
        at com.mapbox.mapboxsdk.views.MapView.<init>(MapView.java:218)
        at com.mapbox.mapboxsdk.views.MapView.<init>(MapView.java:249)
        at brgr.myapp.MyActivity.onCreate(MyActivity.java:18)
        at android.app.Activity.performCreate(Activity.java:5248)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2173)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2269)
        at android.app.ActivityThread.access$800(ActivityThread.java:139)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5102)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
        at dalvik.system.NativeStart.main(Native Method)

有人可以帮我解决这个错误吗?提前致谢!

4

0 回答 0