Search code examples
javafxbluetooth-lowenergygluon-mobile

Gluon Mobile : Bluetooth Low Energy no instance for interface com.gluonhq.attach.ble.BleService


I am new on stackoverflow, this is my first post. I recently started using Gluon Mobile to develop an android mobile application using Bluetooth Low Energy.

I'm having trouble using the BLE technology. If I copy the piece of code provided in the gluon mobile documentation and I get the following message :

WARNING: No new instance for interface com.gluonhq.attach.ble.BleService and class com.gluonhq.attach.ble.impl.AndroidBleService

here is the code from the example:

        ble.startScanningDevices().addListener((ListChangeListener.Change<? extends BleDevice> c) -> {
            while (c.next()) {
                if (c.wasAdded()) {
                    for (BleDevice device : c.getAddedSubList()) {
                        System.out.println("Device found: " + device.getName());
                        device.stateProperty().addListener((obs, ov, nv) -> {
                            if (State.STATE_CONNECTED == nv) {
                                System.out.println("Device connected: " + device.getName());
                            }
                        });
                        ble.connect(device);
                    }
                }
            }
        });
    });

I also modified the AndroidManifest.xml file to provide the necessary permissions to use the bluetooth by adding the following lines to the file :

<uses-permission android:name="android.permission.BLUETOOTH"/>

<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>

Have any of you encountered this kind of problem and managed to solve it? I feel like I can't access the bluetooth.

here is a copy of the pom.xml file :

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.hacare</groupId>
    <artifactId>ehacarebox</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <name>>eHAcareBOX</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.release>11</maven.compiler.release>
        <javafx.version>16</javafx.version>
        <attach.version>4.0.11</attach.version>
        <client.plugin.version>0.1.38</client.plugin.version>
        <javafx.plugin.version>0.0.5</javafx.plugin.version>

        <mainClassName>com.hacare.Main</mainClassName>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>${javafx.version}</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>${javafx.version}</version>
        </dependency>
        <dependency>
            <groupId>com.gluonhq</groupId>
            <artifactId>charm-glisten</artifactId>
            <version>6.0.6</version>
        </dependency>
        <dependency>
            <groupId>com.gluonhq.attach</groupId>
            <artifactId>display</artifactId>
            <version>${attach.version}</version>
        </dependency>
        <dependency>
            <groupId>com.gluonhq.attach</groupId>
            <artifactId>lifecycle</artifactId>
            <version>${attach.version}</version>
        </dependency>
        <dependency>
            <groupId>com.gluonhq.attach</groupId>
            <artifactId>statusbar</artifactId>
            <version>${attach.version}</version>
        </dependency>
        <dependency>
            <groupId>com.gluonhq.attach</groupId>
            <artifactId>storage</artifactId>
            <version>${attach.version}</version>
        </dependency>
        <dependency>
            <groupId>com.gluonhq.attach</groupId>
            <artifactId>util</artifactId>
            <version>${attach.version}</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.gluonhq.attach/ble -->
        <dependency>
            <groupId>com.gluonhq.attach</groupId>
            <artifactId>ble</artifactId>
            <version>${attach.version}</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.gluonhq/charm-down-plugin-ble -->
        <dependency>
            <groupId>com.gluonhq</groupId>
            <artifactId>charm-down-plugin-ble</artifactId>
            <version>3.8.6</version>
        </dependency>


        <!-- https://mvnrepository.com/artifact/com.gluonhq/charm-down-common -->
        <dependency>
            <groupId>com.gluonhq</groupId>
            <artifactId>charm-down-common</artifactId>
            <version>2.0.1</version>
        </dependency>


    </dependencies>

    <repositories>
        <repository>
            <id>Gluon</id>
            <url>https://nexus.gluonhq.com/nexus/content/repositories/releases</url>
        </repository>
    </repositories>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
            </plugin>

            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>${javafx.plugin.version}</version>
                <configuration>
                    <mainClass>${mainClassName}</mainClass>
                </configuration>
            </plugin>

            <plugin>
                <groupId>com.gluonhq</groupId>
                <artifactId>client-maven-plugin</artifactId>
                <version>${client.plugin.version}</version>
                <configuration>
                    <target>${client.target}</target>
                    <attachList>
                        <list>display</list>
                        <list>lifecycle</list>
                        <list>statusbar</list>
                        <list>storage</list>
                    </attachList>
                    <!--
                    <bundlesList>
                        <list>com.hacare.views.primary</list>
                        <list>com.hacare.views.secondary</list>
                    </bundlesList>-->
                    <reflectionList>
                        <list>com.hacare.views.PrimaryPresenter</list>
                        <list>com.hacare.views.SecondaryPresenter</list>
                    </reflectionList>
                    <mainClass>${mainClassName}</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>desktop</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <client.target>host</client.target>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>com.gluonhq.attach</groupId>
                    <artifactId>display</artifactId>
                    <version>${attach.version}</version>
                    <classifier>desktop</classifier>
                </dependency>
                <dependency>
                    <groupId>com.gluonhq.attach</groupId>
                    <artifactId>lifecycle</artifactId>
                    <version>${attach.version}</version>
                    <classifier>desktop</classifier>
                </dependency>
                <dependency>
                    <groupId>com.gluonhq.attach</groupId>
                    <artifactId>storage</artifactId>
                    <version>${attach.version}</version>
                    <classifier>desktop</classifier>
                </dependency>
            </dependencies>
        </profile>
        <profile>
            <id>ios</id>
            <properties>
                <client.target>ios</client.target>
            </properties>
        </profile>
        <profile>
            <id>android</id>
            <properties>
                <client.target>android</client.target>
            </properties>
        </profile>
    </profiles>
</project>


Solution

  • The solution was to add <list>ble</list> to the <attachList> in pom.xml file.