Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find the create package menu in Android Studio

I have a trouble to add a package under one of the flavor folder in Android Studio: after I right click on the java folder and I could not see the 'Package' or 'Java Classes' options there!

I did exactly the same for another flavor and it was fine.. Now I am stuck here, without knowing if it is a bug in AS or I did anything there. Anyone help me please!

(I googled it and did not solve it with what I have found so far)

enter image description here

=======EDIT========

I close the project and create a brand new empty project, now even in the main folder I cannot find the 'Java Classes' or 'Package' when I right click on the java folder I added.

However, if I just create the folders of the package under java with a class there, and do a build, it will finally recognize that and make java blue color and then I am able to see the menus if I right click the blue java folder.

So it sounds like some bug in AS.

like image 431
Qianqian Avatar asked Oct 03 '15 22:10

Qianqian


People also ask

Where is the package folder in Android Studio?

example. app. data. The package for each android application resides within the src/main/java directory of the application module.

How do I add packages to Android apps?

EDIT: To add a new package to android studio, click on Project -> expand the 'app' directory, expand 'src' -> expand 'main' -> right click on 'java' -> New -> Package.

Is package and directory same in Android Studio?

Packages and folders are the same thing, there should be no problem having two packages: com. LS33Tcode. example. adapters and com.

What is the right way to declare package in Android is?

If you develop an Android library, you can declare your package visibility needs by adding a <queries> element in your AAR manifest file.


2 Answers

It might just be the build flavor you are currently selected correctly to enable that flavor.

If we have two build flavor let's say free and pro. If pro is selected is current build flavor. The flavor free will not be shown as java package in blue color as you mentioned, it will be shown as directory structure. Hence change the build variant and make it workable.

Not sure if you faced the same issue, but sharing it for reference of others who might face this issue as i faced now.

like image 189
samuelhard Avatar answered Sep 24 '22 13:09

samuelhard


Package option is available only for selected flavor. switch to desired flavor and IDE will refer that source directory and will convert it to package and directories from other flavors will be listed as normal directories tree structure.

like image 31
Mahesh Avatar answered Sep 22 '22 13:09

Mahesh