Search code examples
androidjavafxjavafxportsgluon-mobilecloudrail

Using an Android aar library in a Gluon JavaFXPorts project


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.


Solution

  • 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.