Android use Mina need to pay attention to the problem

Source: Internet
Author: User

1. Use of third-party jar packages
If you use Add External jars this way in the Java Build path, the runtime will not find the class error (I have, if you do not appear, congratulations), the Internet looked at several ways, I run through the following way:
Build a Lib folder in the project, copy the required jar package, use the Add JARs in the Java Build path, select the jar file in the Lib package under the project, and pack the APK file automatically when you publish it.
On the web there is a way to use the Add Library in the Java Build Path, choose User Libaray-A new user Libaray way, this I did not try, have passed the comrades say.
I recommend the way the project is built with folders.

2. Mina the use of the package log
I am using mina2.0.2, and if there is no special need, use the mina-core-2.0.2 core package.
Key points here: templates
Mina use SLF4J as a log framework (do not know slf4j comrades please google), this is just a log framework, is not implemented, you need a concrete implementation, such as log4j (specific use of the method I do not say, very simple, I do not know to send me the station letter). Use Mina must put SLF4J jar package also introduced, then you also want to introduce a implement log package, in the normal client development this is not a problem, but in Android, already has a log implementation, and with Logcat, its function is very powerful, So how to cooperate with SLF4J to use it? (Ps:slf4j is a must, Mina need to use)
Thanks for the network here, I actually found a slf4j-android jar in SLF4J's official website.
Http://www.slf4j.org/android/comrades can go to see, (highly recommended to see) download this package, introduced into the project, note that this package is not compatible with the SLF4J-API package, my solution is to use only slf4j- Android This package, the rest of the log related packages are deleted (in fact, other log packages are not useful, we have the Android provided by the log class), so Mina will not report the log class can not find errors, and logs are output to Logcat, debugging program is also convenient. In this regard we want to thank slf4j, if there is no such implementation, Mina use of trouble, I can think of the way only change Mina source code, recompile, of course, you can also provide your own log implementation class. http://www.huiyi8.com/moban/
Android Log class has a limit, tag can not exceed 23 characters (you do not know the tag, I do not know how to say ...) ), slf4j also to solve, the official website above has introduced. (again recommended to see Xia Guan net)

3. The use of Mina package Niosocketconnector

There seems to be no problem in android2.1, but there will be bad address family exception in android2.2, this exception is caused by IPV6, this bug is already in Http://code.google.com/p/android/ issues/detail?id=9431 (Comrades See), android2.2 does not support IPV6, there will be problems when using NIO, it is recommended to use IO, can be resolved, but if we must use NIO, the solution is as follows:

Set System Properties: System.setproperty ("Java.net.preferIPv6Addresses", "false"); In this line to solve the problem, some comrades may ask, where to add ah? The system starts with a local plus, such as a service, in OnCreate () before the start of Mina plus the line, the activity is the same.

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.