I have a package com.myapp.api which includes a couple of helper classes and lots of model classes. For the sake of organization, I wish I could place all the models in a subfolder called Models.
When I do that, Android Studio will mark an error on every model file, saying that their packages should be named com.myapp.api.Models instead.
Renaming the package wouldn't be a big deal, but I need those models to access some package-visible methods and variable present in the helper classes. If I rename, I must make those methods and variables public, and I don't want to.
Is there any way to force Android Studio not to try to create a new package based on the files structure?
The simple answer is no. This isn't an Android Studio thing, it's a Java thing -- directories on disk correspond to packages.
If you're really motivated to work around it, you could set up multiple source folders, e.g.
and manipulate srcDirs in your build.gradle to add the new source directories:
sourceSets {
main.java.srcDirs = ['src/main/java', 'src/main/java-models']
}
but that's kind of a confusing way to organize your source, and it's a pattern you rarely see.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With