简体   繁体   中英

Android - How should you manage multiple modules? Manifests, grades, etc.

I understand this question is vague, but can someone outline the rules and/or how we should be dealing with multiple modules? I've been trying to separate my app out into a base feature module, application module and instant app module.

However I've been having a nightmare building it. I've tried searching online but there isn't really much documentation in it?

Ive got two activities in my base module manifest, as I want these in both my installed and instant app. Do I then need to copy these activity manifest entries into my other manifests? I tried running my installed apk without adding in these activities (I thought it might pull it from the base module) but then android studio says can't find default activity to launch the application with. So I need to copy the activity entries into all manifests?

I've also got manifest entry conflicts from all the libraries I'm using. FacebookInitProvider , FacebookInitProvider, CrashlyticsInitProvider etc. I don't have these entries in any manifest, they are adding themselves in to every manifest causing merge conflicts when building.

With the build grades, I've put in the base just the libraries necessary to run the base / instant app (to keep it as small as possible). The installed gradle then has all the extra libraries for the full sized application. If I use implementation project(":base") Will it automatically pull in all the dependencies that base uses? Or do I need to redeclare these? I ask because after getting the app to build, firebase and firestore was causing an exception on getting the instance with the message "Firestore module not found" which makes it look like it hasn't pulled in the dependencies properly?

I apologise for the lengthy post, but I'm honestly at the end of my tether here. Truly stuck!

Im not sure I understand all your project structure correctly so I will give you general information on an app with modules:

Lets say you have the application called "appone" and have a module called "moduleone"

In the module gradle file you declare the minimum you need for the module to work properly by itself and in the manifest just configuration specific for the module that will not be required to be defined in the appone manifest.

Now in the appone manifest, this is the main file, you will have to set here the activity declarations and app permissions (not in moduleone), android studio merges the two files automatically so when you compile it will make one manifest file with both manifests contents so this is what can make conflicts if you declare the same or conflicting data on both files.

In the appone build.gradle file this is where you declare the implementation project(':moduleone'), and the implementation of libraries required by appone. If for example moduleone uses firebase library and in appone you also directly require access to the firebase library you could declare it in both build.gradle files, you just need to make sure both use the same version.

Also you will need to declare moduleone on the settings.gradle file using: include ':moduleone'

appone is declared as an com.android.application and moduleone is declared as com.android.library.

Also appone has in its manifest an activity declared with the LAUNCHER category.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM