简体   繁体   English

无法在Android上运行MQTT示例项目

[英]Cann't running MQTT example project on Android

I'm a newbie in programming Android APP. 我是Android APP编程的新手。 I'm using ActiveMQ running on Win7 as a Messaging Server. 我正在使用在Win7上运行的ActiveMQ作为Messaging Server。 I'm trying to test Message-Oriented Middleware protocols such as MQTT, STOMP, etc. via Android APP. 我正在尝试通过Android APP测试面向消息的中间件协议,例如MQTT,STOMP等。

I've import adroid-mqtt-demo repo's project to Eclipse to test MQTT connection, and include the java_1.4_uber.jar from mqtt-client . 我已经将adroid-mqtt-demo repo的项目导入到Eclipse以测试MQTT连接,并包括了mqtt-client中的java_1.4_uber.jar。 I encountered same problem with this issue . 我在这个问题上遇到了同样的问题。

So I tried to create a source folder /mqtt which is same level with /src under this project, and I copy-paste all the classes under /matt-client/src/main/java/org/fusesource/mqtt directory in the mqtt-client repo one by one. 因此,我尝试在此项目下创建与/ src处于同一级别的源文件夹/ mqtt,然后将所有类复制并粘贴到mqtt中的/ matt-client / src / main / java / org / fusesource / mqtt目录下-客户端回购一项。 (very stupid, I know, but I don't know other way to achieve it.) (我知道这很愚蠢,但我不知道其他实现方法。)

But when I ran this app on either on emulator or my android phone, it showed another errors, such as "error opening trace file", "Could not find class 'org.fusesource.hawbuf.UTF8Buffer'", and "java.lang.VerifyError: org/fusesource/mqtt/codec/CONNECT" . 但是,当我在模拟器或Android手机上运行此应用程序时,它显示了另一个错误,例如"error opening trace file", "Could not find class 'org.fusesource.hawbuf.UTF8Buffer'", and "java.lang.VerifyError: org/fusesource/mqtt/codec/CONNECT"

I've googled to find out the solution for many days, and still cannot find how to make it work. 我已经在Google上寻找解决方案很多天了,但仍然找不到如何使它起作用。 Could anybody give me some advices? 有人可以给我一些建议吗?

If you just want to run the demo you only need to download the uber-jar (as you already did) and then you need to 1) create a libs folder in your project's root folder 2) copy the jar file inside that folder and 3) right click on the uber-jar file, select Build Path > Add to Build Path. 如果您只想运行演示,则只需下载uber-jar(就像您已经做的那样),然后需要1)在项目的根文件夹中创建一个libs文件夹2)复制该文件夹中的jar文件,然后3 ),右键单击uber-jar文件,选择“构建路径”>“添加到构建路径”。

The above is what user anandaverma describes here: https://github.com/jsherman1/android-mqtt-demo/issues/2 以上是用户anandaverma在此处描述的内容: https : //github.com/jsherman1/android-mqtt-demo/issues/2

This should also be helpful: How can I use external JARs in an Android project? 这也应该有所帮助: 如何在Android项目中使用外部JAR? . As it is mentioned in one of the comments: 正如评论之一中提到的:

Note that when using recent Eclipse/ADT versions the external jars have to be in a folder called libs (instead of lib) 请注意,在使用最新版本的Eclipse / ADT时,外部jar必须位于名为libs(而不是lib)的文件夹中。

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

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