When developing an Android Application, how do I package the public parts that can be used for multiple applications or that are intended to be released to a third party for application integration?
As we all know, Android apps use ADT to package them into APK. APK contains everything needed to run the program, including class, asset, res, androidmanifest. XML, etc. For a library project, the jar package generated by the ADT only contains the compiled class file, excluding the res resource file. Res can only package the APK package in the application project.
How can I export the jar on my own? Execute the Export (export) for the library project and tick the res during the export. In this way, the exported jar package does contain the resource files under Res. Unfortunately, it has been learned through repeated experiments that even if the jar package contains res, the target application project will not process the res in the jar package during compilation, when you compress an APK package, it does not contain the res in the jar package. In this way, you cannot use res in the jar package for the target application project.
First, let's make a summary:
1. the android library project can be packaged into a jar file, and the bytecode files in the jar file can be successfully packaged into the APK package of the target application project. If the class library does not contain the content of the interface resources such as activity, or you manually read the resources in the class library, instead of using the ADT's resource reading mechanism from res, the use of this class library jar is completely correct, so you do not need to pay special attention to it.
2. it is meaningless to enter the resource file under Res into the jar package. The target application project will not read the res into the APK package from the jar package. The possible cause of speculation that res cannot be read from jar is that the resource name is duplicated with the target application project (this is a personal guess and cannot be accurate ).
If the jar package cannot be created, it is not appropriate to directly export the source code. What should I do?
The following is a method:
1. develop a Class Library Project (Project-> properties-> Android-> check "is library"), compile normally, and generate a jar package (under bin, jar only contains the bytecode generated by the class under SRC, does not contain the class automatically generated under gen or res ). Assume that this class library is called mylib and the generated jar name is mylib. jar.
2. create a new class library project (also set project-> properties-> Android-> check "is library"). Assume that this class library is called mylibdeploy, and set its namespace to be the same as that of mylib. Create a libs directory under mylibdeploy and import mylib. jar to the libs directory. Copy the assets and res directories under the mylib project to the mylibdeploy directory.
3. Create a reference to mylibdeploy in the target application project (for general Android projects, "Is library" is not checked. The reference method is as follows: Open the Android app Settings Project-> properties-> Android, click "add..." and select mylibdeploy. After this setting, the class in mylib can be referenced in the target application project. Finally, it is compiled and exported to the APK. This APK will contain res under mylibdeploy and automatically generated class files under the corresponding Gen.
For the class library to be released, send mylibdeploy directly. You can compress and package it into a zip file or any other format. You only need to use it to unbind it. By referencing mylibdeploy in step 1, the user (target application developer) can use mylib. jar and package the APK normally.
Of course, when packaging jar (mylib. jar in the above example), you can partially confuse it as needed to generate a jar package that is not easy to decompile.
This package release method is not perfect. We hope to improve the ADT. In the future, we may directly release jar.
Refer:
Managing projects from eclipse with ADT
Http://developer.android.com/guide/developing/projects/projects-eclipse.html
Android Developer Tools
Http://developer.android.com/guide/developing/tools/adt.html
How to export the project as a JAR File
Http://groups.google.com/group/android-developers/browse_thread/thread/bc4b509765bd1956
How to Create Android library in eclipse?
Http://groups.google.com/group/android-developers/browse_thread/thread/ce546a393cbb8bcf