Android Studio, when creating a module, automatically creates the build types debug and release.
However, it only creates the source set
main/
.
So you can put code to be used as Build Variants(different versions of the app) from these build types, has to create their own source set.
To create the source set, follow the following steps:
- On the panel Project choose the view Project(1).
Right click on the folder /app/src
and choose the option New->Folder->Java Folder(3).
In the window that appears, choose debug for Target source set.
Click on Finish.
Repeat the previous step, shrinking release for Target source set.
The briefcase /app/src
will now, in addition to the folder /main
, the folders debug/
and release/
In the folder /main
the code common to both variants is placed in the folders debug/
and release/
, which is specific to each.
But first, you must create a Package in each of the folders /debug/java
and /release/java
:
- On the panel Build Variants(2) ensure that the variant is selected debug(4).
- Right click on the folder
/debug/java
and choose the option New->Package and enter the name of package.
- On the panel Build Variants(2) select the variant release.
- Right click on the folder
/release/java
and choose the option New->Package and enter the name of package.
The folder structure shall be identical to the following figure:
Before running, choose from the panel Build Variants, the variant to be built.
For more information see Configure Build Variants in the documentation.
This is possible. but when using debug and release variants if, for example, Mainactivity calls methods of this class it has to exist in both variants, however the methods may have different implementations. If that’s a deterrent, you’ll have to use Flavors.
– ramaral