java.lang.NoClassDefFoundError:io.reactivex.Observable

Moh*_*ari 7 api android retrofit rx-android rx-java2

当我在带有API 21的手机上的改装API中使用Observable时出现此错误:

java.lang.NoClassDefFoundError: io.reactivex.Observable
Run Code Online (Sandbox Code Playgroud)

但是在使用API​​ 19的电话或使用API​​ 23的模拟器上它可以工作.

这是我的API接口:

import io.reactivex.Observable;
import retrofit2.Response;
import retrofit2.http.Body;
import retrofit2.http.POST;
public interface ApiService {
    /**
     * Created by Mohsen on 5/10/2017.
     *
     */
    @POST("/cp/api/")
    Observable<Response<Integer>> Get_BuyBox_Count(@Body Object request);
}
Run Code Online (Sandbox Code Playgroud)

这是我的改造设置:

    @Provides
    @Application_Scope
    @Store_Retrofit_Qualifier
    public Retrofit Store_retrofit(OkHttpClient client) {
        return new Retrofit.Builder()
                .baseUrl(Urls.Sotre_Base_Url)
                .client(client)
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .addConverterFactory(JSONConverterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
Run Code Online (Sandbox Code Playgroud)

我的依赖:

    compile 'com.squareup.retrofit2:retrofit:2.2.0'
    compile 'com.squareup.retrofit2:converter-gson:2.1.0'
    compile 'io.reactivex.rxjava2:rxjava:2.0.1'
    compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
    compile 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
Run Code Online (Sandbox Code Playgroud)

Moh*_*ari 5

最后,过了一会儿我找到了解决方案。

问题是与Constrainlayout冲突Rxjava

compile 'com.android.support.constraint:constraint-layout:1.0.2'
Run Code Online (Sandbox Code Playgroud)

compile 'io.reactivex:rxjava:1.2.6'
Run Code Online (Sandbox Code Playgroud)

  • 这两个库之间到底有什么关系? (4认同)