我正在尝试使用 gradle 将json-schema-validator添加到我的 android 测试项目中,但我遇到了一些问题:
- 文件重复
json-schema-validator
并json-schema-core
阻止我构建测试项目,所以我将它们排除在packagingOptions
运行测试时找不到文件:运行 android 测试时,出现异常
JsonSchemaFactory 工厂 = JsonSchemaFactory.byDefault();
我的猜测是 JsonLoader 无法在测试项目中找到 /draftv4/schema
任何人成功地将其添加到 android 测试或如何帮助 JsonLoader 获取正确的文件。谢谢
这是构建脚本和异常堆栈跟踪
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
apply plugin: 'android'
android {
packagingOptions {
exclude 'LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE'
exclude 'APK META-INF/ASL-2.0.txt'
exclude 'META-INF/ASL-2.0.txt'
exclude 'META-INF/LGPL-3.0.txt'
exclude 'ASL-2.0.txt'
exclude 'LGPL-3.0.txt'
exclude 'LICENSE'
exclude 'META-INF/NOTICE.txt'
exclude 'draftv3/schema'
exclude 'draftv4/schema'
}
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
minSdkVersion 10
targetSdkVersion 18
renderscriptTargetApi 19
renderscriptSupportMode true
testApplicationId "com.sample.test"
testInstrumentationRunner "android.test.InstrumentationTestRunner"
}
buildTypes {
debug {
debuggable true
zipAlign false
}
}
sourceSets {
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
dependencies {
repositories {
mavenCentral()
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
}
// Other dependencies
androidTestCompile 'junit:junit:3.8'
androidTestCompile ("com.github.fge:json-schema-core:1.2.3");
androidTestCompile ('com.github.fge:json-schema-validator:2.1.8')
androidTestCompile 'org.mockito:mockito-all:1.9.5'
}
apply plugin: 'idea'
idea {
module {
testOutputDir = file('build/test-classes/debug')
}
}
java.lang.ExceptionInInitializerError
at com.github.fge.jsonschema.SchemaVersion.<init>(SchemaVersion.java:65)
at com.github.fge.jsonschema.SchemaVersion.<clinit>(SchemaVersion.java:44)
at com.github.fge.jsonschema.core.load.configuration.LoadingConfigurationBuilder.<init>(LoadingConfigurationBuilder.java:117)
at com.github.fge.jsonschema.core.load.configuration.LoadingConfiguration.byDefault(LoadingConfiguration.java:151)
at com.github.fge.jsonschema.main.JsonSchemaFactoryBuilder.<init>(JsonSchemaFactoryBuilder.java:66)
at com.github.fge.jsonschema.main.JsonSchemaFactory.newBuilder(JsonSchemaFactory.java:120)
at com.github.fge.jsonschema.main.JsonSchemaFactory.byDefault(JsonSchemaFactory.java:110)
at com.chatwing.managers.ApiManagerImplTest.assertRegisterValidationError(ApiManagerImplTest.java:115)
at com.chatwing.managers.ApiManagerImplTest.testRegisterChatWingWithDuplicateEmail(ApiManagerImplTest.java:191)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1701)
Caused by: java.io.IOException: resource /draftv4/schema not found
at com.github.fge.jackson.JsonLoader.fromResource(JsonLoader.java:91)
at com.github.fge.jsonschema.SchemaVersion.<init>(SchemaVersion.java:63)
... 21 more