Java – The package structure in my Android library is better

The package structure in my Android library is better… here is a solution to the problem.

The package structure in my Android library is better

I’m writing an Android library (with its own Activity) that will be imported into other Android projects using Android aar packages.


goal is to publish just one class (let’s call it MyPlugin) that does all the work of providing public methods (calling activities, etc.); But in my opinion, all activities must be public; So I want to separate the classes that users want to use from the classes I don’t want to use. Something like this:

 |--> MyPlugin (public class with public methods)
 |--> Acitivty1
 |--> ....
 |--> ActivityN (public? activities)
 |--> Services (protected? class with protected? methods)

With this design, I can say to the user “you should only use API packages”.

The problem is the Serivice class: it’s used by Activities and MyPlugin if I want it (or its methods) to be protected (so end users can see it).


know anything can be done by the end user through reflection, but I want it to be as clean and simple as possible.

The only solution I found was to have only one package with all the classes, but, as I said, I want to separate MyPlugin from Activities.


A common convention is to use a package called internal for private implementation/inner classes.

com.mycompany.myplugin // all public stuff here and in its subpackages
com.mycompany.myplugin.internal // all non public stuff

Also, follow @Drew’s answer:

It’s often good idea to populate your package by feature, not by component


Related Problems and Solutions