I am creating an instant app, which include application module, base feature module, instant app module and an another feature module. Problem is i am not able to access the activities of application module from base-feature and feature module and same between base-feature module and feature module but i am able to access activity of base-feature module from application module.
Right now i am accessing the activities using :
Intent i = new Intent(this,
Class.forName("com.demo.test.appmodule.TextActivity"));
by this method studio don't show me any errors at compile time.
Is there any other way for communication between two different feature modules?
Why i am able to access base-feature module activity from application module but not vice versa?
can we access activities of application module from base or any other feature module?
Can i have a link which define the project structure for an instant app
Thanks in advance
The reason why you can't communicate directly between features is because they're independent from one another.
The correct way to handle this is calling it with its URL, example: android-instant-apps/hello-feature-module/HelloActivity.java
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("https://hello-feature.instantappsample.com/goodbye"));
intent.addCategory(Intent.CATEGORY_BROWSABLE);
startActivity(intent);
In an instant-app structure, the base acts as a library for the feature modules, and the features are built into APKs. In an installed-app structure, both the base and features act as libraries for the application module. Some explanation can be found here:
Why use the new Android feature plugin over the library plugin?
Android: Can you add activities to the Instant App module?
There used to be a page # https://g.co/instantapps that explained the structure of instant apps, but looks like it's missing. However, you can take a look at:
https://android-developers.googleblog.com/2017/08/android-instant-apps-best-practices-for.html
bottom of page # codelabs/android-multi-feature-instant-app/#3
And no, you won't be able to directly access activities of the application from a feature. As an installed-app, com.android.feature modules are compiled/behave as com.android.library modules, so apply the same rules here: the application depends on the library, not the other way around. To traverse that direction, you will need to use the same kind of Intent as shown above.
Anything in com.android.application will be isolated from the feature modules of the instant-app, and will only appear in the installed-app.
Related
I have an app module and a feature module named LoginModule.
I would like to call a method inside the app module from LoginModule.
Is there any way?
Of course, I know this is not standard at all. But I have to use it temporarily.
Because I just wrote part of the application as a module (LoginModule) and the rest of the application is still in the main/app module and I have to go back to the main/app module to run the rest of the application.
I plan to solve this problem with Navigation-Component in the future.
I'm trying to improve my app dependencies and came across a problem. My code base is shared with another app, so I have modules that are shared between these two apps. The below image is a simplified version of what I currently have.
Currently, my app build gradle sets the AppNetwork dependency as implementation and the AppNetwork declares the SharedNetwork dependency as api. It's api because app module needs to know stuff about the SharedNetwork module (more on this next). App module also implements the SharedFuncionalities module.
SharedNetwork contains an INetwork interface. This interface is extended by IAppNetwork interface that it's implemented by AppNetworkImpl (the latter two files are placed in the AppNetwork module).
Here is an example of why this is being set like this.
My app module creates AppNetworkImpl and also creates an ItemRepository (location is inside the SharedFuncionalities module) that takes INetwork (implemented by AppNetworkImpl) as a param in its constructor. This allows the ItemRepository to "talk" with the SharedNetwork module.
If I set AppNetwork to declare the SharedNetwork dependency as implementation thus making my app module unaware of the SharedNetwork (that makes sense to me. I would then use AppNetworkImp as the bridge between the app module and the SharedNetwork module) I then lose the ability to create objects in the SharedFuncionalities that use AppNetworkImpl as the bridge for using the SharedNetwork.
What I would like to know if I have the possibility of the app module only knowing about AppNetwork but still create objects in SharedFuncionalities that can "talk" with the SharedNetwork.
I'm creating a sample app which I'm following the clean architecture, my app structure now is like this :
:app
:firebase
:library_base (which contains all the baseActivity, baseFragment, etc.. I know I could create a base_ui, base_data, module, but let's first solve this question that I'm having right now)
:networking (which contains retrofit stuff)
feature1
feature2
....
So now, my question is, now I do not need a core module, but in case one of my featureX, needs a dependency from featureY, what should I do in this case? I'm used to have a core on my app that contains stuff like LoginSettings which contains data from the user logged and things like that, and now if I'd have to do this I could not because featureX can not depend on app, so that's why I'm thinking about adding a core module and insert all of the needs from featureX there so they can use it. (Yes, I said "all of the needs", I did not mean to create a god module, but just to start the app).
Is it necessary to create a core module? I'm not using dynamic feature tho, and also I'm seeing that on each build.gradle files I'm duplicating a lot of dependencies...
From now in the app I have everything with api should I put that in the core?
One approach would be create modules "with UI" (call them features) and "without UI" (call them libraries).
Rule is "features" can not depend on each other directly, they can only depend on "libraries". While "libraries" can depend on each other.
Now LoginSettings, SessionConfigs kind of things can be a "library" where multiple "features" (UI) can depend on. Not all features has to depend on that "library".
just like all of you, I've made MyFirst Instant App from AndroidInstantAppDemo, but what if I want to add more activities into my app?
I want to provide multiple links for them.
Should I simply add all of those activities under app module and provide dependencies{... implementation project (":base") } in build.gradle.
Along with that, adding the different path with same host address in .manifest file.
Or
Put all the activities under base module only.
If yes (2nd options), does that mean that we should transfer data from app module to base module, in order to add InstantApp functionality into our project.
I think I'm not very familiar with all three modules of them, and the PROJECT STRUCTURE just provided an overview of these modules. Can anyone help?
Basically both your Instant app module and application module depends on feature modules. As far as I know Instant app and application module does not contain any activities.
Out of all these feature modules there should be a baseFeature module. The feature modules should be less than 4mb in size. Now, when a linked is clicked for an Instant app, Google Play downloads base + feature1 apks and installs them in background. If you wants to travel between feature modules you can do that by using deep links.
A feature module can contain any number of activities but with the constraint that it's size should be less than 4 mb.
I will suggest not to put any activities in application module. Just make some feature modules and link them with a URL. The feature module works like a library generating an aar file for your installable app.
If you want to provide multiple links, maybe this can help - Here
I would like to have a little bit of information before starting a new android project. I have read that the android-maven plugin works nice and smooth... Is that true?
And more important, what are its possibilities? I have something in mind.
Let's say I want a modular application. Thus, I want an app made of apps (all of them android-maven). Imagine I have an app for log in in some server, an app that connects to a service1 to get some information and another one that gets information from another service2.
Can I create three individual apps (log in, service1 and service2) and then use them as a dependency on a container maven app?
Is is worth it?
Thx! E.
Maven is great project management and build tool, and can be used to build android applications with proper plugin ( maven-android-plugin IIRE provides apk packaging )
But you do not build PAK from another apks, but plain java jars - zou can tap whateveryou like form wast maven repository of jars but have to keep in mind that not every java jar or framework is usefull, makes sense , or will run on android.
There is no such thing as "container app" on android - but you can define dependencies
to other apps and android library porjects. And applications can (and should) communicate via intents and exported services.