0

In my project I am using an .aar Android library, which I have put inside the <project-dir>/<app-dir>/libs folder. Of course I want to use this library in my project, so I changed the build.gradle (the one inside the <app-dir>) so that it looks like this:

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'
    }
}

When using the library in my main activity, the auto complete feature of Android Studio could find the classes from the library. However, when executing the app, I get the following error:

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)

Can someone help me fix this error? Thanks in advance!

brgr
  • 318
  • 3
  • 16
  • Does it work if you take off the explicit packaging in your dependencies (i.e. remove the `, ext:'aar'` and `@aar` bits)? – Scott Barta Jul 14 '14 at 16:54
  • When doing this, after syncing Android Studio tells me the following: `Error: A problem occurred configuring project ':app'. > Could not resolve all dependencies for configuration ':app:_debugCompile'. > Could not find :MapboxAndroidSDK-0.3.0:. Required by: MyApp:app:unspecified` – brgr Jul 14 '14 at 19:25
  • In general what's happening is that Gradle doesn't pick up transitive dependencies of dependencies you include where you explicitly specify the packaging; this is by design. It seems like leaving the packaging off also doesn't work if your AAR files are local. If you could include your libraries via networked repositories instead of local files, you could leave the packaging off and it would work. Anyhow, I think one of your libraries depends on Guava, and Gradle isn't including it. The solution may be to add in explicit dependencies for the transitive dependencies of your libraries. – Scott Barta Jul 14 '14 at 20:57

0 Answers0