Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Note</strong>: This answer is basically obsolete now that one can create .aar libraries with resources. It still works, though, and there may be times when the portability of a .jar is desirable, so I'm leaving it here.</p> <p>Blumer's answer is a good one, and you should definitely look into Android's idea of library projects. However, there is another alternative. If you have a module that contains only Java code, but no resources of any kind (images, layouts, etc.), you can compile it to a .jar file separately and use the resulting .jar in multiple application projects. It works like this:</p> <ul> <li>Create a new Java project in Eclipse (not an Android project) and move the source code of your module there.</li> <li>If your module references any classes from the SDK, you'll need to add the Android SDK .jar to the project's classpath (Project > Properties > Java Build Path > Libraries > Add JAR).</li> <li>When your module is ready to use, bundle up its .class files into a .jar. You can do this manually, or you can look around to figure out how to get Eclipse to do it for you.</li> <li>Copy your module .jar file into the "libs" directory of your app's main project.</li> <li>Add the module .jar to the project's classpath (again, Project > Properties > Java Build Path > Libraries > Add JAR).</li> </ul> <p>Now you should be able to build multiple apps using the same .jar, while maintaining only one copy of the module's source code.</p> <p>Depending on your particular situation, this may or may not work any better for you than the standard Android library mechanism. But it's worth considering as an alternative.</p>
 

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