Reputation: 16948
I have a Gradle Android project (in Android Studio) that includes two packages (both in app
module). You know then there are two sets of folders under src/main/java
directory:
src/main/java/the/first/pkg/...{The Files Under First Package}...
src/main/java/the/second/pkg/...{The Files Under Second Package}...
Note: Both first and second packages are in a folder that named main
. But I mean, from the main package, my first package. In other words you can see this in main/AndroidManifest.xml
file:
<manifest ... package="the.first.pkg">
But what about src/main/res
directory?! All resources have been located in the root of this path (not categorized by package name)!
Now how can I define a resource
(like a layout
) NOT under the first package, but under the second package? (So I would be able to access it in my java
code through the.second.pkg.R.layout.resource_name
.)
Upvotes: 1
Views: 472
Reputation: 4051
You should change your scheme a little bit. By default, Android Studio
creates main
package and put all your sources in it, like this:
If you want to get different res folders, for different packages you should define another package inside src
package:
Also, Android Studio
can generate it for you:
- Open the Project pane and select the Project view from the drop-down menu at the top of the pane.
- Navigate to MyProject/app/src/.
- Right-click the src directory and select New > Folder > Java Folder.
- From the drop-down menu next to Target Source Set, select debug.
- Click Finish.
It's called source sets
more detail you can get from this link.
Upvotes: 1