How to distribute reusable android code in a package?

I developed a reusable Android component that is basically a class. This class has some resource dependencies, for example. some png drawables, some xml layouts, etc. Thus, this class refers to an autogenerated R file. I would like to distribute this code in one package, such as a jar file, to other developers for use in their applications.

I read that the only possible solution is to distribute the code along with all my resources, which others should copy to the "res" ( source ) folder .

So, I created a jar file with a class file (for example, MyClass, which is in the package com.xyz.android.app) and resources, and tried to use it in my new application.

So, I added the jar file to my new application build path using the option add external jarsin eclipse and copied all the resources to the new res res folder. (The activity class says that the MainActivity of my new application is in the package com.abc.myapplication, just for the case if it might be useful)

But when I launch this new application, there is a class in the MyClass class java.lang.ClassCastException. I tried to debug the application, and then found that in the MyClass class the "R cannot be solved" problem.

Then I changed the MainActivity package to com.xyz.android.app(this is not so, other developers will be happy), but again the problem.

But when I just copy the source Java file in such a way that both MainActivity.java and MyClass.java are in the package com.xyz.android.app, then the application works fine.

So if I need to distribute so that other users do not need to worry about it, how can I do it? Please, help!

Edit

There are also some resources in android.jar. How are they mentioned in the project? How are they used in Android classes? There is also an android.R file?

Is it possible to do the same thing to make a jar file, for example, android.jar for my reusable code?

+5
source share
3 answers

Nic Strong, , , , SDK .

, . , .

+3

Mark Murphy ParcelHelper http://github.com/commonsguy/cwac-parcel. , , "R" , "R" .

If I understand your question correctly, this is exactly what you want. You may still have to copy some resources, such as styles, into your project.

+1
source

All Articles