我在android studio的gradle项目中有一个纯java模块和我的android模块。此java模块依赖于.jar文件。当我运行我的Android应用程序时,我得到了这个:
04-15 14:42:02.854 12528-12528/se.springworks.apiexample.androidexampleapp W/ApplicationPackageManager﹕ getCSCPackageItemText()
04-15 14:42:02.864 12528-12528/se.springworks.apiexample.androidexampleapp I/dalvikvm﹕ Failed resolving Lse/springworks/api/client/ServerConfig; interface 1557 'Lorg/aeonbits/owner/Config;'
04-15 14:42:02.864 12528-12528/se.springworks.apiexample.androidexampleapp W/dalvikvm﹕ Link of class 'Lse/springworks/api/client/ServerConfig;' failed
04-15 14:42:02.864 12528-12528/se.springworks.apiexample.androidexampleapp I/dalvikvm﹕ Failed resolving Lse/springworks/api/client/ServerConfig; interface 1557 'Lorg/aeonbits/owner/Config;'
04-15 14:42:02.864 12528-12528/se.springworks.apiexample.androidexampleapp W/dalvikvm﹕ Link of class 'Lse/springworks/api/client/ServerConfig;' failed
04-15 14:42:02.864 12528-12528/se.springworks.apiexample.androidexampleapp E/dalvikvm﹕ Could not find class 'se.springworks.api.client.ServerConfig', referenced from method se.springworks.api.client.M2HClient.<init>
04-15 14:42:02.864 12528-12528/se.springworks.apiexample.androidexampleapp W/dalvikvm﹕ VFY: unable to resolve const-class 1729 (Lse/springworks/api/client/ServerConfig;) in Lse/springworks/api/client/M2HClient;
04-15 14:42:02.864 12528-12528/se.springworks.apiexample.androidexampleapp D/dalvikvm﹕ VFY: replacing opcode 0x1c at 0x000c
04-15 14:42:02.864 12528-12528/se.springworks.apiexample.androidexampleapp I/dalvikvm﹕ Failed resolving Lse/springworks/api/client/ServerConfig; interface 1557 'Lorg/aeonbits/owner/Config;'
04-15 14:42:02.864 12528-12528/se.springworks.apiexample.androidexampleapp W/dalvikvm﹕ Link of class 'Lse/springworks/api/client/ServerConfig;' failed
04-15 14:42:02.864 12528-12528/se.springworks.apiexample.androidexampleapp D/AndroidRuntime﹕ Shutting down VM
java.lang.NoClassDefFoundError: se.springworks.api.client.ServerConfig
at se.springworks.api.client.M2HClient.<init>(M2HClient.java:53)
at se.springworks.apiexample.androidexampleapp.ExampleActivity.onCreate(ExampleActivity.java:23)
at android.app.Activity.performCreate(Activity.java:5426)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
at android.app.ActivityThread.access$900(ActivityThread.java:161)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
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:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
现在,ServerConfig是我自己的Class,但它扩展了一个类'Config',如上所示。这与所有者(http://owner.aeonbits.org/docs/usage/)的使用情况一致。我不太明白为什么这些课程找不到或出了什么问题。我已经尝试在Android模块中直接使用所有者并且它工作得更好(首先,它不会崩溃)。据我所知,这是一个依赖配置问题,但我真的可以在这里使用。这是我使用缺少的类
的子模块的build.gradle文件apply plugin: 'java'
sourceCompatibility = 1.5
version = '1.0'
task wrapper(type: Wrapper) {
gradleVersion = '1.11'
}
repositories {
mavenCentral()
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
}
}
dependencies {
//Maven syntax groupings...
compile group: "com.squareup.retrofit", name: "retrofit", version: "1.5.0"
compile group: "com.squareup.okhttp", name: "okhttp", version: "1.5.3"
testCompile group: 'junit', name: 'junit', version: '4.10'
//Gradle syntax...
compile 'commons-codec:commons-codec:1.2'
//compile 'org.aeonbits.owner:owner:1.0.5'
compile fileTree(dir: 'libs', include: '*.jar')
testCompile 'org.mockito:mockito-all:1.8.4'
}
这是android模块的build.gradle:
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile project(':m2h-api-java-client')
compile 'com.android.support:appcompat-v7:19.+'
compile fileTree(dir: 'libs', include: ['*.jar'])
}
我觉得可能会遗漏一些东西。
答案 0 :(得分:0)
由于body: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text('Hello word')
],
),
是从ServerConfig
扩展而来的,因此如果类路径中缺少org.aeonbits.owner.Config
依赖项,它将不会加载,并且如您的情况,ClassLoader将失败。重新添加依赖项,它将起作用。
答案 1 :(得分:0)
默认情况下,无法在生成jar的过程中构建第三个依赖项,在build.gradle中,配置如下所示的jar任务:
RSACryptoServiceProvider