Gluon Mobile:低功耗蓝牙没有接口实例 com.gluonhq.attach.ble.BleService

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

我是 Whosebug 的新手,这是我的第一个 post。我最近开始使用 Gluon Mobile 开发一个使用低功耗蓝牙的 android 移动应用程序。

我在使用 BLE 技术时遇到问题。如果我复制 gluon mobile documentation 中提供的一段代码,我会收到以下消息:

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

示例代码如下:

        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);
                    }
                }
            }
        });
    });

我还修改了 AndroidManifest.xml 文件,通过向文件添加以下行来提供使用蓝牙的必要权限:

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

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

大家遇到过这种问题并且解决了吗?感觉连不上蓝牙了

这里是 pom.xml 文件的副本:

<?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>

解决方案是将 <list>ble</list> 添加到 pom.xml 文件中的 <attachList>