Multi features Instant Apps support is broken :(

Written by elye.project | Published 2017/09/20
Tech Story Tags: android-instant-apps | google | android-app-development | mobile-app-development | android

TLDRvia the TL;DR App

I had the pleasure work on Instant Apps and got released as one of the Instant Apps announced in Google IO 2017. Now planning to enhanced it further to multiple features, using Android Studio 3.0, just realized it is relatively broken :(.

Sharing here, so you could follow up with the issues, without going too far and save hours of time trying to figure out what happen.

Background

Instant Apps has a feature limitation of 4 MB (In fact a combined APK Features loaded shouldn’t be more than 4MB.) Hence given that we want to extend more features to our Instant Apps, we should break it into multiple Features.

The Issues

Unfortunately after quite a bit of exploration, I have given up working on it, and filed 3 issues to Google. Sharing this with all, so that we could check them up if they are resolved before attempting it.

1. Inability to use shrinkResources = true

shrinkResources = true is a setting provided by Android, so that it would optimize the resource usage of the APK, and hence shrink the APK size.

Given size is so crucial for Instant App, I would expect shrinkResources = true should be supported in Feature, especially given each Feature is an APK. However, whenever it is set, during compilation, it will error stating

Error:Resource shrinker cannot be used for libraries.

I understand when compile in App mode,Features are libraries. But in Instant Apps mode, they are APKs. Hence it should be allow to use shrinkResources (It was usable at the start of the Android Studio 3.0 Alpha 4 and earlier)

The issue is reported in https://issuetracker.google.com/issues/65708840

2. Crashlytic fail to register key

If you are using Crashlytic in your App, you could have it work in single Feature Instant Apps. Using the approach shared in

How do I integrate Crashlytics with Android Instant Apps?

When you move to Multi-Features Instant Apps, the compilation will complaint. The reason is, it can’t reads in Key provided.

This app relies on Crashlytics. Please sign up for access at https://fabric.io/sign_up, install an Android build tool and ask a team member to invite you to this app’s organization.

There’s a workaround in the stackoverflow for it, but it will still break the Continuous Integration (CI) flow, as that workaround, once applied will complain duplicate resources found.

Crashlytic now belongs to Google. So I don’t see why it should be broken when using with Android Instant Apps.

The issue is reported in https://issuetracker.google.com/issues/65804378

3. Proguard across Features is oblivion

As we have multiple Features (APK), each has to be Proguarded, if you want to optimize and obfuscate it before release. Also this is so important, as it could shrink your APK size in magnitude.

Unfortunately, if you use Proguard for each Features, I suspect it is unaware that the Features are related to each other. Hence the optimization done would optimized more than it should, and obfuscate would rename to something unmatchable across Features.

When you run your App, you’ll get something like

java.lang.ClassNotFoundException: could not find com.elyeproj.myapplication.feature.MainActivity in any atom class loader or parent class loader

to solve, this, you have to protect your classes one by one. I gave up trying, and just use keep class ** { *; } and all went back to normal. This is as good as not Proguarding.

Surprising to me is, even if I just create the Instant Apps Empty Activity default project generated by Android Studio 3.0, turning ON Proguard for the features, would also fail the project in run time.

Among the 3 issues, I would say this is the major one that prevents Multi-Features Instant Apps to be in an acceptable usable state for Release.

The issue is reported at https://issuetracker.google.com/issues/65710224

I have dropped emails to some Google Rept on these matters, and also file the 3 issues. I hope they would get addressed soon. Anyway at the time of writing, Android Studio 3.0 is still in Beta (6) mode, it’s acceptable that there’s problem still.

My sincere hope is by Android Studio 3.0 full release, all this would have been resolved and simplified much better.

If you like my post and want to get future update, follow me at medium or Twitter or Facebook


Published by HackerNoon on 2017/09/20