Android debugging: Debugging Android projects across Java Projects

Source: Internet
Author: User

This blog is suitable:

* Use eclipse + ADT to develop the coder of the android Project

* The coder that knows and uses build path

* Coder for which you want to write test code

JUnit debugs and tests the Java project. In Android development, it also has its own testing framework.

However, there are not many projects, at least I do!


The following describes a simple and direct debugging method.


1. Create an android Project




It is just a simple Android project, which is easy to explain below.


2. Create a Java Project




3. Right-click the Java Project




4. Select Java build path




5. Add an android Project


Click Add in Step 4, select ondemo, and click OK.


6. Build the test class logictest in the Java Project




Source code

import com.example.ondemo.util.StringUtil;public class LogicTest {public static void main(String[] args) {int res = StringUtil.compare("1", "2");System.out.println("res = " + res);System.out.println("the MainActivity flag = " + com.example.ondemo.MainActivity.FLAG);}}


We can see that the stringutil under the util package is tested.
Methods and mainactivity constants.



Let's test the activity method.


import com.example.ondemo.util.StringUtil;public class LogicTest {public static void main(String[] args) {int res = StringUtil.compare("1", "2");System.out.println("res = " + res);int res2 = com.example.ondemo.MainActivity.getFlag();System.out.println("res2 = " + res2);System.out.println("the MainActivity flag = " + com.example.ondemo.MainActivity.FLAG);}}

When running (as Java application), the program will report an error, mainly because the activity class cannot be found.



Here, you can build path the Android. jar that corresponds to your current Android project SDK.


This android jar package is under the corresponding Android-SDK installation directory platforms.


Build path Android jar, Java project structure



Run again




Note:

If other third-party jar files (such as APACHE) are used in the android project ),

The corresponding build path should also be included in the Java project.











Related Article

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.