IncompatibleClassChangeError ...应该是直接类型,但是发现它是virtual类型

时间:2016-12-20 16:12:31

标签: java lambda rx-java

我正在使用RxJava,现在我试图通过给lambda来订阅一个observable:

observableProvider.stringForKey(CURRENT_DELETED_ID)
    .subscribe(str -> this.elementDeleted(str));

问题是,我收到了这个有趣的错误:

The method 'void elementDeleted(String)' was expected to be of type direct but instead was found to be of type virtual (declaration of 'java.lang.reflect.ArtMethod' appears in /system/framework/core-libart.jar)

该功能如下:

private elementDeleted(String elemId) {
    // removing element from some lists
    this.updateView();
}

将函数elementDeleted(String)设置为public是有帮助的,但是我在调​​用函数updateUser时遇到了同样的错误。所以要解决这个问题,我必须将从该点调用的所有函数都设置为public。这不是解决方案。

即使我尝试提供这样的函数引用:

observableProvider.stringForKey(CURRENT_DELETED_ID)
    .subscribe(this::elementDeleted);

没用。而且我认为它甚至没有使用公共功能。

我希望你能帮助我。

修改 这是我的gradle文件:

apply plugin: 'com.android.application'
apply plugin: 'realm-android'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'dexguard'

android {

    buildToolsVersion '24.0.1'
    compileSdkVersion 24

    defaultConfig {
        applicationId "com.myapp.isthebest"
        minSdkVersion 21
        targetSdkVersion 24
        versionCode 380
        versionName "0.1.8"

        renderscriptTargetApi 18
        renderscriptSupportModeEnabled true

        vectorDrawables.useSupportLibrary = true

    }

    buildTypes {
        debug {
            proguardFile getDefaultDexGuardFile('dexguard-debug.pro')
            proguardFile 'proguard-project.pro'
            proguardFile 'proguard-project-debug.pro'
            ndk {
                abiFilters = ['armeabi-v7a', 'x86']
            }
            jniDebuggable true
        }
        release {
            proguardFile getDefaultDexGuardFile('dexguard-release-aggressive.pro')
            proguardFile 'proguard-project.pro'
            proguardFile 'proguard-project-release.pro'
            signingConfig signingConfigs.release
            lintOptions {
                disable 'MissingTranslation'
            }
            ndk {
                abiFilters = ['armeabi-v7a']
            }
        }
        beta {
            proguardFile getDefaultDexGuardFile('dexguard-release-aggressive.pro')
            proguardFile 'proguard-project.pro'
            proguardFile 'proguard-project-release.pro'
            proguardFile 'proguard-project-beta.pro'
            signingConfig signingConfigs.release
            lintOptions {
                disable 'MissingTranslation'
            }
            ndk {
                abiFilters = ['armeabi-v7a']
            }
        }
    }

    dexOptions {
        javaMaxHeapSize "4g"
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/DEPENDENCIES'
    }

    dataBinding {
        enabled = true
    }

    testOptions {
        unitTests.returnDefaultValues = true
    }

    lintOptions {
        abortOnError false
    }

}


dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:24.1.1'
    compile 'com.android.support:design:24.1.1'
    compile 'com.android.support:recyclerview-v7:24.1.1'
    compile 'com.android.support:cardview-v7:24.1.1'
    compile 'com.android.support:support-v4:24.1.1'
    compile 'com.android.support:multidex:1.0.1'
    compile 'org.functionaljava:functionaljava:4.4'
    compile 'fr.avianey.com.viewpagerindicator:library:2.4.1@aar'
    compile 'io.reactivex:rxjava:1.1.6'
    compile 'com.squareup.picasso:picasso:2.6.0-20161009.170155-29'
    compile 'com.appyvet:materialrangebar:1.3'
    compile 'com.google.code.gson:gson:2.4'
    compile 'commons-codec:commons-codec:1.10'
    compile 'commons-io:commons-io:2.4'
    compile 'org.apache.commons:commons-collections4:4.1'
    compile 'org.apache.commons:commons-lang3:3.4'
    compile 'com.amazonaws:aws-android-sdk-core:2.2.20'
    compile 'com.amazonaws:aws-android-sdk-cognito:2.2.20'
    compile 'com.amazonaws:aws-android-sdk-s3:2.2.20'
    compile 'com.amazonaws:aws-android-sdk-ddb:2.2.20'
    compile 'com.amazonaws:aws-android-sdk-ddb-mapper:2.2.20'
    compile 'net.hockeyapp.android:HockeySDK:4.0.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4'
    compile 'us.feras.mdv:markdownview:1.1.0'
    compile 'ly.count.android:sdk:16.06.03'
    compile 'com.theartofdev.edmodo:android-image-cropper:2.3.1'
    compile 'com.nulab-inc:zxcvbn:1.1.4'
    compile 'com.neovisionaries:nv-websocket-client:1.30'
    compile 'com.squareup.retrofit2:retrofit:2.1.0'
    compile 'com.squareup.retrofit2:converter-gson:2.1.0'
    compile 'com.github.pwittchen:reactivenetwork:0.5.2'
    testCompile 'com.squareup.retrofit2:retrofit-mock:2.1.0'
    testCompile 'junit:junit:4.12'
    testCompile 'org.robolectric:robolectric:3.0'
    testCompile 'org.mockito:mockito-core:1.9.5'
    testCompile 'org.powermock:powermock-module-junit4:1.6.1'
    testCompile 'org.powermock:powermock-api-mockito:1.6.1'
    provided 'com.google.auto.value:auto-value:1.2'
    apt "com.google.auto.value:auto-value:1.2"

    apt 'com.ryanharter.auto.value:auto-value-gson:0.4.3'
    provided 'com.ryanharter.auto.value:auto-value-gson:0.4.3'

    compile 'com.google.dagger:dagger:2.7'
    apt "com.google.dagger:dagger-compiler:2.7"
    provided 'javax.annotation:jsr250-api:1.0'
    compile 'javax.inject:javax.inject:1'
    testCompile 'com.google.dagger:dagger:2.7'
    testApt "com.google.dagger:dagger-compiler:2.7"
    testProvided 'javax.annotation:jsr250-api:1.0'
    testCompile 'javax.inject:javax.inject:1'
    compile files('libs/dexguard-runtime.jar')
    compile ':securekeyboard-runtime:@aar'
}

afterEvaluate {
    dexguardRelease.logging.level = 'INFO'
}

1 个答案:

答案 0 :(得分:1)

我看到你正在为android构建,所以可能的问题如下:build set minSdkVersion 21 - android 5棒棒糖和java 8的targetCompatibility - 从sdk 24开始支持(非常有限),从而导致你的构建问题。您可以通过三种方式解决此问题:

1)为minSdkVersion 24构建,定位为实体0.4% 设备

2)摆脱java 8功能并设置源代码/目标兼容性到java 7

3)使用java 8特性并使用retrolambda构建(有一些限制,存在于lib自述文件中)