The application consists of 3 packages:

  • Presentation (Contains dependencies android API)

  • Data (On pure Java, without android dependencies, is responsible for working with the server)

  • Domain

The question is how to make it so that when building this (or another) version, the API address to which we refer changes.

In the first package, we can create buildVariants->productFlavors (we change applicationId and it will work).

But these build options do not affect the Data package. What to do?

 Presentation(Имеет зависимость от Domain) src- main-java stage-java Domain(Имеет зависимость от Data) Data(На чистой джаве, нет зависимостей андроида) src- main-java-Const->www.adders.com stage-java-Const->www.stage.adderss.com 

When I change to Presentation productFravors , the Data module ignores this. How do I make the Data module going in different ways.

    1 answer 1

    You can do this if I correctly understood the question.

     productFlavors { target1 { applicationId "com.target1" buildConfigField "String", "BASE_URL", '\"http://baseurl1.com/\"' } target2 { applicationId "com.target2" buildConfigField "String", "BASE_URL", '\"http://baseurl2.com/\"' } } 

    and then in your Data class use BuilConfig.BASE_URL. When you change the target, the URL will change to the appropriate.

    • In the presentation package, that's exactly what I do. Only without BuildConfig, because BuildConfig is unique for each package. And if I specify the base URL in the reenactment, then the date of this is not known in the package - Garf1eld
    • I updated the question - Garf1eld