Android Studio, when you create a module, automatically creates build types Debug and release .
However, it only creates the source set
main/
.
In order to put code to be used as Build Variants (different versions of the app) of these build types , you must create their source set in>.
To create the source set , follow these steps:
- In the Project panel, choose Project (1).
-
Right-click the /app/src
folder and choose New-> Folder-> Java Folder (3).
In the window that appears, choose debug for Target source set .
Click Finish .
-
Repeat the previous step by shrinking release to Target source set .
Thefolder/app/src
nowhas,inadditiontothe/main
folder,thedebug/
andrelease/
folders
Inthe/main
folder,thecodecommontobothvariantsisplacedinthedebug/
andrelease/
folders,whichisspecifictoeach.
ButfirstyoushouldcreateaPackageineachofthe/debug/java
and/release/java
folders:
- IntheBuildVariants(2)panelmakesurethatthedebugvariant(4)isselected.
- Right-clickthe
/debug/java
folderandchooseNew->Packageandenterthenameofthepackage. - IntheBuildVariants(2)panelselectthereleasevariant.
- Right-clickthe
/release/java
folderandchooseNew->Packageandenterthenameofthepackage.
Thefolderstructurewilllooklikethefollowingfigure:
Beforerunning,choosetheBuildVariantspanel,thevarianttobuild.
Formoreinformation,see Configure Build Variants in the documentation.