retrofit2

ExceptionInInitializerError in Okhttp.Builder w/ Multidex & Kitkat

♀尐吖头ヾ 提交于 2019-12-05 08:11:16
I'm experiencing an ExceptionInInitializerError exception on VM running Kitkat 4.4.2 with Multidex enabled. java.lang.ExceptionInInitializerError at okhttp3.OkHttpClient.newSslSocketFactory(OkHttpClient.java:263) at okhttp3.OkHttpClient.<init>(OkHttpClient.java:229) at okhttp3.OkHttpClient$Builder.build(OkHttpClient.java:1015) at myapp.utils.Utils.getHttpClientBuilder(Utils.java:131) at myapp.fragments.FragmentHome.getHome(FragmentHome.java:326) at myapp.fragments.FragmentHome.onViewCreated(FragmentHome.java:135) I have the following libraries: implementation 'jp.wasabeef:recyclerview

Handling Error RXJava Android with Kotlin

你说的曾经没有我的故事 提交于 2019-12-05 07:12:20
Hi I'm new with RxJava and Kotlin and I loose some concepts about it. I have "api" like this: interface VehiclesService { @GET("/vehicles/") fun getVehicles(): Single<List<Vehicle>> } Then I create the retrofit client, etc.. like this: var retrofit = RetrofitClient().getInstance() vehiclesAPI = retrofit!!.create(VehiclesService ::class.java) finally I do the call: private fun fetchData() { compositeDisposable.add(vehiclesAPI .getVehicles() .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe { vehicles -> displayData(vehicles) } ) } And here is where I have the

Unable to parse error in Retrofit 2

怎甘沉沦 提交于 2019-12-05 06:44:08
I am using Retrofit 2 and I am getting a null pointer exception at this line: RetrofitClient.APIError error = RetrofitClient.ErrorUtils.parseError(response, retrofit); The error is null. More details: This is the format that the API returns the error in: { "error": { "message": "Incorrect credentials", "statusCode": 401 } } Here is my login Callback code: new Callback<LoginResponse>() { @Override public void onResponse(Response<LoginResponse> response, Retrofit retrofit) { if (listener != null) { if (response.isSuccess() && response.body() != null) { User user = RetrofitUserToUserMapper

Cannot POST multipart data from retrofit 2

烂漫一生 提交于 2019-12-05 05:41:26
I have to send a post request in this format. --__X_PAW_BOUNDARY__ Content-Disposition: form-data; name="user_photo[image]"; filename="file.jpg" Content-Type: image/jpeg ÿØÿàJFIFHHÿáLExifMM*i ÿí8Photoshop 3.08BIM8BIM%ÔÙ²é ìøB~ÿÀ "ÿÄ ÿĵ}!1AQa"q2¡#B±ÁRÑð$3br %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz¢£¤¥¦§¨©ª²³´µ¶·¸¹ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖרÙÚáâãäåæçèéêñòóôõö÷øùúÿÄ ÿĵw!1AQaq"2B¡±Á #3RðbrÑ $4á%ñ&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz¢£¤¥¦§¨©ª²³´µ¶·¸¹ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖרÙÚâãäåæçèéêòóôõö÷øùúÿÛC ÿÛC ÿÝZÿÚ?ü_¢+þæð¢(¢(¢(¢(¢(¢(¢(¢(¢(¢(¢(¢(¢(¢(¢(¢(¢(¢(¢(¢(¢(¢(¢(¢(¢(¢(¢(¢(¢(¢(¢(¢(¢(¢(¢(¢(¢(¢(¢(¢(¢(¢(¢(¢(¢(

Dagger2 cannot access nullable. javax.annotation.Nullable not found

烈酒焚心 提交于 2019-12-05 05:08:48
I have a module to provide a Retrofit interface. @Module class NetModule(val base: String) { @Provides @Singleton fun provideOkHttpClient(): OkHttpClient { return OkHttpClient.Builder() .addInterceptor(object: Interceptor { override fun intercept(chain: Interceptor.Chain): Response { val request = chain.request() info("Request for ${request.url()}") return chain.proceed(request) } }).build() } @Provides @Singleton fun provideGson(): Gson { return GsonBuilder() .enableComplexMapKeySerialization() .serializeNulls() .setPrettyPrinting() .setLenient() .create() } @Provides @Singleton fun

HTTP/2 protocol not working with okhttp

走远了吗. 提交于 2019-12-04 23:35:05
I am using Retrofit 1.9 with okhttp 2.4.0. So far we have SPDY protocol disabled on server side (I checked it by this ). And enabled protocol on server side is HTTP/2 (I checked it by this ). So I was thinking that okhttp will try to make an api call using HTTP/2 (latest one protocol) but it's using HTTP/1.1 on android device 4.2.2 samsung S4 - D/Retrofit : OkHttp-Selected-Protocol: http/1.1 Someone told me that android device doesn't support SPDY until 5.0 (I don't have any proof), so that device never attempted to use a SPDY connection. But I am sure that our server not using SPDY at all I

RxJavaCallAdapterFactory cannot be converted to Factory

北战南征 提交于 2019-12-04 23:31:32
I'm trying to use Retrofit 2 and RxJava following the guide in this https://inthecheesefactory.com/blog/retrofit-2.0/en In section "RxJava Integration with CallAdapter " explains how use RxJava with retrofit Retrofit retrofit = new Retrofit.Builder() .baseUrl("http://api.nuuneoi.com/base/") .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) .build(); However during compilation there is the following error: Error:(63, 71) error: incompatible types: RxJavaCallAdapterFactory cannot be converted to Factory How can I fix it? Thanks Make

RxJava : How to handle error with zip operator ?

偶尔善良 提交于 2019-12-04 22:29:39
I am using RxJava and RxAndroid with Retrofit2. Observable<ResponseOne> responseOneObservable = getRetrofitClient().getDataOne() .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()); Observable<ResponseTwo> responseTwoObservable = getRetrofitClient().getDataTwo() .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()); Using zip operator as below on above two Observer. Observable<ArrayList<TestData>> testDataObservable = Observable.zip(responseOneObservable, responseTwoObservable, new Func2<ResponseOne, ResponseTwo, ArrayList<TestData>>() { @Override public

Retrofit 2.0 headers authentication

北慕城南 提交于 2019-12-04 21:40:32
问题 private void setUpRestClient() { OkHttpClient client = new OkHttpClient(); client.interceptors().add(new Interceptor() { @Override public Response intercept(Chain chain) throws IOException { Request original = chain.request(); Request request = original.newBuilder() .header("Accept", "application/pyur.v1") .header("Authorization", new SharedPreferencesUtil(getBaseContext()).getToken()) .header("Content-Type", "application/json") .method(original.method(),original.body()) .build(); return

Retrofit 2 returns null in release APK when minifyenable but ok in debug APK

♀尐吖头ヾ 提交于 2019-12-04 21:16:31
问题 Getting null response but code 200 with Release APK when minify enable, when minify false then its ok. But Getting expected response with debug APK when minify enable. 回答1: Problem solved :) No issue with proguard-rules no need to add anything extra. Needed to add SerializedName annotation if minifyEnabled even if variable name same as key. That was the only Model which i had created manually :P Which works fine in Debug but not after Signed in. :) 回答2: You need to setup proguard-rule for