Sumit Sahoo
Sumit Sahoo

Reputation: 3219

How to resolve circular dependency in module using Gradle?

The project structure is like this

  1. Main Module : This is the base App Code
  2. Enhancement Module 1 : This is an addition of extra feature and it has it's own Activity and it uses some code from Main Module.
  3. Enhancement Module 2 : Same as Module 1 but a separate developer is working on another feature. Also uses some code from Main Module.

Now as Module 1 and 2 has their own Activity which needs to be invoked from Main Module, there rises an problem with circular dependency. Main Module needs to invoke Activity from Module 1 and Module 1 needs some code from Main.

So how to resolve these kind of dependency problem in Android Studio using gradle ?

Upvotes: 4

Views: 8854

Answers (2)

AtomicBoolean
AtomicBoolean

Reputation: 1210

You can do this via an implicit Intent. Let's say you want Activity1 in Module1 to start Activity2 in Module2, but you can't because that would cause a circular dependency. Go to the AndroidManifest.xml in Module2 and set android:exported="true" as a property on the Activity2. Then, in Activity1, do this:

Intent intent = new Intent();
intent.setComponent(new ComponentName("com.example.module2", "com.example.module2.Activity2"));
startActivity(intent);
finish();

Upvotes: 3

Johan Stuyts
Johan Stuyts

Reputation: 3687

Move the common code used by the two enhancement modules to another module, and create two application modules:

  • common
  • enhancement 1 depends on common
  • enhancement 2 depends on common
  • app 1 depends on enhancement 1
  • app 2 depends on enhancement 2

If needed created another module common-app to contain the common code shared between the two applications.

Upvotes: 3

Related Questions