Multiple watch faces/wearapps for one mobile project - android

I'm making an app which needs to be able to connect to multiple watch faces (not at the same time). I have multiple modules in my project. I can't add
wearApp project(':wearApp1')
wearApp project(':wearApp2')
in the same gradle dependencies section.
Is there a way to do this?

You can only have a single Wear module per application, because a requirement for auto-installation is that it have the same package name as its "wrapper" handheld APK. But, you can build that module out with as many watch faces (and whatever else) as you'd like.
A watch face is simply a Service, and you're free to include as many <service /> elements in your manifest as you want. Each will appear as a separate entry in Wear's watch face picker. They can share code or resources if that's helpful to your app's architecture, and in fact doing so is easier when they're all in the same module.
Likewise, that same module can include an Activity, or any other Android components you need. It's a full-fledged app, and can be as complex as required.
But you'll definitely need to merge the code into a single wearable module. If you already have these watch faces as separate modules, the easiest route might be to make them into libraries, and just create a single wearable APK that includes them.

Related

How can I use specific classes when building an apk with Android Studio?

I searched a little about this here but didn't found anything that helps me, maybe because it's impossible but I need confirmation.
The situation is the following:
I have an android app that integrate with many mobile POS, these card machines, and because I have many classes to integrate with these machines, the app became heavy for some POS stores, like Stone.
I saw that it's possible to impplement the libs modules and dependencies for specific flavors with android, so I would generate an specific appp, with just the classes that this integration use and nothing more, but I have everything together now, just like in the pics.
And when I build an app that will be used with Stone, for example, it will put all integrations in the JS interface.
I stated changing it, imlementing by flavor but as the implementation is per integration now, the Cielo class starts having problems with its dependencies because, as the app will be for Stone, it doesn't download the Cielo dependencies. The generation process crash.
When I started changing the structure, I manage to make the gradle build work, but after that, everything crashes.
There is something I can do ? Maybe impost only when the Cielo package really exists, or something like that.
If its needed to change the entire structure, it's ok, I just need to make it smaller but still in one place.
Thanks!
I tried useing flavors and separating the source sets alongside main directory, like:
-main
--assets
--java
-cielo
--java
-stone
bus it still have a problem when building because the import inside my main class.
You can split your application to multiple parts:
Main application which implements the app's features except an integration.
Android service API which defines API between the main application and an integration service
Integration services one for every platform. Each service have to implement API from point 2 to provide required contracts to the main application.
Finally you can deploy the main app and only one required integration service.

Access constant in different modules of Android Studio project

I have a wearOS application combined with a mobile app in Android Studio. I communicate between those two with listeners who listen on certain paths and behave diffently dependent on the messages they recieve.
I had to define the meaning of the messages in each module and thereby violated the DRY-principle.
Is there a way to store a constant so that both modules can access it in their code and/or manifest?
I would suggest creating a new module for the shared code and add it as a dependency for your mobile and wear modules.
Yes, it's a little bit of overhead for just a few constants. But it helps keep things organized.

Android Instant Apps multiple activities

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

How to use classes from mobile module?

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 possible to add a externally-maintained project library, without copying?

I'm working with Android Studio 0.5.8.
I have a Working project, and I want to reuse all its contents to make an almost identical app with only another name and different colors.
Basically I want to make a library from the original app and reuse it in various identical apps, but I don't want to copy & paste inside each new app, I want to maintain and develop only one codebase (the project library).
I have read and read, but I can'tt find any real solution.
I tried this in my settings.gradle:
include ':AppCopy1', ':..:LibraryProject'
It works, but I cant use any classes in AppCopy1.
This sounds like a good candidate for Product Flavors. The Gradle build system has support for maintaining a single codebase and building multiple apps from that codebase that only differ by a few files changes. See the configuration examples here: http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants for details.

Categories

Resources