Getting java.lang.NoClassDefFoundError: while adding a library to a UIAutomator project using Android Studio built with Gradle

I am trying to add Joda-Time as a dependency of my UIAutomator test project in Android Studio using Gradle, and I get the following error when I try to use the LocalDate class in Joda:

java.lang.NoClassDefFoundError: org.joda.time.LocalDate

      

I'm not sure what I am doing wrong. I'm pretty sure my build.gradle and Test Class are correct. This is probably not a Joda problem ... I am implementing the library incorrectly.

Here are my gradle.properties:

androidSdkHome=/Users/timbo/sdk
androidSdkTarget=android-20
androidSdkBuildToolsDir=build-tools/android-4.4W/

      

Here is my build.gradle file:

apply plugin: 'java'
apply plugin: 'idea'

sourceCompatibility = 1.7
targetCompatibility = 1.7

version = '0.1'

project.ext {
    dexDir = new File('build/dex')
    distDir = new File('./dist')
}

repositories {
    mavenCentral()
}

dependencies {
    compile fileTree(dir: androidSdkHome + '/platforms/' + androidSdkTarget, include: '*.jar')
    compile group: 'junit', name: 'junit', version: '4.11'
    compile group: 'joda-time', name: 'joda-time', version: '2.5'
}

jar {
    doLast {
        tasks.dex.execute()
    }
}

task dex(dependsOn: jar, type:Exec) {
    println 'Building dex...'
    project.dexDir.mkdirs()
    workingDir '.'
    commandLine androidSdkHome + '/' + androidSdkBuildToolsDir + '/' + 'dx', '--dex', '--no-strict', '--output=' + buildDir +'/dex/' + project.name + '.jar', jar.archivePath
    doLast {
        tasks.dist.execute()
    }
}

task dist(dependsOn:dex, type:Copy) {
    project.distDir.mkdirs()
    from(project.dexDir)
    into(project.distDir)
    include('*.jar')
}

      

Here's my test:

package com.mofo.hilton.android.uiautomator.tests;

import com.android.uiautomator.core.UiObjectNotFoundException;
import com.android.uiautomator.testrunner.UiAutomatorTestCase;

import org.joda.time.LocalDate;

/**
 * Created by TimBo on 10/11/14.
 */
public class TestJodaTime extends UiAutomatorTestCase {

    @Override
    public void setUp() throws UiObjectNotFoundException {


    }

    public void testJodaTime() throws UiObjectNotFoundException {

        LocalDate dt = new LocalDate();
        LocalDate lastDayOfMonth = dt.dayOfMonth().withMaximumValue();
        System.out.println(lastDayOfMonth);

    }
}

      

And here is a picture of the external libraries that are in my project:

external libraries in AS

+3


source to share





All Articles