我试图使用Gradle将Joda-Time作为依赖项添加到Android Studio中的UIAutomator测试项目中,当我尝试在Joda中使用LocalDate类时出现以下错误:
java.lang.NoClassDefFoundError: org.joda.time.LocalDate
我不确定我做错了什么。我非常确定我的build.gradle和Test Class是正确的。这可能不是Joda问题......我只是错误地实现了库。
这是我的gradle.properties:
androidSdkHome=/Users/timbo/sdk
androidSdkTarget=android-20
androidSdkBuildToolsDir=build-tools/android-4.4W/
继承我的build.gradle文件:
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')
}
这是我的测试:
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);
}
}
这是我项目中的外部库的图像: