Repository navigation
Generates huge APKs #10717
Copy link
Copy link
Closed
Labels
platform-androidAndroid applications specificallyAndroid applications specificallyt: gradle"flutter build" and "flutter run" on Android"flutter build" and "flutter run" on Android
Description
tl;dr
why package arm, x86 and x86_64 runtimes with each apk? Use this technique
https://developer.android.com/studio/build/configure-apk-splits.html
Brought down the apk size from 20m to 9m
The Long version:
Steps to Reproduce
Build the hello world sample.
Logs
kamathln@laxX550L:~/exp/android/fluttersamples/myapp/build/app/outputs/apk$ ls -lh
total 44M
-rw-r--r-- 1 kamathln kamathln 22M Jun 11 16:59 app.apk
-rw-r--r-- 1 kamathln kamathln 40 Jun 11 16:59 app.apk.sha1
-rw-r--r-- 1 kamathln kamathln 22M Jun 11 16:59 app-debug.apk
Unzipping, I find this:
kamathln@laxX550L:~/exp/android/fluttersamples/myapp/build/app/outputs/apk$ mkdir apkcontents
kamathln@laxX550L:~/exp/android/fluttersamples/myapp/build/app/outputs/apk$ cd apkcontents
kamathln@laxX550L:~/exp/android/fluttersamples/myapp/build/app/outputs/apk/apkcontents$ unzip ../app.apk
Archive: app.apk
inflating: AndroidManifest.xml
inflating: META-INF/CERT.RSA
inflating: META-INF/CERT.SF
inflating: META-INF/MANIFEST.MF
inflating: assets/app.flx
inflating: assets/icudtl.dat
inflating: classes.dex
inflating: lib/armeabi-v7a/libflutter.so
inflating: lib/x86/libflutter.so
inflating: lib/x86_64/libflutter.so
extracting: res/mipmap-hdpi-v4/ic_launcher.png
extracting: res/mipmap-mdpi-v4/ic_launcher.png
extracting: res/mipmap-xhdpi-v4/ic_launcher.png
extracting: res/mipmap-xxhdpi-v4/ic_launcher.png
extracting: res/mipmap-xxxhdpi-v4/ic_launcher.png
extracting: resources.arsc
kamathln@laxX550L:~/exp/android/fluttersamples/myapp/build/app/outputs/apk/apkcontents$ ls -l
total 132
-rw-rw-rw- 1 kamathln kamathln 2344 Dec 31 1979 AndroidManifest.xml
drwxr-xr-x 2 kamathln kamathln 4096 Jun 15 10:06 assets
-rw-r--r-- 1 kamathln kamathln 108516 Dec 31 1979 classes.dex
drwxr-xr-x 5 kamathln kamathln 4096 Jun 15 10:06 lib
drwxr-xr-x 2 kamathln kamathln 4096 Jun 15 10:06 META-INF
drwxr-xr-x 7 kamathln kamathln 4096 Jun 15 10:06 res
-rw-rw-rw- 1 kamathln kamathln 1156 Dec 31 1979 resources.arsc
kamathln@laxX550L:~/exp/android/fluttersamples/myapp/build/app/outputs/apk/apkcontents$ cd lib
kamathln@laxX550L:~/exp/android/fluttersamples/myapp/build/app/outputs/apk/apkcontents/lib$ ls -lh
total 12K
drwxr-xr-x 2 kamathln kamathln 4.0K Jun 15 10:06 armeabi-v7a
drwxr-xr-x 2 kamathln kamathln 4.0K Jun 15 10:06 x86
drwxr-xr-x 2 kamathln kamathln 4.0K Jun 15 10:06 x86_64
kamathln@laxX550L:~/exp/android/fluttersamples/myapp/build/app/outputs/apk/apkcontents/lib$ cd x86
kamathln@laxX550L:~/exp/android/fluttersamples/myapp/build/app/outputs/apk/apkcontents/lib/x86$ ls -lh
total 20M
-rw-r--r-- 1 kamathln kamathln 20M Dec 31 1979 libflutter.so
kamathln@laxX550L:~/exp/android/fluttersamples/myapp/build/app/outputs/apk/apkcontents/lib/x86$ cd ..
kamathln@laxX550L:~/exp/android/fluttersamples/myapp/build/app/outputs/apk/apkcontents/lib$ cd x86_64/
kamathln@laxX550L:~/exp/android/fluttersamples/myapp/build/app/outputs/apk/apkcontents/lib/x86_64$ ls -lh
total 21M
-rw-r--r-- 1 kamathln kamathln 21M Dec 31 1979 libflutter.so
As you can see, the x86, x86_64 and arm runtimes are all bundled with each apk.
I tried removing the x86 and x86_64 libraries and repackaged them. The apk size is now
kamathln@laxX550L:~/exp/android/fluttersamples/myapp/build/app/outputs/apk/apkcontents/lib$ rm -fr x86 x86_64/
kamathln@laxX550L:~/exp/android/fluttersamples/myapp/build/app/outputs/apk/apkcontents/lib$ cd ../..
kamathln@laxX550L:~/exp/android/fluttersamples/myapp/build/app/outputs/apk$ zip new.apk apkcontents/ -r
updating: apkcontents/ (stored 0%)
adding: apkcontents/lib/ (stored 0%)
adding: apkcontents/lib/armeabi-v7a/ (stored 0%)
adding: apkcontents/lib/armeabi-v7a/libflutter.so (deflated 62%)
adding: apkcontents/res/ (stored 0%)
adding: apkcontents/res/mipmap-xhdpi-v4/ (stored 0%)
adding: apkcontents/res/mipmap-xhdpi-v4/ic_launcher.png (deflated 5%)
adding: apkcontents/res/mipmap-xxxhdpi-v4/ (stored 0%)
adding: apkcontents/res/mipmap-xxxhdpi-v4/ic_launcher.png (deflated 7%)
adding: apkcontents/res/mipmap-mdpi-v4/ (stored 0%)
adding: apkcontents/res/mipmap-mdpi-v4/ic_launcher.png (deflated 8%)
adding: apkcontents/res/mipmap-xxhdpi-v4/ (stored 0%)
adding: apkcontents/res/mipmap-xxhdpi-v4/ic_launcher.png (deflated 3%)
adding: apkcontents/res/mipmap-hdpi-v4/ (stored 0%)
adding: apkcontents/res/mipmap-hdpi-v4/ic_launcher.png (deflated 5%)
adding: apkcontents/resources.arsc (deflated 76%)
adding: apkcontents/classes.dex (deflated 61%)
adding: apkcontents/META-INF/ (stored 0%)
adding: apkcontents/META-INF/MANIFEST.MF (deflated 50%)
adding: apkcontents/META-INF/CERT.RSA (deflated 12%)
adding: apkcontents/META-INF/CERT.SF (deflated 50%)
adding: apkcontents/assets/ (stored 0%)
adding: apkcontents/assets/icudtl.dat (deflated 65%)
adding: apkcontents/assets/app.flx (deflated 0%)
adding: apkcontents/AndroidManifest.xml (deflated 63%)
kamathln@laxX550L:~/exp/android/fluttersamples/myapp/build/app/outputs/apk$ ls -lh new.apk
-rw-r--r-- 1 kamathln kamathln 8.7M Jun 15 10:12 new.apk
Flutter Doctor
[✓] Flutter (on Linux, locale en_IN, channel alpha)
• Flutter at /opt/apps/flutter
• Framework revision e2f54df5ab (12 days ago), 2017-06-02 10:43:54 -0700
• Engine revision 1f2aa07571
• Tools Dart version 1.24.0-dev.3.0
[✓] Android toolchain - develop for Android devices (Android SDK 25.0.3)
• Android SDK at /home/kamathln/.buildozer/android/platform/android-sdk-20
• Platform android-25, build-tools 25.0.3
• ANDROID_HOME = /home/kamathln/.buildozer/android/platform/android-sdk-20
• Java binary at: /opt/apps/android-studio/jre/bin/java
• Java version: OpenJDK Runtime Environment (build 1.8.0_112-release-b06)
[✓] Android Studio (version 2.3)
• Android Studio at /opt/apps/android-studio
• Gradle version 3.2
• Java version: OpenJDK Runtime Environment (build 1.8.0_112-release-b06)
[✓] Connected devices
• ASUS Z010D • ********* • android-arm • Android 6.0.1 (API 23)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
platform-androidAndroid applications specificallyAndroid applications specificallyt: gradle"flutter build" and "flutter run" on Android"flutter build" and "flutter run" on Android
Activity
kamathln commentedon Jun 15, 2017
This may help in pushing the right apk to the phone :
Hixie commentedon Jun 15, 2017
Is this for release builds or debug builds?
kamathln commentedon Jun 15, 2017
I uncompressed app.apk and not the app-debug.apk . If that is what you mean. Or is there yet another release mechanism in flutter that I am not aware of?
kamathln commentedon Jun 15, 2017
Ok, My bad I come from the land of kivy-python and assumed it would be same here.
I learnt that flutter build does things differently, and packages a relatively leaner ~7mb library.
But, I now notice that it now packs only the armeabi-v7a and none other. So my suggestion still holds.
using https://developer.android.com/studio/build/configure-apk-splits.html , you can generate all different apks.
sethladd commentedon Jun 15, 2017
Would you mind opening a new issue for support apk splits?
kamathln commentedon Jun 15, 2017
kamathln commentedon Jun 15, 2017
Opened #10728
github-actions commentedon Sep 4, 2021
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.