如何修复HiveMQ(MQTT协议)中未解决的DaggerSingletonComponent [英] How to fix DaggerSingletonComponent not resolved in HiveMQ (MQTT protocol)

查看:255
本文介绍了如何修复HiveMQ(MQTT协议)中未解决的DaggerSingletonComponent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图先设置创建客户端以测试MQTT是否正常运行,然后再实现connect()方法.我下载了最新版本的HiveMQ(用Java完成的开源MQTT实现),并在Eclipse中将其作为Gradle构建正确导入项目并使用GIT正确导入后,收到一条错误消息.它说:"DaggerSingletonComponent无法解析."我的程序根本无法运行.

I'm trying to set create the client first to test that the MQTT works without errors then I will implement the connect() method. I downloaded the latest version of HiveMQ (an open source MQTT implementation done in Java) and after importing the project properly as a Gradle build in Eclipse and using GIT I was greeted with an error message. It said "DaggerSingletonComponent cannot be resolved." My program can't run at all.

我下载的开源链接: https://github.com/hivemq/hivemq -mqtt-client

我尝试过手动编辑构建文件,以查看是否有一些代码在依赖项中遗漏了匕首,但没有.

I've tried manually editing the build files to see if there was some code left out for dagger in dependencies but there wasn't.

package com.hivemq.client.internal.mqtt.ioc;

import com.hivemq.client.internal.mqtt.netty.NettyEventLoopProvider;
import com.hivemq.client.internal.mqtt.netty.NettyModule;
import dagger.Component;
import org.jetbrains.annotations.NotNull;

import javax.inject.Singleton;

/**
 * Singleton component for all clients. It exists the whole application lifetime.
 *
 * @author Silvio Giebl
 */
@Component(modules = {NettyModule.class})
@Singleton  
public interface SingletonComponent {

    @NotNull SingletonComponent INSTANCE = DaggerSingletonComponent.create();

    @NotNull ClientComponent.Builder clientComponentBuilder();

    @NotNull NettyEventLoopProvider nettyEventLoopProvider();
}


__________________________
For the module: NettyModule.class


package com.hivemq.client.internal.mqtt.netty;

import dagger.Module;

import dagger.Provides;
import io.netty.channel.epoll.Epoll;
import io.netty.channel.epoll.EpollEventLoopGroup;
import io.netty.channel.epoll.EpollSocketChannel;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import org.jetbrains.annotations.NotNull;

import javax.inject.Singleton;

/**
 * @author Silvio Giebl
 */
@Module
public abstract class NettyModule {

    @Provides
    @Singleton
    static @NotNull NettyEventLoopProvider provideNettyEventLoopProvider() {
        if (Epoll.isAvailable()) {
            return new NettyEventLoopProvider(EpollEventLoopGroup::new, EpollSocketChannel::new);
        } else {
            return new NettyEventLoopProvider(NioEventLoopGroup::new, NioSocketChannel::new);
        }
    }
}

错误消息:DaggerSingletonComponent无法解析

Error Message: DaggerSingletonComponent cannot be resolved

推荐答案

Dagger是一个在编译时生成用于依赖项注入的代码的库. 提到的类是生成的类之一.

Dagger is a library that generates code for dependency injection at compile time. The mentioned class is one of the generated classes.

请使用gradle构建项目:

Please use gradle to build the project:

  1. 打开一个终端
  2. 导航到项目目录
  3. 执行./gradlew build(Linux/Mac)或gradlew build(Windows)
  1. Open a terminal
  2. Navigate to the project directory
  3. Execute ./gradlew build (Linux/Mac) or gradlew build (Windows)

您需要确保将目录build/generated/source/apt/main/配置为源目录,以便IDE拾取生成的类.

You need to ensure that the directory build/generated/source/apt/main/ is configured as a source directory so that the IDE picks up the generated classes.

然后,在使用gradle进行首次构建后,您应该能够使用IDE的构建方法.

Then you should be able to use the build methods of your IDE after the first build with gradle.

这篇关于如何修复HiveMQ(MQTT协议)中未解决的DaggerSingletonComponent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆