adequate
adequate
adequate
adequate
 

JPPF, java, parallel computing, distributed computing, grid computing, parallel, distributed, cluster, grid, cloud, open source, android, .net
JPPF

The open source
grid computing
solution

 Home   About   Features   Download   Documentation   Forums 
September 19, 2018, 03:12:59 AM *
Welcome,
Please login or register.

Login with username, password and session length
Advanced search  
News: New users, please read this message. Thank you!
  Home Help Search Login Register  
Pages: [1]   Go Down

Author Topic: Using Dropbox in an Android Task  (Read 450 times)

Ognjen19872

  • JPPF Padawan
  • *
  • Posts: 6
Using Dropbox in an Android Task
« on: June 07, 2016, 10:04:33 PM »

Hy Guys,

It's me again with another question:
is it somehow possible to use the Dropbox API within an Android Task?

I started to try with the dropbox-core-api and also somehow used the Android-side Api.
When I take a look at the log-output it mainly looks like this:

06-07 21:57:13.478: V/DefaultAndroidNodeIntegration(6768): starting job 'Processing: IMG-0003-00001.jpg'
06-07 21:57:13.482: V/DefaultAndroidNodeIntegration(6768): ending job 'Processing: IMG-0003-00001.jpg'
06-07 21:57:13.483: I/System.out(6768): Attempting connection to the node server at 192.168.0.17:11111
06-07 21:57:13.540: I/System.out(6768): Reconnected to the node server

The problem is that I put some Sysouts around the Dropbox-lines and they are not printed here.

You have any suggestions what could be wrong here? Is there some kind of Timeout for the job execution maybe?



best regards

PS: After the server reconnection the task is again propagated to the phone. So in conclusion the same task was executed 3 times or something

« Last Edit: June 07, 2016, 10:06:27 PM by Ognjen19872 »
Logged

lolo

  • Administrator
  • JPPF Council Member
  • *****
  • Posts: 2240
    • JPPF Web site
Re: Using Dropbox in an Android Task
« Reply #1 on: June 08, 2016, 12:45:50 PM »

Hello,

Assuming you're using the Android demo as a template, I suspect this is an issue with class loading: you probably do not have the drop box jar(s) bundled with the dex-ed jar.
I gave it a try, starting from the demo code. I modified the task like this:

Code: [Select]
public class DropboxTask extends AbstractTask<String> {
  private transient DropboxAPI<AndroidAuthSession> mDBApi;

  @Override
  public void run() {
    System.out.println("starting DropboxTask");
    AppKeyPair appKeys = new AppKeyPair("APP_KEY", "APP_SECRET");
    AndroidAuthSession session = new AndroidAuthSession(appKeys);
    mDBApi = new DropboxAPI<>(session);
    System.out.println("I am a demo Android task !!!");
    setResult("demo Android task successful");
  }
}

Please note the transient modifier for "mDBApi": its class is not serializable and would prevent the node from sending the task back to the server.

For this to compile, I also added these jars: dropbox-android-sdk-1.6.3.jar and json_simple-1.1.jar (If you use Android-specific APIs, then you also need to add android.jar).
Now, running "ant dex.jar" produces a dex-ed jar that only contains the DropboxTask class, so you are missing the dropbox API classes.

To fix that, I changed the build.xml as follows:

- the original "dex" macrodef takes a single jar file as input, due to the argument <arg value="@{in}"/>. Instead, I used an option that takes a file containing a list of jars to include: <arg value="--input-list=@{in}"/>. I also created a file "dex-input.txt" with this content:
Code: [Select]
demo.jar
lib/dropbox-android-sdk-1.6.3.jar
lib/json_simple-1.1.jar

- the macrodef is now like this:
Code: [Select]
  <macrodef name="dex">
    <attribute name="in"/>
    <attribute name="out"/>
    <attribute name="toolsDir" default="${android.tools.home}"/>
    <sequential>
      <!-- compute the name of the dex command based on the OS -->
      <local name="cmd"/>
      <condition property="cmd" value="dx.bat" else="dx">
        <os family="windows"/>
      </condition>
      <!-- execute the dex command -->
      <exec executable="@{toolsDir}/${cmd}" failonerror="true" searchpath="true">
        <arg value="--dex"/>
        <arg value="--output=@{out}"/>
        <arg value="--input-list=@{in}"/>
      </exec>
    </sequential>
  </macrodef>

- finally, I changed the "dex.jar" target so that it provides the input list instead of a jar file:
Code: [Select]
  <target name="dex.jar" depends="jar" description="dex">
    <delete file="dex-demo.jar" quiet="true"/>
    <dex in="dex-input.txt" out="dex-demo.jar"/>
    <delete file="demo.jar" quiet="true"/>
    <printmsg message="The file dex-demo.jar is now ready to be deployed"/>
  </target>

With this, a correct dexed jar file is generated and can be used by the application.

I hope this helps,
-Laurent
Logged

Ognjen19872

  • JPPF Padawan
  • *
  • Posts: 6
Re: Using Dropbox in an Android Task
« Reply #2 on: June 13, 2016, 11:02:38 PM »

Hy Laurent,

Thanks for your reply. The thing is that I'm using Maven for my whole dependency management.
Do you know wether the libraries are then included by automatically or should i still provide the list for adding
the *.jar files?

best regards,
ognjen
Logged

lolo

  • Administrator
  • JPPF Council Member
  • *****
  • Posts: 2240
    • JPPF Web site
Re: Using Dropbox in an Android Task
« Reply #3 on: June 14, 2016, 01:27:00 PM »

Hello,

If you use Maven for your builds, then you might want to consider the android-maven-plugin's dex mojo instead of our Android demo's Ant script. I believe this should allow you to create a dex jar from maven artifacts instead of straight jar files.

Sincerely,
-Laurent
Logged
Pages: [1]   Go Up
 
JPPF Powered by SMF 2.0 RC5 | SMF © 2006–2011, Simple Machines LLC Get JPPF at SourceForge.net. Fast, secure and Free Open Source software downloads