Precautions for using Mina for Android

Source: Internet
Author: User

1. third-party jar package usage
If add external jars is used in Java build path, a class error will not be found during running (My above, if you didn't see it, congratulations) I have checked several ways online. The running method is as follows:
Create a lib folder in the project and copy the required jar package, use add jars in the Java build path and select the JAR file in the Lib package under the project. The APK file is automatically packaged when it is released.
there is another way on the Internet. In Java build path, use add library, select user libaray-> create a user libaray method. If this is the case, I did not try it. Software development
I recommend creating folders for projects.

2. Mina package usage log
I use mina2.0.2. If you do not have any special requirements, use the Mina-core-2.0.2 core package.
the key points are as follows:
Mina uses slf4j as the log framework (for those who do not know slf4j, please google). This is only a log framework and is not implemented, you need a specific implementation, such as log4j (I will not talk about the specific usage, It is very simple, and I really don't know how to send an insite email to me ). When using Mina, The slf4j jar package must also be introduced. Therefore, you must also introduce a log implementation package. This is not a problem during normal client development, but in Android, there is already a log implementation, and with logcat, its function is very powerful, so how to use it with slf4j? (PS: slf4j is required and Mina is required)
thanks to the network, I found a slf4j-android jar package on the official website of slf4j
http://www.slf4j.org/android/ comrades can go to see, (strongly recommended to see) download this package, introduced to the project, pay attention to ah, this package cannot coexist with the slf4j-api package, my solution is to only use the slf4j-android package, the rest of the log-related packages are deleted, (in fact, other log packages are useless, we have the log class provided by Android), so that Mina will not report errors not found by the log class, And all logs are output to logcat, debugging Programs is also convenient. In this regard, we would like to thank slf4j. Without this implementation, Mina will be in trouble. The only way I can think of is to change Mina Source Code , re-compile. Of course, you can also provide your own log implementation class.
there is a limit in the log class of Android, And the tag cannot exceed 23 characters (you do not know the tag, and I do not know what to say ...), slf4j also solved the problem. It is described on the official website. (I suggest you go to the official website)

3. Use of Mina package niosocketconnectortp-Link

There seems to be no problem in android2.1, but there will be a bad address family exception in android2.2, this exception is caused by IPv6, this bug has been in the http://code.google.com/p/android/issues/detail? Id = 9431 (Check It Out). android2.2 does not support IPv6. there may be problems when using NiO. I/O is recommended to solve this problem, but if we must use NiO, the solution is as follows:

Set the system property: system. setproperty ("java.net. preferipv6addresses", "false"); To solve this problem, some comrades may ask where to add it? Add the place where the system starts, for example, Service. Add the line before starting Mina in oncreate (). The same is true for the activity.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.