问题
I noticed that when I convert an existing Android Application project to an Android Library project by checking the "is Library" checkbox, nothing changes in the project's source code or XML files.
So what really happens when the "is Library" checkbox is checked? What changes internally, in the package and/or project files? Where can I learn more about this?
To better explain my question:
- What I am interested to know (mainly for troubleshooting purposes) is what differentiates an Application package from a Library package "under the cover"?
- Is the fact that a project is "Library Project" marked somewhere? If so, where does it mark it (obviously not in the source files and not even in the res XML files)
回答1:
From the Managing Projects from the Command Line page:
The create lib-project command creates a standard project structure that includes preset property that indicates to the build system that the project is a library. It does this by adding this line to the project's default.properties file:
android.library=true
In other words, it's a property that is utilized by the build system and not by the operating system.
UPDATE: I'm on my iPhone so I won't type out a whole paraphrase, but here's a pretty good blog article discussing the differences between a Java JAR and an Android Library Project, including how the dex tools add the resources and dex code to the .apk:
http://devmaze.wordpress.com/2011/05/22/android-application-android-libraries-and-jar-libraries/
回答2:
From the devsite: http://developer.android.com/guide/developing/projects/projects-eclipse.html
You can also designate an Android project as a library project, which allows it to be shared with other projects that depend on it. Once an Android project is designated as a library project, it cannot be installed onto a device.
回答3:
A library project isn't packaged as a seperate redistributable file as you're used to with a jar. It's merged with the the apk file of your application.
The page you linked to mentions it in the Referencing a library project section.
As soon as the Properties dialog closes, Eclipse rebuilds the project, including the contents of the library project.
来源:https://stackoverflow.com/questions/6333093/what-does-checking-the-is-library-checkbox-do-under-the-cover