0

I'm in the process of converting my android app to an instant app, following this tutorial.


For now, I have split my app module to two:

  • base module which contains the code
  • installed module, used for the non-instant-app version of the app

Before the split, in my only module (app) I was using the google-services plugin. After the split, I have moved the plugin to the installed module, as that's where it seems to need to be so that it will generate strings.xml from the google-services.json file.

The problem is, in the base module I have some code that tries to access a variable generated by the google services plugin: R.string.default_web_client_id, which is now not available, producing a compile error.


I need to somehow gain access from the base module to that generated value, without introducing a cyclic dependency...

Minas Mina
  • 2,058
  • 3
  • 21
  • 35
  • You may find some help about the structure of the instant app from https://stackoverflow.com/questions/51035892/how-can-i-access-an-activity-from-another-feature-module/51049978#51049978 – TWL Oct 30 '18 at 21:41
  • But in short, when your project is built as an installed-app, the base-module is compiled as a library for the installed module. And if it is built as an instant app, nothing from the installed module will be available to the instant app. – TWL Oct 30 '18 at 21:43

1 Answers1

0

You just can't access classes or values of child modules from parent modules.

I faced this same problem when I first converted a project to modules in order to run it as an instant app. The solution I successfully applied to overcome it was creating set methods in the parent module's classes that where using values from it's child modules, and calling them from child module's classes.

Example:

In the parent module you have

class ParentModuleClass {
  private String defaultWebClientID = null;

  public void setDefaultWebClientID (String defaultWebClientID) {
    this.defaultWebClientID = defaultWebClientID;
  }

  private yourMethod () {
    ...
    if (defaultWebClientID != null) {
      //use defaultWebClientID
    }
    ...
  }

}

And in the child module you have this constructor

import com.app.parent.ParentModuleClass;
import com.app.child.R;

class ChildModuleClass {
  public ChildModuleClass (ParentModuleClass parentClassObj) {
    parentClassObj.setDefaultWebClientID(R.string.default_web_client_id);
  }

}
henrique
  • 28
  • 3