As I understand, the three ways of distributing my application are via Jar, Android Library and Android Library Project.
Jar - cannot contain resources or XML layouts (so this is out for me)
Android Library - I don't really know how this works but the Google API uses it...
Android Library Project - includes resources but allows the client free rein on the code as it is distributed as source.
If I am to create a closed source application that requires drawables 开发者_JAVA技巧and XML files that I want to distribute to other Android programmers, what should I use? And can someone direct me to a tutorial on creating an Android Library?
More details on what exactly does your project would be welcome. My understanding is that you want to sell a library (a set of components/tools developers can integrate in their app) without disclosing the source.
As you stated, you can't include assets/resources in Jar files.
An Android Library Project would force you to let the source code be "visible". Proper licensing terms could help you put legal fences around source code usage but... well, you know what people do with licenses... Maybe some code obfuscation (not on the public visible methods) could help.
I'm not sure about how "shared libraries" included with <uses-library> work, but the examples have seen are system dependent (maps API available only on "official" Google accepted devices, Sprint Evo front facing camera...) and might require to be built within the system. Maybe some root privilege could help adding one, but this would have to be done on EACH device where applications using your library would want to run...
Why not try something along the following lines:
Create an Android Eclipse project (not flagged as Library), or just a Java Eclipse project where to stuff all your code. This will not contain any XML/PNG resource, only Java code. Make a build file (e.g. Ant) so to produce a Jar out of it.
- You might also try to add proguard into the build, so to obfuscate the non-public part of code.
Create an Android Library Eclipse project (this one is flagged as library) where to stuff all your XML/PNG resources. Also, in this project add a plain Jar reference to the output Jar from the aforementioned project.
- Probably here you should also flag the reference to be exported, in order to be used by library clients.
As an alternative to obfuscating the Jar, you might skip that and just obfuscate the whole Android Library project output, as that will work for both the Jar and the actual library output. Just be sure to explicitly keep all your public API. The advantage here would be to skip manual proguard implementation in build script, and use the one already implemented in Android Eclipse.
The android developer documentation has an article on about Android Libraries:
Update: http://developer.android.com/tools/projects/index.html#LibraryProjects
First of all, I think that if you want to publish your projects, programs you want them to work on an android device.. So you may want to publish them on .apk format. And when you create an apk package there isn't any limitations about what you put in it. Your resources and layouts must be in it because your application won't work without them.. if I were you, I would check out the android project export tutorials at first.
http://developer.android.com/guide/publishing/app-signing.html
In this page it explains the methods of publishing and signing your application.. You can have a look at this.
You can create an Android Project like what open intents (http://www.openintents.org/en/applications) do so that when you export it as an apk other developers can call it in their code.
Hope this helps.
I'm also agree with Kevin in the idea of creating an obfuscated android library. In that case you must keep in mind some considerations listed here. Otherwise, if you had come with an other idea, feel free to share it.
精彩评论