开发者

Create library for Android development?

开发者 https://www.devze.com 2023-01-16 06:22 出处:网络
I\'m pretty new to Android development, but Ihave some experience with Java and Eclipse. I\'m looking for ways to create re-usable libraries (controls, helpers, \"standard\" activities, etc.) that I c

I'm pretty new to Android development, but I have some experience with Java and Eclipse. I'm looking for ways to create re-usable libraries (controls, helpers, "standard" activities, etc.) that I could use in my own projects, but that could also be distributed to other developers without disclosing the source code.

Normally, I'd package the class files into a JAR file and any other developer could add it to the classpath and use the packaged classes.

How c开发者_JAVA技巧an I do that with Android projects? I've read about Android Library Projects, but as the documentation states they can not be packaged into a JAR, but will be compiled along with the project that references the library project. This means I also have to distribute the source code.

I've also read this post, which asks about the same question but didn't provide a satisfying answer.

So: Is there a way of compiling and packaging a set of classes and other files (including XML layouts, resources and stuff) and distribute only that package without any source codes so that it can be "referenced" and used like a JAR file by any other developer?


I've read about Android Library Projects, but as the documentation states they can not be packaged into a JAR, but will be compiled along with the project that references the library project. This means I also have to distribute the source code.

Not true. It does require a bit of extra packaging work, but you can compile your code to a JAR and distribute the JAR in the library project's libs/ directory.

So: Is there a way of compiling and packaging a set of classes and other files (including XML layouts, resources and stuff) and distribute only that package without any source codes so that it can be "referenced" and used like a JAR file by any other developer?

Use an Android library project. I have some stuff written up here that describes a bit more of the packaging options, plus pointers to some "parcels" that follow the conventions described therein.


Thanx for your solution. From what I understand, you still can not access the resources private to the library from within the libary code. So assume your library has a string resource named "my_lib_resource" under res/values in the library. You bundle this in the jar along with the source code. Can you access this resource from the library source code using something like:

int id = res.getIdentifier("com.example.mylib:string/my_lib_resource",null,null) 

assuming your library package name is com.example.mylib.

For me this does not work.


Brave new world of dependency management:

http://tools.android.com/recent/dealingwithdependenciesinandroidprojects

0

精彩评论

暂无评论...
验证码 换一张
取 消