0

I want to build an android instant app from my previous app.My main source code is less than 4 MB (Instant App Requirement). But I am using some external libraries those have a size of approx 39 MB. How I can shrink the code to 4 MB?

Is there any possible way to load the libraries dynamically from the internet? Or shrink my code to 4 MB?

ScreenShot

Emanuel Graf
  • 756
  • 17
  • 37
john
  • 2,324
  • 3
  • 20
  • 37
  • 2
    "How I can shrink the code to 4 MB" -- get rid of that library, or do not use it from the Instant App module. Even if you used APK splits, each individual CPU architecture takes up at least 8.5MB, which exceeds your size budget. – CommonsWare May 26 '18 at 13:54
  • But I can not get rid of those libs. I have to use them in the Instant App. Thats the requirement. – john May 26 '18 at 20:23
  • then postpone your project until Google offers bigger Instant Apps – CommonsWare May 26 '18 at 20:29
  • Hmm. Thanks, But I can't. I have to Find some solution. Thanks :) – john May 26 '18 at 20:30
  • @commonswae Isn't there any way to upload the Libs on cloud and call it dynamically by using RPC (gRPC) protocol? – john May 26 '18 at 20:33
  • That would depend entirely on what the library does, what operating systems it runs on, whether its data needs fit a Web service approach, etc. It also is outside the scope of your question. – CommonsWare May 26 '18 at 20:45
  • You might consider asking a separate Stack Overflow question, where you say what library this is and ask whether you could wrap it in a Web service. – CommonsWare May 26 '18 at 20:55
  • can you check URL https://stackoverflow.com/questions/48283683/instant-app-getting-below-4mb-difficulties-how-to-reduce-apk-size and https://medium.com/google-developers/enabling-proguard-in-an-android-instant-app-fbd4fc014518 might it help you. – Prags May 28 '18 at 04:57
  • Split APK's and proguard is your friend. Proguard helps us reduce our app by about half. – dazza5000 May 31 '18 at 02:53

1 Answers1

1

You can reduce your APK size greatly by using App Bundles, which will build split APKs for you (or just do the splits yourself). In your case, only one architecture will be delivered.

On that same page, you can also read about dynamic feature modules. You can develop them now, but uploading to Google Play isn't available to all developers yet.

This may not work for extracting a library unless it's well encapsulated with the user facing feature and code that uses it in your app. So, if your app can't launch without the library, it will not help much.

Also relevant, Google announced a 10MB beta program to increase instant apps size limit: http://g.co/instantapps/10MB

Hassan Ibraheem
  • 2,329
  • 1
  • 17
  • 23
  • Isn't there any way to upload the Libs on the cloud and call it dynamically by using RPC (gRPC) protocol? – john May 26 '18 at 20:32
  • can you check URL https://android-developers.googleblog.com/2017/08/android-instant-apps-best-practices-for.html – Prags May 28 '18 at 04:59