vikzilla
(vikzilla)
May 9, 2016, 7:22pm
1
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
vikzilla
(vikzilla)
May 9, 2016, 7:59pm
3
This error means that either the specified class or one of its dependencies is missing.
vikzilla
(vikzilla)
May 9, 2016, 8:26pm
5
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?
vikzilla
(vikzilla)
May 9, 2016, 8:30pm
6
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> ;
vikzilla
(vikzilla)
May 9, 2016, 9:40pm
7
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?
vikzilla
(vikzilla)
May 9, 2016, 9:47pm
8
Ah, I am guessing this could be related to trying to run asynchronous code on the server side.
vikzilla
(vikzilla)
May 9, 2016, 10:04pm
9
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.
vikzilla
(vikzilla)
May 9, 2016, 11:23pm
11
Yes, it properly points to my libs folder
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> ;
vikzilla
(vikzilla)
May 9, 2016, 11:34pm
12
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.
vikzilla
(vikzilla)
May 10, 2016, 12:25am
14
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
It has nothing to do with the problem you’re experiencing. There is a missing dependency…
vikzilla
(vikzilla)
May 10, 2016, 1:35am
16
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.
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.