Adding library to Business Logic project

I am trying to use a 3rd-Party library with my Business Logic code; it is this one here: okhttp

Normally with an Android Studio project I just add it to the gradle. But I’m unsure how to integrate it here with the project / code generated by Backendless.

Thank you

See step 2 under “Customizing and Running Code”

https://backendless.com/documentation/business-logic/java/bl_getting_started.htm

I’ve added the JAR to my libs folder, however when I try to deploy my code I get an error:

http://support.backendless.com/public/attachments/6ef92d6837cd2f1e8284514a4d540034.png</img>

This error means that either the specified class or one of its dependencies is missing.

I added the JAR for the library to the libs folder as suggested. It appears to all be there:

http://support.backendless.com/public/attachments/a2ee8cad02cef67a0a4654c56f86624e.png</img>
Is there something extra I need to be doing for this to work when deploying to the server as I am attempting to do?

a2ee8cad02cef67a0a4654c56f86624e.png

I am thinking maybe I did not add the library correctly, because when I ran the code locally I got a similar error:

http://support.backendless.com/public/attachments/ccdc2a847be4db36bfadfd1daee507c8.png</img>

Here’s the code I am trying to deploy:

@Override
public void execute( String appVersionId ) throws Exception
{
  String apiKey = "6e46fb2e1acef97d5bb8b75d4e5c9e5a";
  String forecastUrl = "https://api.forecast.io/forecast/" + apiKey + "/" + "41.9484" + "," + "-87.6553";


  OkHttpClient client = new OkHttpClient();


  Request request = new Request.Builder()
          .url(forecastUrl)
          .build();
  Call call = client.newCall(request);


  call.enqueue(new Callback() {
    @Override
    public void onFailure(Call call, IOException e) {


    }


    @Override
    public void onResponse(Call call, Response response) throws IOException {


    }
  });
}

I am able to deploy it when I comment out any references to the Callback class. Which I find odd because why can I deploy when referencing other classes from the same library?

Ah, I am guessing this could be related to trying to run asynchronous code on the server side.

Unfortunately I got this error back when I tried running synchronously:

Caused by: java.lang.NoClassDefFoundError: okhttp3/OkHttpClient

So still wondering if I am importing the library incorrectly.

    Check the "location.jar" property in in bin/runner.properties. It must point to your libs folder. Make sure that all other JAR dependent files that the jar you put in there are also available in the libs folder.
  1. Yes, it properly points to my libs folder

  2. I believe they are all available in the libs folder, as this is the only JAR I added:

http://support.backendless.com/public/attachments/22da1a3a19a0f8d097d6d69399b04874.png</img>

22da1a3a19a0f8d097d6d69399b04874.png

Here’s a more detailed look at the error I get back from the server when the code runs / is locally debugged through code runner:

http://support.backendless.com/public/attachments/abb0e79fbe06059471a1ce00903dcfd8.png</img>

A dependency is missing. Do you research and find out what other JARs okhttp depends on.

I noticed it says my JAVA_HOME and JRE_HOME are not set:

http://support.backendless.com/public/attachments/c7231f7f2b88641bf7bdb2c02823268d.png</img>

Wondering if this could be related and how to fix it, thanks

c7231f7f2b88641bf7bdb2c02823268d.png

It has nothing to do with the problem you’re experiencing. There is a missing dependency…

I seem to have resolved the JAR issue, but it now claims my code is using thread manipulation:

http://support.backendless.com/public/attachments/a3dda380e669b7a5173b1147584391e9.png</img>

However, the line it’s referencing does not open a new thread; it is synchronous (as recommended here):

Response response = client.newCall(request).execute();

I am unsure why the server is telling me I am attempting thread manipulation if I am using a synchronous method.

a3dda380e669b7a5173b1147584391e9.png

Look at the stack trace. The new thread is created in okhttp3.ConnectionPool.put (line 134)

For future reference: You’ll also need Okio, which OkHttp uses for fast I/O and resizable buffers.