java.lang.NoClassDefFoundError: io.reactivex.Observable

java.lang.NoClassDefFoundError: io.reactivex.Observable

当我在 API 和 API 21 的 API 改造中使用 Observable 时,我得到了这个错误:

java.lang.NoClassDefFoundError: io.reactivex.Observable

但是在 phone 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);
}

这是我的 Retrofit 设置:

    @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();
    }

我的依赖项:

    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'

终于,我找到了解决方案。

问题是 Rxjava 与 Constrainlayout 冲突

compile 'com.android.support.constraint:constraint-layout:1.0.2'

compile 'io.reactivex:rxjava:1.2.6'