0

I have a pure java module alongside my android module in a gradle project in android studio. This java module has a dependency on a .jar file. When I run my android application I get this:

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)

Now, ServerConfig is my own Class, and but it extends a class 'Config' as you can see above. This is in accordance with the usage of Owner (http://owner.aeonbits.org/docs/usage/). I don't quite understand why these classes can't be found or what's going wrong. I've tried using owner directly in an android module and it works better (to begin with, it doesn't crash). As far as I can tell this is a dependency configuration issue, but I could really use a hand here. This is my build.gradle file for the submodule using the missing class

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

And this is the build.gradle for the android module:

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

I feel like there may be something missing.

Coinhunter
  • 83
  • 1
  • 9

2 Answers2

0

Since ServerConfig extends from org.aeonbits.owner.Config, it won't load if org.aeonbits.owner:owner dependency is missing from the classpath, and the ClassLoader will fail, as in your case. Re-add the dependency and it will work.

Luigi R. Viggiano
  • 8,659
  • 7
  • 53
  • 66
0

In default,third dependenties could not be build in generating jar,in build.gradle,configure jar task like this :

jar{
    baseName = "libdemo"
    version = "1.0"
    manifest {
        attributes ('Main-Class': 'com.example.lib.Main')
    }
    from {
        configurations.extraLibs.collect { it.isDirectory() ? it : zipTree(it) }
    }
}
mickeyyang
  • 455
  • 4
  • 6