使用rxjava-android的问题

时间:2013-12-01 14:48:02

标签: android gradle android-gradle

我正在尝试在我使用gradle的项目中使用Rxjava。我没有任何编译错误,但当我运行项目我的应用程序崩溃。

12-01 14:40:41.553    1015-1015/? I/dalvikvm﹕ Could not find method rx.Subscription.unsubscribe, referenced from method com.flipper83.protohipster.view.feed.ui.HipsterListFragment.onPause
12-01 14:40:41.553    1015-1015/? W/dalvikvm﹕ VFY: unable to resolve interface method 11579: Lrx/Subscription;.unsubscribe ()V
12-01 14:40:41.553    1015-1015/? D/dalvikvm﹕ VFY: replacing opcode 0x72 at 0x0005
12-01 14:40:41.553    1015-1015/? W/dalvikvm﹕ VFY: unable to find class referenced in signature (Lrx/Observable;)
12-01 14:40:41.565    1015-1015/? I/dalvikvm﹕ Could not find method rx.concurrency.Schedulers.newThread, referenced from method com.flipper83.protohipster.view.feed.ui.HipsterListFragment.onResume
12-01 14:40:41.565    1015-1015/? W/dalvikvm﹕ VFY: unable to resolve static method 11581: Lrx/concurrency/Schedulers;.newThread ()Lrx/Scheduler;
12-01 14:40:41.569    1015-1015/? D/dalvikvm﹕ VFY: replacing opcode 0x71 at 0x0014
12-01 14:40:41.569    1015-1015/? I/dalvikvm﹕ Failed resolving Lcom/flipper83/protohipster/view/feed/ui/HipsterListFragment$1; interface 2027 'Lrx/Observer;'
12-01 14:40:41.569    1015-1015/? W/dalvikvm﹕ Link of class 'Lcom/flipper83/protohipster/view/feed/ui/HipsterListFragment$1;' failed
12-01 14:40:41.569    1015-1015/? D/dalvikvm﹕ DexOpt: unable to opt direct call 0x148a at 0x1e in Lcom/flipper83/protohipster/view/feed/ui/HipsterListFragment;.onResume
12-01 14:40:41.577    1015-1015/? W/dalvikvm﹕ VFY: unable to find class referenced in signature (Lrx/Observer;)
12-01 14:40:41.577    1015-1015/? W/dalvikvm﹕ VFY: unable to find class referenced in signature (Lrx/Observer;)
12-01 14:40:41.577    1015-1015/? I/dalvikvm﹕ Could not find method rx.Observer.onNext, referenced from method com.flipper83.protohipster.view.feed.model.FeedViewModel.notifyFeed
12-01 14:40:41.577    1015-1015/? W/dalvikvm﹕ VFY: unable to resolve interface method 11578: Lrx/Observer;.onNext (Ljava/lang/Object;)V
12-01 14:40:41.577    1015-1015/? D/dalvikvm﹕ VFY: replacing opcode 0x72 at 0x0028
12-01 14:40:41.577    1015-1015/? I/dalvikvm﹕ Failed resolving Lcom/flipper83/protohipster/view/feed/model/FeedViewModel$1; interface 2025 'Lrx/Observable$OnSubscribeFunc;'
12-01 14:40:41.577    1015-1015/? W/dalvikvm﹕ Link of class 'Lcom/flipper83/protohipster/view/feed/model/FeedViewModel$1;' failed
12-01 14:40:41.577    1015-1015/? E/dalvikvm﹕ Could not find class 'com.flipper83.protohipster.view.feed.model.FeedViewModel$1', referenced from method com.flipper83.protohipster.view.feed.model.FeedViewModel.populateFeed
12-01 14:40:41.581    1015-1015/? W/dalvikvm﹕ VFY: unable to resolve new-instance 794 (Lcom/flipper83/protohipster/view/feed/model/FeedViewModel$1;) in Lcom/flipper83/protohipster/view/feed/model/FeedViewModel;
12-01 14:40:41.581    1015-1015/? D/dalvikvm﹕ VFY: replacing opcode 0x22 at 0x0000
12-01 14:40:41.581    1015-1015/? I/dalvikvm﹕ Failed resolving Lcom/flipper83/protohipster/view/feed/model/FeedViewModel$1; interface 2025 'Lrx/Observable$OnSubscribeFunc;'
12-01 14:40:41.581    1015-1015/? W/dalvikvm﹕ Link of class 'Lcom/flipper83/protohipster/view/feed/model/FeedViewModel$1;' failed
12-01 14:40:41.581    1015-1015/? D/dalvikvm﹕ DexOpt: unable to opt direct call 0x145d at 0x02 in Lcom/flipper83/protohipster/view/feed/model/FeedViewModel;.populateFeed
12-01 14:40:41.585    1015-1015/? D/AndroidRuntime﹕ Shutting down VM
12-01 14:40:41.585    1015-1015/? W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xa62ca288)
12-01 14:40:41.585    1015-1015/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.NoClassDefFoundError: com.flipper83.protohipster.view.feed.model.FeedViewModel$1
            at com.flipper83.protohipster.view.feed.model.FeedViewModel.populateFeed(FeedViewModel.java:43)

我认为问题来自gradle。这是我的gradle build.xml。

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.6.+'
    }
}
apply plugin: 'android'

repositories {
    mavenCentral()
    flatDir {
        dirs 'lib'
    }
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.0"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 19
    }

    sourceSets {
        main {
            assets.srcDirs = ['assets']
        }
    }

}

dependencies {
    compile 'com.squareup.picasso:picasso:2+'
    compile 'com.squareup.dagger:dagger-compiler:1.1.0'
    compile 'com.squareup.dagger:dagger:1.1.0'
    compile 'com.android.support:support-v4:18.0.+'
    compile 'com.squareup.retrofit:retrofit:1.2.+'
    compile 'com.netflix.rxjava:rxjava-android:0.14.+'
    compile files('lib/Parse-1.3.8.jar')
}

任何想法?

3 个答案:

答案 0 :(得分:2)

是的,我修好了:

compile 'com.netflix.rxjava:rxjava-core:0.+'
compile 'com.netflix.rxjava:rxjava-android:0.+'
compile 'com.squareup.retrofit:retrofit:1.5.0'

在我的 build.gradle

谢谢

答案 1 :(得分:2)

compile 'com.netflix.rxjava:rxjava-core:0.+'是暂时的依赖 compile 'com.netflix.rxjava:rxjava-android:0.+'Gradle automatics已解决此依赖关系并下载

答案 2 :(得分:1)

基于 ReactiveX / RxAndroid https://github.com/ReactiveX/RxAndroid

最好同时使用android和java依赖项:

compile 'io.reactivex:rxandroid:1.0.1'
// Because RxAndroid releases are few and far between, it is recommended you also
// explicitly depend on RxJava's latest version for bug fixes and new features.
compile 'io.reactivex:rxjava:1.0.14'