1

I want to use some "gluonhq charm down" services such as the magnetometer.

I don't understand why the MagnetometerService cannot be imported in my Java class file. The error message is

The "import com.gluonhq.charm.down.plugins.accelerometer cannot be resolved".

Before, in Eclipse Neon2 - Help -Available Software sites, I had installed e(fx)clipse. You can see, in the Installation details:

 "e(fx)clipse - IDE - Update site" with http://download.eclipse.org/efxclipse/updates-released/2.4.0/site

Note: I have installed GluonTools 2.4.0 including e(fx)mobile IDE 2.3.0. Here is the build.gradle of my project:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'org.javafxports:jfxmobile-plugin:2.4.0'
    }
}

plugins {
    id "com.github.hierynomus.license" version "0.13.1"
}

apply plugin: 'org.javafxports.jfxmobile'

repositories {
    jcenter()
    maven {
        url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
    }
}

mainClassName = 'com.gluonapplication.GluonApplication'

jfxmobile {
     downConfig {
        version '4.0.0'
        plugins 'accelerometer', 'compass', 'device', 'orientation', 'storage', 'vibration', 'display', 'lifecycle', 'statusbar', 'position'
    }

    android {
        applicationPackage = 'com.gluonapplication'
        manifest = 'src/android/AndroidManifest.xml'
        androidSdk = 'C:/Users/pascal/AppData/Local/Android/sdk'
        resDirectory = 'src/android/res'
        compileSdkVersion = '23'
        buildToolsVersion = '25.0.1'
    }
    ios {
        infoPList = file('src/ios/Default-Info.plist')
    }
}
Pascal DUTOIT
  • 121
  • 1
  • 13

1 Answers1

1

These are the steps to create an app on Eclipse with the Gluon plugin 2.4.0 installed.

1. Use the IDE plugin

Click on New, select Gluon -> Gluon Mobile - Single View Project, fill the required data (name of project, package, ...), click finish.

2. Review the build.gradle file

Open the build file, and update the versions: the current jfxmobile plugin version is 1.3.2. Gluon Charm is 4.3.0, and Gluon Down plugins use 3.2.0.

3. Add your Down plugins

Add the magnetometer plugin to downConfig.

This should be your build.gradle file (except for the main class name):

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'org.javafxports:jfxmobile-plugin:1.3.2'
    }
}

apply plugin: 'org.javafxports.jfxmobile'

repositories {
    jcenter()
    maven {
        url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
    }
}

mainClassName = 'com.gluonhq.magnetometer.TestMagnetometer'

dependencies {
    compile 'com.gluonhq:charm:4.3.0'
}

jfxmobile {
    downConfig {
        version = '3.2.0'
        plugins 'display', 'lifecycle', 'magnetometer', 'statusbar', 'storage'
    }
    android {
        manifest = 'src/android/AndroidManifest.xml'
    }
    ios {
        infoPList = file('src/ios/Default-Info.plist')
        forceLinkClasses = [
                'com.gluonhq.**.*',
                'javax.annotations.**.*',
                'javax.inject.**.*',
                'javax.json.**.*',
                'org.glassfish.json.**.*'
        ]
    }
}

Note that you don't need to add any further plugin dependency, downConfig does it for you.

4. Add the service to your basic view

This is a simple use case of the Magnetometer service:

package com.gluonhq.magnetometer;

import com.gluonhq.charm.down.Services;
import com.gluonhq.charm.down.plugins.MagnetometerService;
import com.gluonhq.charm.glisten.control.AppBar;
import com.gluonhq.charm.glisten.control.Icon;
import com.gluonhq.charm.glisten.mvc.View;
import com.gluonhq.charm.glisten.visual.MaterialDesignIcon;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;

public class BasicView extends View {

    public BasicView(String name) {
        super(name);

        Label label1 = new Label();
        Label label2 = new Label();

        Button button = new Button("Start Magnetometer");
        button.setGraphic(new Icon(MaterialDesignIcon.VIBRATION));

        button.setOnAction(e -> 
            Services.get(MagnetometerService.class)
                .ifPresent(s -> s.readingProperty()
                        .addListener((obs, ov, nv) -> {
                            label1.setText(String.format("X: %.4f Y: %.4f Z: %.4f\n Mag: %.4f", nv.getX(), nv.getY(), nv.getZ(), nv.getMagnitude()));
                            label2.setText(String.format("Yaw: %.2f\u00b0 Pitch: %.4f\u00b0 Roll: %.4f\u00b0", Math.toDegrees(nv.getYaw()), 
                                    Math.toDegrees(nv.getPitch()), Math.toDegrees(nv.getRoll())));
                        })));

        VBox controls = new VBox(15.0, button, label1, label2);
        controls.setAlignment(Pos.CENTER);

        setCenter(controls);
    }

    @Override
    protected void updateAppBar(AppBar appBar) {
        appBar.setNavIcon(MaterialDesignIcon.MENU.button(e -> System.out.println("Menu")));
        appBar.setTitleText("Magnetometer");
    }

}

5. Test on desktop

Using the Gradle Task window, selecting application->run

Notice the service is not available on desktop, and it won't work, but you'll check the app runs without errors.

6. Deploy on Android

Using Gradle Task window, selecting other->androidInstall.

Plug your phone before running the task. If everything goes ok you should be able to test the app on your device:

José Pereda
  • 44,311
  • 7
  • 104
  • 132
  • I cannot install the jfxmobile plugin.by Help - Install New Software, and drag and Drop the Gluon Plugin "http://marketplace.eclipse.org/marketplace-client-intro?mpc_install=2496245". After the "Pending" , there is an error message: Unable to read repository at http://marketplace.eclipse.org/marketplace-client-intro?mpc_install=2496245. "Unable to read repository at http://marketplace.eclipse.org/marketplace-client-intro?mpc_install=2496245. http://marketplace.eclipse.org/marketplace-client-intro?mpc_install=2496245 is not a valid repository location." A Marketplace problem?Get it elsewhere? – Pascal DUTOIT Jan 31 '17 at 17:04
  • 1
    Didn't you have already installed the Gluon IDE plugin on your Eclipse Neon?? Go to File->New->Project... Do you see a Gluon folder? You don't need to install the jfxmobile plugin. – José Pereda Jan 31 '17 at 17:09
  • I had installed e(fx)clipse 2.4.0 and gluon plugin 2..0 BUT not download.eclipse.org/efxclipse/updates-released/2.4.0/site. Two activities are launched: e(fx)clipse - "install" and "single components". Perhaps, e(fx)clipse was not completely installed, before? When I do that, the message is "Cannot perform operation. Computing alternate solutions, may take a while: 2/15". Almost 15 mns in this state. Is it normal? Perhaps, I should uninstall then install again this part? – Pascal DUTOIT Jan 31 '17 at 18:21
  • 1
    I've had issues installing Eclipse as well, sometimes it goes painfully slow. Have you tried NetBeans? – José Pereda Jan 31 '17 at 18:24
  • I have aborted this action. I require to "Check for updates". There is a problem about Marketplace updates. There is a infinite loop between these three checks: ...content.jar?mpc_install= 865191 and 2496245 and 2306961. That explains that I cannot update any Marketplace plugin. Have you an idea to solve that? Does I uninstall something? Thanks. It is very difficult to create the Android develoment environment. – Pascal DUTOIT Jan 31 '17 at 18:25
  • I'm trying to update an old Eclipse Mars installation, it fails all the time as well (nothing to do with Gluon's plugin). I'm trying now a fresh installation of Eclipse Neon – José Pereda Jan 31 '17 at 18:46
  • I've just installed Neon and Gluon IDE plugin 2.4.0. Installed Neon first, then searched in the marketplace for Gluon, 0 results but clicked on browse for more solutions. Then a tab with the marketplace showed up with the Gluon plugin link, just clicked on Install, and it worked fine. – José Pereda Jan 31 '17 at 19:07
  • I am going to try your solution – Pascal DUTOIT Jan 31 '17 at 19:18
  • It seems to be that works now. There a "Building gradle model" with Download https://jcenter.bintray.com/com/gluonhq/charm-down-plugin-accelerometer-android/3.2.0/charm-down-plugin-accelerometer-android-3.2.0.pom." Then BUILD SUCCESSFUL . Then, Download https://jcenter.bintray.com/com/gluonhq/charm-down-plugin-accelerometer/3.2.0/charm-down-plugin-accelerometer-3.2.0-sources.jar. But, in the java code, "import com.gluonhq.charm.down.plugins.accelerometer;" cannot be resolved. And Services.get(MagnetometerService.class).ifPresent(service -> { .., too. Is the import directive correct? – Pascal DUTOIT Jan 31 '17 at 20:03
  • Refresh your gradle project (Right click menu->Gradle->Refresh gradle project), every time you update your initial build file, and then clean and build again. – José Pereda Jan 31 '17 at 20:05
  • Is it by "Right click on the project", then "Gradle - Refresh All"? If yes, this action does not work. The "com.gluonhq.charm.down.plugins.accelerometer" is unresolved. Thanks for your help. – Pascal DUTOIT Jan 31 '17 at 20:26
  • 2
    Right click on either the project root or the build.gradle file itself, select Gradle, and then Refresh Gradle Project. There are other plugins resolved, so accelerometer and magnetometer will be resolved as well. Else, close Eclipse and open it again so the project gets refreshed. – José Pereda Jan 31 '17 at 20:30
  • I have followed your instructions, without success – Pascal DUTOIT Jan 31 '17 at 20:35
  • 1
    Make sure you have updated the build gradle and the BasicView with the code from my answer. Then you just need to run `gradlew clean build run` to make it work, or select the tasks clean, build and run from the Gradle Tasks View. If you have an error, post it. – José Pereda Jan 31 '17 at 20:40
  • All plugins, as the accelerometer, "cannot be resolved". But, the charm down elements that are NOT plugins as com.gluonhq.charm.down.Platform and com.gluonhq.charm.down.Services are RECOGNIZED. – Pascal DUTOIT Jan 31 '17 at 20:44
  • Try to run it from the command line: Open a terminal, go to the root folder of the project and run `gradlew.bat run`. Does it work? – José Pereda Jan 31 '17 at 21:07
  • Yes, it says: "BUILD SUCCESSFUL". As com.gluonhq.charm.down.Platform and com.gluonhq.charm.down.Services are RECOGNIZED, but not the plugins imports, have I omitted to set an environment variable or something like that? – Pascal DUTOIT Jan 31 '17 at 21:51
  • If the task runs on command line, it means that it has managed successfully the plugins. Run again now: `gradlew.bat --info run`, and have a look at the console, about how the plugins are resolved. – José Pereda Jan 31 '17 at 21:55
  • THE SOLUTION:When I replace "import com.gluonhq.charm.down.plugins.compass" BY "import com.gluonhq.charm.down.plugins.CompassService", then I download the compass.jar from https://maven2repo.com/com.gluonhq/charm-down-plugin-compass-android/3.2.0/jar AND I add this external jar in the project, that works fine now. I don't understand that all Web examples provide the syntax without "Service"? It remains a single error with the magnetometer, even if I get its plugin by the same way by downloading its 3.2.0 jar, with plugin-magnetometer-android/3.2.0/jar . An idea? In any case, thanks a lot. – Pascal DUTOIT Feb 01 '17 at 08:06
  • 1
    For sure you can use regular dependencies, like `compile 'com.gluonhq:charm-down-plugin-compass:3.2.0'`, and so on. No need for manual download. But precisely, that is what `downConfig` does for you, and that's why on command line works for you. So it's a case of bad config on your IDE. As for the syntax, what examples do you mean? See my code above, I use `MagnetometerService`. – José Pereda Feb 01 '17 at 08:31
  • Yes, your example is right. But, the problem was about some reference examples like: https://javalibs.com/artifact/com.gluonhq/charm-down-plugin-position-android?className=com.gluonhq.charm.down.plugins.android.AndroidPositionService&source: "import com.gluonhq.charm.down.plugins.Position; 40.import com.gluonhq.charm.down.plugins.PositionService;". The plugins are Position or PositionService and I chose the first. => a mishmash in my Java tools understanding. Still, thanks a lot for your help. Now, I am going to test these specific funtionalities with my phone. Have a nice day! – Pascal DUTOIT Feb 01 '17 at 09:16
  • 1
    In that case, `Position` is a class on its own, not the plugin – José Pereda Feb 01 '17 at 09:18