Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use a different class for each build variant

I have an Application class that I want to be different in each build variant like debug and release.
this is my map:

app/      
   |      
   |----debug/          
             |----java\            
                       |----com.example.App.class       
             |----res\
                      |----mipmap-hdpi       
   |----main/          
             |----java\      
                      |----com.example.App.class       
             |----res\
                      |----mipmap-hdpi            

but in android studio give me this error message "duplicate class found in ..."
but it does not show any error in my resources.
my question is why gradle cannot figure it out what class should use in different build variant but it can decide what resource must be used in different build variants.

like image 313
max Avatar asked Mar 08 '23 00:03

max


1 Answers

Code under main is shared between all build types. Hence the class is there twice, once from debug and again from main.

To have build type specific source files, put them under build type specific folders instead of main. For example if you have the usual debug and release build types, put the other variant under release.

Why this is not needed for resources is because resource merging can override resources over build types. There is no code merging.

like image 111
laalto Avatar answered Mar 10 '23 09:03

laalto