2

my question is simple enough. I am using Gluon's plugin for Eclipse and developing an application in JavaFX to run on Android. However, I need to use an Android library (.aar format) and after a while of trying, cannot. Does anybody know how I can do this? I have already tried just using the classes.jar inside the .aar, while this has sort of worked, there are a few resources and things I believe the library is missing that is essential to its function. Thank you.

Edit: The library I'm trying to use is CloudRail, the download is here (Direct download) Currently, using the classes from the extracted classes.jar it is somewhat functional but when the activity from their library is launched (com.cloudrail.si.servicecode.commands.awaitCodeRedirect.AuthenticationActivity) it is displayed however it is blank and there is nothing in it. I am currently under the assumption that this is incorrect and that the missing resources/files are the cause of this.

Tmm
  • 187
  • 4
  • Check this [question](http://stackoverflow.com/questions/31155816/javafx-android-port-google-play-services), maybe it will help you. Otherwise, please post what type of library you need to import. – José Pereda May 10 '16 at 20:10
  • All your links are broken. Please review them. – José Pereda May 10 '16 at 21:41
  • I'm not an expert on JavaFX, but CloudRail for Android is using an Android WebView for authentication. Maybe the JavaFX version of WebView is less powerful and does not support a feature the SDK needs. – Florian May 11 '16 at 08:19
  • Web view is part of Android and as far as I know there is no "JavaFX version" so to speak, so I'm not that's the issue, thanks anyways –  May 11 '16 at 13:58
  • How do you call the interface function? Do you put it in a separate thread and not the main thread or an AsyncTask? This is mentioned in the FAQ (https://docs.cloudrail.com/docs/faq). Hope that helps. – Florian May 11 '16 at 17:10
  • I have resolved the problem after seeing Jose's example and it was indeed a threading issue! The new activity was basically being launched from my ui thread and that causes the ui to become unresponsive. Thank you for your help! The issue has been resolved, honestly that was a rather foolish mistake on my part. –  May 12 '16 at 15:36

1 Answers1

3

I've managed to extract the classes.jar from the aar file and add it to a Gluon project as dependency.

Next, I added the activity to the AndroidManifest.xml file, after the main FXActivity:

<activity android:name="com.cloudrail.si.servicecode.commands.awaitCodeRedirect.AuthenticationActivity" />  

Then I created a class in the Android package, provided the required credentials to access to Google Drive.

public AndroidTestAar() {
    GoogleDrive cs = new GoogleDrive(FXActivity.getInstance(), "****","****");
    new Thread() {
        @Override
        public void run() {
            List<CloudMetaData> metas = cs.getChildren("/");
            Log.i("info", "Folder has " + metas.size() + " children");
            for (CloudMetaData meta : metas) {
                Log.i("info", "Child: " + meta.getName());
            }
        }
    }.start();
}

This class is called from the View:

public BasicView(String name) {
    ...
    button.setOnAction(e -> {
        try {
            Class c = Class.forName("com.testaar.AndroidTestAar");
            c.newInstance();
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex)  {}

    });
}

I could deploy the apk and run it.

The activity runs outside the JavaFX app, in an Android WebView.

First it asked me to sign in with my user/password, then it asked me about allowing offline access, and finally on the console it successfully listed all my files.

José Pereda
  • 44,311
  • 7
  • 104
  • 132
  • 1
    So, as it turns out. The problem I was having is not actually at all related to any sort of issue with using .aar's! It was infact a mistake I made by not authenticating with a new thread, therefore locking up the ui. Thank you for your time José Pereda. –  May 11 '16 at 20:39