Several goals in android studio

I am working on a project for an educational university, where 5 separate universities each university has its own application , but in each application the image is json , and the source code remains the same. I want to create 5seperate apks with a different package name using only one source code, and if any change made in the source code should be updated in all apks.

please give me the project structure, setting up the graddle.build tool, and if I need to make a library, how and where it will be, or please upload a sample to do the type above in detail.

+5
source share
2 answers

The following Android Developers Guide Configuring Gradle Builds I was able to create an application that uses the same code with different resources.

Firstly, after creating a new project in Android Studio (Gradle: Android Module), I added the build.gradle file (located in your modules directory, for example, "Project / app / build.gradle"), "blue" and "red" aromas:

android { // ... productFlavors { blue { applicationId 'com.example.app.blue' versionName '1.0-blue' } red { applicationId 'com.example.app.red' versionName '1.0-red' } } } 

The IDE requested to sync project files with Gradle, so I did this. Then I added the colors.xml resource file to the “red” flavor by right-clicking on the “application” directory in the root of the project in the Project panel (“New” → “Android resource file”, selected “red” as the source set )

Next, I changed the new file to contain the definition of a color resource:

 <?xml version="1.0" encoding="utf-8"?> <resources> <color name="primary">#ff0000</color> </resources> 

I did the same for my blue fragrance (but with a different color value).

I changed the background color of the activity layout, created automatically when creating a new project, to see if it will work.

 <RelativeLayout ... android:background="@color/primary" /> 

The panel "Switch assembly of options in the panel" Assembly options "(opened by the names of the lower left buttons) led to different background colors in my activity.

I assume that you save your images, json and other files in Android, restores directories, so the way you have to store different files in different versions is similar to what I achieved.

See this site for a better understanding of product tastes and build options.

+8
source

project structure for generating multiple apks using single source set

  • main - parent directory with source code, res, assets.
  • flavour1, flavour2, flavour3 - my child directory, where they have different images, json and are placed as shown in flavour1, similarly done with flavour2, flavour3.

  • Using the build option, select the taste to launch and the corresponding apk.

  • any resources that are placed inside the flavor redefine the resources inside the main one, so the images and localjson flavor1 are filled.

0
source

Source: https://habr.com/ru/post/1214341/


All Articles