Sybit-Education / airtable.java

Java API for Airtable (http://www.airtable.com)
MIT License
48 stars 25 forks source link

Android HTTP AllowAllHostnameVerifier Error #40

Closed SaeedAlRahma closed 4 years ago

SaeedAlRahma commented 4 years ago

Hey, I'm running into this HTTP error when I attempt to initialize and configure the Airtable object. Seems like it's common problem from my search online but I'm not familiar with HTTP so I'm still not sure how to resolve this issue. I'm running the app on an Pixel 3 API 29 emulator using Android Studio 3.5.1. I'm using airtable.java version 0.2.0. Is my project somehow using the wrong Apache HTTP library?

Updated: I see that there's an android port here https://github.com/Sybit-Education/airtable.android but I don't know how to apply it. Could provide some instructions or point me to an article please?

Here is my code (inside onCreate of MainActivity):

    // Initialize Airtable
    try {
        Airtable airtable = new Airtable();
        airtable.configure(AIRTABLE_API_KEY); // Runtime crash happens in this call
    } catch (AirtableException e) {
        e.printStackTrace();
    }

And this is the error I get: E/AndroidRuntime: FATAL EXCEPTION: main Process: saeed.org.recipeat, PID: 15322 java.lang.NoSuchFieldError: No static field INSTANCE of type Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier; in class Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier; or its superclasses (declaration of 'org.apache.http.conn.ssl.AllowAllHostnameVerifier' appears in /system/framework/framework.jar!classes3.dex) at org.apache.http.conn.ssl.SSLConnectionSocketFactory.<clinit>(SSLConnectionSocketFactory.java:146) at org.apache.http.conn.ssl.SSLConnectionSocketFactory.getSocketFactory(SSLConnectionSocketFactory.java:174) at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.getDefaultRegistry(PoolingHttpClientConnectionManager.java:115) at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:122) at com.mashape.unirest.http.options.Options.refresh(Options.java:72) at com.mashape.unirest.http.options.Options.<clinit>(Options.java:46) at com.mashape.unirest.http.options.Options.setOption(Options.java:35) at com.mashape.unirest.http.Unirest.setProxy(Unirest.java:65) at com.sybit.airtable.Airtable.setProxy(Airtable.java:185) at com.sybit.airtable.Airtable.configureProxy(Airtable.java:213) at com.sybit.airtable.Airtable.configure(Airtable.java:155) at com.sybit.airtable.Airtable.configure(Airtable.java:113) at com.sybit.airtable.Airtable.configure(Airtable.java:100) at saeed.org.recipeat.MainActivity.onCreate(MainActivity.java:45) at android.app.Activity.performCreate(Activity.java:7802) at android.app.Activity.performCreate(Activity.java:7791) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7356) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

SaeedAlRahma commented 4 years ago

After researching, I learned that Android seems to not work with the Apache HTTP library. I used the port provided by the same author here https://github.com/Sybit-Education/airtable.android

I'm not sure what is the "right" way of using it but this is what I did: 1) Get the repo files 2) Copy all source inside src/main/java into your project source directory 3) Copy all libs inside libs directory inside your project libs directory 3a) I noticed a conflict between the libraries so I have to open one of them using 7zip and delete org.apache.commons because it was a duplicate 4) Update build.gradle dependencies as in the repo.

Now you should be able to use the airtable java api as described on this repo.