Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to distribute the android reusable code in a package?
    primarykey
    data
    text
    <p>I have developed some reusable android component which is basically a class . This class has some resource dependencies e.g. some png drawables, some xml layouts etc. So this class referenced the auto-generated R file.I would like to distribute this code in a single package like jar file to other developers for use in their applications. </p> <p>I have read that the only possible solution is to distribute code together with all my resources, which others have to copy to their "res" folder (<a href="https://stackoverflow.com/questions/1995004/packaging-android-resource-files-within-a-distributable-jar-file/2825174#2825174">source</a>).</p> <p>So I created a jar file having the class file (say MyClass which is in the package <code>com.xyz.android.app</code>) and resources and tried to use this in my new application.</p> <p>So I added the jar file to my new applications build path using <code>add external jars</code> option in eclipse and copied all the resources to my new application's res folder. (The activity class say MainActivity of my new application is in <code>com.abc.myapplication</code> package, just for the case if it may helpful)</p> <p>But when I run this new application there is <code>java.lang.ClassCastException</code> in the MyClass class. I tried to debug the application and then I found that in the MyClass class, there is "R cannot be resolved" problem.</p> <p>Then I changed MainActivity's package to <code>com.xyz.android.app</code> (which is not the way, other developers will be happy to do), But again the same problem.</p> <p>But When I just copy the source java file such that both MainActivity.java and MyClass.java are in com.xyz.android.app package then application runs fine.</p> <p>So if I need to distribute such that other users need not to bother these package naming things, how can I accomplish this? Please help !!</p> <p><strong>Edit</strong></p> <p>In android.jar, there are also some resources. How are they referenced in a project? How are they used in android classes? There is also android.R file?</p> <p>Is it not possible to do the same thing i.e. to make jar file like android.jar for my reusable code?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload