Sometimes we wantCodeDuring Android development, resources such as resource files cannot be packaged into jar packages for project import. What should we do? We can use jar + Library for processing. The specific operation method is as follows:
1. Create an android project testlib as the test project for which we want to create a jar package. The package name is "com. Test. lib" and set the project to "is library ";
You should know how to set it. Right-click the project-properties-android page, select "is library" in the lower library section, and click "OK". This is very simple;
2. Compile a test_lib.xml layout file for testing;
<? XML version = "1.0" encoding = "UTF-8"?> <Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: layout_width = "match_parent" Android: layout_height = "match_parent" Android: Orientation = "vertical"> <textview Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: text = "test lib"/> </linearlayout>
3. Modify the default code setcontentview (R. layout. main) is setcontentview (R. layout. test_lib); (the newly compiled layout file must be used, huh, huh); in this way, the first test project to be compiled into a jar package is created;
4. Now we are creating an android project mytestlib for integration. The package name is the same as "com. test. "lib", also set to "is library"; this project can delete automatically generated items under the SRC and res directories (because it is useless );
5. Copy related resources in testlib of the above project to the mytestlib project, mainly under the assets and res directories, and then create a libs directory in mytestlib project;
6. Compile the testlib project and generate a testlib under the bin directory of the project. copy the jar package to the libs directory in the mytestlib project and compile the mytestlib project. This completes the mytestlib project;
7. Now we can create a test project (that is, your project) to test the jar + Library. Import the Library Project mytestlib to the test project, right-click the library in the lower part of the test project-properties-android page and click "add" to select the mytestlib project. OK;
8. Import the jar package. Import testlib to the test project. jar package, right-click test project-properties-Java build path, and click Add jars to select testlib under the libs directory of mytestlib project. jar, click OK twice. Now, we can call the code in the testlib project in the test project. You can write a line of code to call testlibactivity IN THE testlib project;
Note: The resource names in testlib and test must not be the same, otherwise there will be conflicts; resources such as the default image string layout generated by the testlib project can be deleted (if useful, modify the name at the end );
So far, the whole work has been completed;