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
Related
I want to build an app with different configurations. Let's say there are two flavors, A and B, which depend on different third-party libraries to perform similar tasks. I want to offer a default configuration on Google Play which comes with a separate launcher for each flavor. Both launcher instances should share local data. However, I also would like to keep the option to build and ship just one of the flavors without including the third-party libraries required for the other one.
From what information I've found, I could either use a single flavor with two launchers, losing the option to build just for one of the third-party libraries. Or I could use two flavors, but would have to separate the whole project into multiple apps with separate ids which would have to be updated separately, presumably require more storage and require some kind of workaround for sharing local data.
So, is there a way to build multiple flavors into a single app bundle with separate launchers or a similar solution for these requirements?
is there a way to build multiple flavors into a single app bundle with separate launchers
I am assuming that by "flavors" you mean product flavors in the Android build system. If that is correct, then... no, sorry, there is no simple option for this.
or a similar solution for these requirements?
It might be possible to pull off something like this with a careful subdivision of your app into modules. You would have three app modules — I will call them a, b, and ab after your naming system. Those would be as small as possible. Most of your code would reside in a series of library modules. In particular, code tied to each third-party SDK would be isolated in its own library (or libraries). a would link to library modules tied to one SDK (plus common modules), b would link to library modules tied to the other SDK (plus common modules), and ab would link to (probably) everything.
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.
Some time ago i created a wear module on existing project.
Both modules have identical Application ID and packages.
Is there any possibility to solve this problem without creating new Android Library to contain classes which i want to be shared? (I have too many files and it will take too much time to fix project)
Afraid not (there is no "possibility... without creating new Android Library"). The handheld and wearable apps are distinct APKs, running on separate devices, and cannot share code at runtime. You need to move your common code into a library that will be compiled into into both.
Is it advantageously to have multiple modules in an Android Studio Project over having only a single large app-module?
I know about Android Modules in general and the advantages of SOLID so my focus is especially considering build performance. As gradle can do incremental builds, and if only one module changes, those other modules don't need to be processed?
Is this noticeable or is there even a considerable amount of overhead?
It is of great advantage to have multiple modules rather than to create a single large app-module. Following are the key points:
If you find the compile time is taking longer then you can disable the module from gradle you are not working upon temporarily and compile it faster.
A module helps us to divide project into discrete units of functionality also. You can create one data module which contains all pure java beans and can be used by multiple app if you are in same domain. Eg. Finance domain can have two applications one for viewing policies for customer and other can be for an insurance agent for viewing the same data. But the data module can be shared across all apps and even the data module can be borrowed from server or API team. Data module can be tested individually without any android dependencies and any one knows about java can write test cases.
Each module can be independently build, tested, and debugged.
Additional modules are often useful when creating code libraries within your own project or when you want to create different sets of code and resources for different device types, such as phones and wearables, but keep all the files scoped within the same project and share some code.
Also Android app module and Library module are different.
You can keep two different versions of module based on the API releases as from ASOP.
You can have a look for more on android developer resource
How modularization can speed up your Android app’s built time
App modularization and module lazy loading at Instagram and beyond
Modularizing Android Applications by Mauin
Survey on how Android developers were modularising their apps
There was an article on Medium yesterday, which exactly adresses my question:
https://medium.com/#nikita.kozlov/how-modularisation-affects-build-time-of-an-android-application-43a984ce9968#.at4n9imbe
tl;dr:
First and most important, the hypothesis was correct, modularising project can significantly speed up build process, but not for all configurations.
Second, if splitting is done in a wrong way, then build time will be drastically increased, because Gradle build both, release and debug version of library modules.
Third, working in test-driven way is much easier for a project with multiple modules, because building a small library module is way faster then the whole project.
Forth, doing many things in parallel slows down the build. So having more powerful hardware is a good idea.
Below you can find results of all experiments described in this article
Update
Addressed at Google I/O '17: https://youtu.be/Hx_rwS1NTiI?t=23m17s
i'll try to better explain my question.
We are are developing a business application for a target customer.
This application has some function very specific for the customer but the core should be re-used for other customer.
For istance the log-in activity would be the same for all customers, but customer A could see activity A and customer B could see activity B and so on...what part of the app to show is managed from the data returned by log in.
I'd like to have only ona project in order to better mantain it....but here my question:
i create the application for customer A, with common activities and custom activities.
I put this application with package name com.mybigapplication and with apk name mybigapplication.apk in the play store.
Customer A download install and use it.
Now I have customer B, I take the same project, I'll add the custom activities for customer B and I'd like to put the app in the play store.
Here my problem if i put the app with same package and apk name the customer A will update the app without any reason...
How can I do ?
Is there a way to manage this problems ?
Please notice that I haven't already put anything in the store.
Best regards
The way to go is putting the common code in an Android Library project, that the specialized apps for customer A and customer B will depend on. So you will have 3 projects in Eclipse:
common (Library)
customerA (Android)
customerB (Android)
An Android application is uniquely identified by the package attribute in AndroidManifest.xml. The two android projects can (actually must) have different package attribute in their manifest, that's how upgrading one app will not affect the other.
For more details on library projects, see the docs:
http://developer.android.com/tools/projects/index.html#LibraryProjects
This article may also be helpful:
http://blog.donnfelker.com/2010/08/05/howto-android-full-and-lite-versions/
A trivial solution would be to create 2 separate projects with different package names.
Then write a shell script or something that just periodically copies all the source files from the directory of project A to project B.
You have to be careful not to copy stuff that might mess up configurations etc. You'll have to manually adjust those. for example, the manifest file can't be copied directly; You'll have to manually add any activities, Services etc in Project A to Project B's manifest too.
Another option is to create an Android library project with the shared code and just include it in both the projects. Here's a tutorial on this.