Refactoring an existing Android app to support Instant App.

This article is not exactly an introduction or guide to Instant App. There are plenty of good articles on this topic. I am just going to share some difficulties we faced while refactoring an existing android app for Instant App support.

Existing Project Structure:

The existing project was on MVP architecture and had all common libraries like Dagger2, Butterknife, RxJava etc. Here is a screenshot of all the dependencies we had in our existing project.

Refactoring Process:

Step 1: Prerequisites

According to official documentation, these are the prerequisites for getting started with Instant App.

  • Install Android Studio version 3.0 or later.
  • JDK 1.8
  • Android SDK 6.0+
  • Android SDK Build Tools 26.x or later
  • Android SDK Tools 25.x or later
  • Android SDK Platform Tools 25.x or later
  • Android Support Library (latest)
  • Android Repository (latest)

Thankfully our app satisfied all of these prerequisites.

Step 2: Installing the Instant Apps Development SDK

This was a very easy step, nothing fancy. Just launch SDK Manager, Go to SDK Tools, Select Instant Apps Development SDK and click apply. That’s all. So far so good.

Step 3: Implement Android App Links

App links were introduced in Android 6.0. Instant Apps leverage the same app links feature to map HTTPS URLs to entry-point activities in Instant Apps. Here is a great video to get started with App links!

Step 4: Break your app to Feature Modules

In order to support Instant App feature you have to break your app into Feature Modules. This was the step where we faced most of the challenges. I am going to list down all of them:

Problem 1: Kotlin plugin version

We encountered this problem while converting our App application module to Feature Module. Here is a part of the error message:

null cannot be cast to non-null type


Problem 2: Android Studio Issue(3.0 Canary 3)

After solving the kotlin plugin problem we faced another issue. Here is a part of the error message:

point to same directory in the file system. Each module has to have a unique path.


Problem 3: Same build.gradle file

After solving Problem 2 our build failed once again. Here is the error message we got.

Error:Failed to resolve: Could not resolve project :Social-News.


Problem 4: ButterKnife Problem

After solving problem 3, we got complains from ButterKnife. Tried adding ButterKnife as we add them to library projects, but no luck. As we all developers do, I went to Github to check issues.

I found the following closed issue:

Which was a duplicate of this open issue:

Someone suggested a workaround of moving the butterknife plugin locally into project’s buildsrc. I tried that too, but did not work for me.


If someone finds a real solution to this problem please do comment below.

After solving these problems we were able to successfully build(with one base module) and install the apk to device. Since our original apk size was less than 4Mb, we were able to install the full featured app as an Instant App.

Problem 5: Only TLS protocol like HTTPS:

After installing the apk, we found some of our screens were not displaying anything. After checking the logcat we got to know that network traffic from inside the Instant App must be encrypted using a TLS protocol like HTTPS.


Finally we had a working Instant App.

But our current Instant App consists only one base feature module which is actually the whole app. We were not satisfied with this so we decided to add another feature module to the project. This module will have only one Activity which is actually needed for our Instant App.

Problem 5: Android studio Feature Module Wizard

As soon as I added one new feature module to our project using Android studio Feature Module Wizard, I got this error:

Project refresh failed:

To solve this problem these are the things We tried, which did not work for us:

  • Clean Project
  • Re-import project
  • Restart android Studio
  • Clear cache
  • Re-install android studio(Yes! Tried this too.)


After solving this problem we were able to build the project successfully.

Problem 6: A Strange One

I updated my android studio to 3.0 Canary 5 and my build started to fail. Here is the error I got:

Error:(2) attribute 'split' in <manifest> tag is not a valid split name

I was surprised to see something like this. Since AS was in canary channel, I was also not sure whether the problem is causing because of the update or not.


I have seen ‘ — ’ in module names in Google Sample projects and it was working for me earlier. So, I don’t know what’s the exact reason causing this issue. Therefore, I have convinced myself for now with this gif.

These were the main difficulties we faced during our first Instant App development period. Not as smooth as the demo video at I/O 17 right? I still have one problem(Not related to Instant App) left related to Dagger2 which is more of an Architecture level problem, That’s why I am not including it right now. If you have faced any other problems or if you have any better solutions please let me know in the comment section below.

If you liked this article please click the 💚 below to recommend. I would love to hear your thoughts in the comment section or at Twitter. Thanks a lot !


Our community publishes stories worth reading on software development and design. Android | Machine Learning | #MakeEveryoneCode

Bedanta Bikash Borah

Written by

Android Dev. ML Enthusiast. Marvel, DC and STAR WARS fan. Self proclaimed Designer ;) Novice Traveller.



Our community publishes stories worth reading on software development and design. Android | Machine Learning | #MakeEveryoneCode

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade