How to compile 1 of the several projects in Android?

Hello. There is an Android project to work with different API (vk, ok, fb...). Now there is 1 class, which defines all the functions to work with API. For example: vkPost(), vkDeletePost(), okPost(), fbPost() and TP. Want to create separate classes for each SOC. network (VKConfig, OKConfig, FBConfig...). The rest of the code, in addition to resources, the same. Resources for each SOC. networks are in the folder app/src/appForVk/res app/src/appForOk/res app/src/appForFb/res. With them everything is OK When compiling, I choose which project you want to build. Question: how do similar way to add and the 3+ .java class. To all moved up, and the only one who requested. Now gragle:
productFlavors {
 appForVk {
 applicationId 'com.social.myapp.vk'
}
 appForOk {
 applicationId 'com.social.myapp.ok'
}
}
.

Thank you.
August 23rd 19 at 10:44
1 answer
August 23rd 19 at 10:46
Solution
Try this:
1) create an interface to work with different APIs
public interface SocialApi {
 void post(Post post);
 void deletePost();
}

2) for each SOC.network implementate this interface
public class VkApi implements SocialApi {
@Override
 void post(Post post){}
@Override
 void deletePost(){}
}

3) in productFlavors prescribed
productFlavors {
 appForVk {
 buildConfigField("com.social.myapp.SocialApi", 'api',", new com.social.myapp.vk.VkApi()")
 applicationId 'com.social.myapp.vk'
}
 appForOk {
 buildConfigField("com.social.myapp.SocialApi", 'api',", new com.social.myapp.ok.OkApi()")
 applicationId 'com.social.myapp.ok'
}
}

4) then in the BuildConfig will be generated field
public static final com.social.myapp.SocialApi api = new com.social.myapp.vk.VkApi();

Using BuildConfig.api can work with the social network and the implementation of the class is going to be substituted for different ProductFlavor
Thanks for the proposed solution. Digging in the Internet I found this option: create a folder for each of the social sphere (app/src/appForVk/java, etc.), it is the Settings folder, and in it the file Settings.java. Now everything is working. In the main class simply import Settings (import Settings.Settings;), and from there you can call functions. But I note Your version as a solution. Thank you. - yasmeen_Hoppe commented on August 23rd 19 at 10:49

Find more questions by tags AndroidJava