Wednesday, June 5, 2019

Android library packages should be unique

I recently set up a project consisting of an Android app module and some Android libraries. I wanted the libraries to provide interchangeable versions of functionality in the app (swapped out via some other tricks), so I tried to give the libraries the same package name in their manifest as the app. However, library code appeared to then use the wrong R class at runtime - the app's, not the library's own - which was somewhat expected. Classes from the library can be dumped into the same Java package as the app classes, but the package declared in the manifest should be different. Library code can still use R (with an import).

No comments:

Post a Comment