从外部库访问内部类时的NoClassDefFoundError

时间:2015-04-04 18:11:58

标签: java android gradle

我有一个使用库的应用程序,其中包含外部JAR - Cardboard SDK。

App编译但在运行时我得到NoClassDefFoundError - 它无法从纸板SDK中找到内部类CardboardDevice$DeviceParams

完整堆栈跟踪:

java.lang.NoClassDefFoundError: com.google.vrtoolkit.cardboard.proto.CardboardDevice$DeviceParams
        at com.google.vrtoolkit.cardboard.CardboardDeviceParams.createFromInputStream(CardboardDeviceParams.java:273)
        at com.google.vrtoolkit.cardboard.HeadMountedDisplayManager.createCardboardDeviceParamsFromExternalStorage(HeadMountedDisplayManager.java:247)
        at com.google.vrtoolkit.cardboard.HeadMountedDisplayManager.createCardboardDeviceParams(HeadMountedDisplayManager.java:200)
        at com.google.vrtoolkit.cardboard.HeadMountedDisplayManager.<init>(HeadMountedDisplayManager.java:54)
        at com.google.vrtoolkit.cardboard.CardboardView.init(CardboardView.java:793)
        at com.google.vrtoolkit.cardboard.CardboardView.<init>(CardboardView.java:262)
        at org.androidworks.villagevr.villagevr.BaseVRActivity.onCreate(BaseVRActivity.java:65)
        at android.app.Activity.performCreate(Activity.java:5933)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
        at android.app.ActivityThread.access$800(ActivityThread.java:144)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5221)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

图书馆build.gradle

apply plugin: 'com.android.library'

android {
    compileSdkVersion 21
    buildToolsVersion "19.1.0"

    defaultConfig {
        //applicationId "org.androidworks.vrcommon"
        minSdkVersion 9
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
}

dependencies {
//    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile files('libs/cardboard.jar')
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile project(':LiveWallpaperTulipsCommon')
}

申请build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "19.1.0"

    defaultConfig {
        applicationId "org.androidworks.villagevr.villagevr"
        minSdkVersion 9
        targetSdkVersion 21
        versionCode 15
        versionName "1.5"
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile project(':LiveWallpaperTulipsCommon')
    compile project(':LiveWallpaperVillageCommon')
    compile project(':VRCommon')
}

1 个答案:

答案 0 :(得分:2)

Cardboard SDK包含一个libprotobuf jar文件。确保它存在并包含在您的构建中。