We do have 2 similar projects for an app. The first one is for my country and the second one is for the EU. They are %90 same may be more. We do want to merge these two projects into one and switch between them with build variants. Is that possible? If it is, how can I do it?
Main Project
@OnClick(R.id.image_view)
public void onClicked(View view) {
if (isXEnabled) {
ImageView.setImageResource(R.drawable.inactive);
ImageView.setContentDescription(getString(R.string.passive));
presenter.sendCommand();
isEnabled = false;
} else {
ImageView.setImageResource(R.drawable.active);
ImageView.setContentDescription(getString(R.string.active));
presenter.disableFeature();
isEnabled = true;
}
}
EU Project
@OnClick(R.id.image_view)
public void onClicked(View view) {
if (isXEnabled) {
ImageView.setImageResource(R.drawable.EuInactive);
ImageView.setContentDescription(getString(R.string.EUpassive));
presenter.sendCommand();
isEnabled = false;
} else {
ImageView.setImageResource(R.drawable.active);
ImageView.setContentDescription(getString(R.string.EUactive));
presenter.disableFeature();
isEnabled = true;
}
}
For example, some drawable is different on EU Project
- Or -
Main Project
@OnClick(R.id.image_view)
public void onClicked(View view) {
if (isXEnabled) {
ImageView.setImageResource(R.drawable.inactive);
ImageView.setContentDescription(getString(R.string.passive));
presenter.sendCommand();
isEnabled = false;
DoSomething();
} else {
ImageView.setImageResource(R.drawable.active);
ImageView.setContentDescription(getString(R.string.active));
presenter.disableFeature();
isEnabled = true;
}
}
Eu Project
@OnClick(R.id.image_view)
public void onClicked(View view) {
if (isXEnabled) {
ImageView.setImageResource(R.drawable.inactive);
ImageView.setContentDescription(getString(R.string.passive));
presenter.sendCommand();
isEnabled = false;
DoSomethingElse();
} else {
ImageView.setImageResource(R.drawable.active);
ImageView.setContentDescription(getString(R.string.active));
presenter.disableFeature();
isEnabled = true;
}
}
In this example we did added different line everything else is similar.
There nearly a thousand of this kind of differences and nearly five hundreds of exactly same classes and two hundreds of new classes.
In conclusion, how can I manage these two projects with build variants in one project?
Edit 2 : I've tried these steps.
- Implement dimensions
- Implement flavor
- Created res,asset,java files for eu project
- Created sourceSet in gradle for eu project
for now build variant looks like this mainDevDebug,EuDevDebug,... etc main...... ones works fine but i had an error for Eu..... ones
Error message while rebuilding or running app:
Could not determine the dependencies of task ':app:compileEuTestDebugJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':app:EuTestDebugCompileClasspath'.
> Could not resolve project :com.xx.core.main.core.
Required by:
project :app
> No matching configuration of project :com.xx.core.main.core was found. The consumer was configured to find an API of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'project' with value 'Eu', attribute 'default' with value 'Test', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but:
- None of the consumable configurations have attributes.