I have integrated the Retrofit library for server calls. I get the below exception when I get a response in retrofit and the app crashes. Unable to understand what's going wrong.
FATAL EXCEPTION: OkHttp Dispatcher
Process: com.eclerx_services.android.fs_security, PID: 9495
java.lang.NoSuchMethodError: No static method metafactory(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; in class Ljava/lang/invoke/LambdaMetafactory; or its super classes (declaration of 'java.lang.invoke.LambdaMetafactory' appears in /apex/com.android.art/javalib/core-oj.jar)
at retrofit2.DefaultCallAdapterFactory$ExecutorCallbackCall$1.onResponse(DefaultCallAdapterFactory.java:82)
at retrofit2.OkHttpCall$1.onResponse(OkHttpCall.java:161)
at okhttp3.RealCall$AsyncCall.run(RealCall.kt:140)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
at java.lang.Thread.run(Thread.java:1012)
public LiveData < ClientValidationModel > getEmployeeCompanyExistance(Map < String, Object > params) {
//isCanceled = false;
final MutableLiveData < ClientValidationModel > data = new MutableLiveData < > ();
if (ConnectionManager.Connection(context)) {
clientValidationModelCall = apiRequest.getEmployeeCompanyExistance(params);
clientValidationModelCall.enqueue(new Callback < ClientValidationModel > () {
@Override
public void onResponse(Call < ClientValidationModel > call, Response < ClientValidationModel > response) {
if (!clientValidationModelCall.isCanceled()) {
ClientValidationModel clientValidationModel = response.body();
if (clientValidationModel != null) {
data.setValue(clientValidationModel);
} else {
Toast.makeText(context, context.getResources().getString(R.string.error_something_went_wrong), Toast.LENGTH_SHORT).show();
data.setValue(null);
}
}
}
@Override
public void onFailure(Call < ClientValidationModel > call, Throwable t) {
if (!clientValidationModelCall.isCanceled()) {
Toast.makeText(context, t.getMessage(), Toast.LENGTH_SHORT).show();
data.setValue(null);
}
}
});
} else {
Toast.makeText(context, context.getResources().getString(R.string.error_something_went_wrong), Toast.LENGTH_SHORT).show();
data.setValue(null);
}
return data;
}
This is the API call & get response function, where it doesn't enter into the onResponse
callback at all. It is crashing on the enqueue
call itself.
The API is working fine in Postman and another app as well.
These are the dependencies I am using:
// retrofit
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'com.squareup.okhttp3:logging-interceptor:4.3.1'
I really appreciate any help you can provide!
I have resolved this by downgrading the retrofit dependencies from this
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'com.squareup.okhttp3:logging-interceptor:4.3.1'
to this
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'