简体   繁体   English

在Gluon JavaFXPorts项目中使用Android Aar库

[英]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. 我正在使用Gluon的Eclipse插件,并在JavaFX中开发应用程序以在Android上运行。 However, I need to use an Android library (.aar format) and after a while of trying, cannot. 但是,我需要使用Android库(.aar格式),经过一段时间的尝试后,还是不能。 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. 我已经尝试过仅使用.aar内部的classes.jar,尽管这种方法已经可以工作了,但我相信缺少一些资源和东西,对于它的功能来说,该库是必不可少的。 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. 编辑:我要使用的库是CloudRail ,下载在这里(直接下载)当前,使用提取的classes.jar中的类可以正常工作,但是当从其库中启动活动时(com.cloudrail。 si.servicecode.commands.awaitCodeRedirect.AuthenticationActivity),但显示为空白,其中没有任何内容。 I am currently under the assumption that this is incorrect and that the missing resources/files are the cause of this. 目前,我假设这是不正确的,并且缺少资源/文件是造成这种情况的原因。

I've managed to extract the classes.jar from the aar file and add it to a Gluon project as dependency. 我已经设法从aar文件中提取classes.jar并将其作为依赖项添加到Gluon项目中。

Next, I added the activity to the AndroidManifest.xml file, after the main FXActivity : 接下来,我在主FXActivity之后将活动添加到AndroidManifest.xml文件中:

<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. 然后,我在Android包中创建了一个类,提供了访问Google云端硬盘所需的凭据。

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. 我可以部署apk并运行它。

The activity runs outside the JavaFX app, in an Android WebView. 该活动在Android WebView的JavaFX应用程序外部运行。

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. 首先它要求我使用用户名/密码登录,然后问我有关允许脱机访问的问题,最后它在控制台上成功列出了我的所有文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM