15

When I try to shrink my Feature APK size, I use shrinkResources true in my feature Build Gradle. However it complaints Error:Resource shrinker cannot be used for libraries.

This article ask us to use it https://medium.com/jet-stories/make-your-app-instant-33855ab5d02b

Did I do something wrong or is this really not supported by Instant Apps?

Elye
  • 53,639
  • 54
  • 212
  • 474
  • 1
    This might be a possible issue in the recent Gradle versions. `shrinkResources` works fine for me on AS 3.0 Canary 4. But when I tried to use `shrinkResources true` in AS 3 beta 4, I got the same error as you do. Can you file a bug, then link to it back in here? It would be helpful for all, thanks! https://issuetracker.google.com/issues/new?component=316045&template=1018787 – Julia K Sep 15 '17 at 00:08
  • Thanks. Filed on https://issuetracker.google.com/issues/new?component=316045&template=1018787 – Elye Sep 15 '17 at 03:14
  • @Elye Can you share the link to the issue? I'm unable to find it https://issuetracker.google.com/issues?q=componentid:316045%20shrinkResources nor https://issuetracker.google.com/issues?q=componentid:316045 Thanks! – Xavier Rubio Jansana Sep 15 '17 at 06:04
  • 1
    Ops, there you go. https://issuetracker.google.com/issues/65708840 – Elye Sep 15 '17 at 06:30
  • Disappointed that AS3.0 has been officially released, yet ShrinkResources is still not usable for IA :( – Elye Oct 26 '17 at 23:59

3 Answers3

8

From what I understand from the article (I've just read it quickly, still pending in my reading list), shrinkResources true is only needed to reduce APK size by removing unused resources, but it is not a formal requirement of Instant Apps. I guess the toolchain cannot decide if a resource will be unused in a library, as final APK is not built.

So, if there are no unused resources in your project, should not be a problem and could be removed.

Then, there is one thing that maybe is wrong in your project (without having tried Instant Apps by myself, just read and saw Google IO talks): from what I understand, all the modules of an instant app are APKs, not libraries. So, if you apply the shrinkResources true to the APKs, you should be good to go. If you have libraries in your project that are used to assemble the final APK modules, then remove shrinkResources true there, and just leave it in the modules.

Xavier Rubio Jansana
  • 6,388
  • 1
  • 27
  • 50
2

I think this is not and AndroidStudio bug, but a Gradle bug. I'm trying to build with Jenkins, with an updated version of Gradle (previousely used com.android.tools.build:gradle:2.2.3, upgraded it to com.android.tools.build:gradle:3.0.1) and I still get the error

"> Resource shrinker cannot be used for libraries."

Santacrab
  • 3,165
  • 2
  • 25
  • 31
  • If you have different problem, Can you ask as question and file a bug to Google and then link to it back in here? It would be helpful for all, thanks! https://issuetracker.google.com/issues/new?component=316045&template=1018787 – Prags Feb 22 '18 at 05:52
1

With Reference to Google issue tracker

The fix will be in 3.2 canary 1 and afterwards release.

I just tried it again on 3.2 canary 3 and it was working. Are you sure you updated the plugin version to 3.2.0-alpha03? It's easy to overlook.

If any issue persists, please report at Google issue tracker they will re-open to examine.

Prags
  • 2,457
  • 2
  • 21
  • 38