英文:
How to reduce flutter app apk size when using agora rtc engine and agora uikit
问题
构建一个使用Agora库的Flutter约会网站。
Flutter版本3.10.5
JDK 18
Gradle 7.5 (Gradle属性)
应用Gradle依赖项如下:
buildscript {
ext.kotlin_version = '1.8.21'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.0'
classpath 'com.google.gms:google-services:4.3.10'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
以下是Flutter依赖项列表:
dependencies:
agora_rtc_engine: ^6.1.1
agora_uikit: ^1.3.3
awesome_snackbar_content: ^0.1.3
cached_network_image: ^3.2.3
cloud_firestore: ^4.5.0
country_code_picker: ^3.0.0
crop_image: ^1.0.5
cupertino_icons: ^1.0.2
easy_localization: ^3.0.1
equatable: ^2.0.5
firebase_auth: ^4.4.0
firebase_core: ^2.4.0
google_sign_in:
firebase_messaging: ^14.1.4
firebase_storage: ^11.1.0
flutter:
sdk: flutter
flutter_bloc: ^8.1.2
flutter_callkit_incoming: ^2.0.0
flutter_facebook_auth: ^5.0.11
flutter_flushbar: ^0.0.2
flutter_geocoder: ^0.2.2-nullsafety
flutter_image_compress: ^1.1.3
flutter_mapbox_autocomplete: ^2.0.0
flutter_ringtone_player: ^3.2.0
flutter_swiper_null_safety: ^1.0.2
fluttertoast: ^8.2.1
font_awesome_flutter: ^10.4.0
google_mobile_ads: ^3.0.0
http: ^0.13.5
image: ^4.0.16
image_cropper: ^3.0.2
image_picker: ^0.8.7+3
in_app_purchase: 3.1.5
location: ^4.4.0
path_provider: ^2.0.14
permission_handler: ^10.2.0
pin_code_fields: ^7.4.0
provider: ^6.0.5
rflutter_alert: ^2.0.4
share_plus: ^6.3.2
shimmer: ^2.0.0
swipable_stack: ^2.0.0
url_launcher: ^6.1.10
uuid: ^3.0.7
当我使用以下命令构建APK时:
flutter build apk --target-platform android-arm64 --analyze-size --release
输出如下:
app-arm64-v8a-release.apk (总压缩大小) 53 MB
尝试使用DevTools查找每个库实际占用的大小,输出如下:
你可以看到arm64-v8a
占用的空间要大得多。请问我如何能够减小APK的整体大小?谢谢提前回答。
(对不起,我的英语不太好。)
英文:
building a dating site in flutter which is using agora libraries
flutter version 3.10.5
jdk 18
gradle 7.5 (gradle properties)
app gradele dependecies are
buildscript {
ext.kotlin_version = '1.8.21'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.0'
classpath 'com.google.gms:google-services:4.3.10'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
here are flutter dependancy list
dependencies:
agora_rtc_engine: ^6.1.1
agora_uikit: ^1.3.3
awesome_snackbar_content: ^0.1.3
cached_network_image: ^3.2.3
cloud_firestore: ^4.5.0
country_code_picker: ^3.0.0
crop_image: ^1.0.5
cupertino_icons: ^1.0.2
easy_localization: ^3.0.1
equatable: ^2.0.5
firebase_auth: ^4.4.0
firebase_core: ^2.4.0
google_sign_in:
firebase_messaging: ^14.1.4
firebase_storage: ^11.1.0
flutter:
sdk: flutter
flutter_bloc: ^8.1.2
flutter_callkit_incoming: ^2.0.0
flutter_facebook_auth: ^5.0.11
flutter_flushbar: ^0.0.2
flutter_geocoder: ^0.2.2-nullsafety
flutter_image_compress: ^1.1.3
flutter_mapbox_autocomplete: ^2.0.0
flutter_ringtone_player: ^3.2.0
flutter_swiper_null_safety: ^1.0.2
fluttertoast: ^8.2.1
font_awesome_flutter: ^10.4.0
google_mobile_ads: ^3.0.0
http: ^0.13.5
image: ^4.0.16
image_cropper: ^3.0.2
image_picker: ^0.8.7+3
in_app_purchase: 3.1.5
location: ^4.4.0
path_provider: ^2.0.14
permission_handler: ^10.2.0
pin_code_fields: ^7.4.0
provider: ^6.0.5
rflutter_alert: ^2.0.4
share_plus: ^6.3.2
shimmer: ^2.0.0
swipable_stack: ^2.0.0
url_launcher: ^6.1.10
uuid: ^3.0.7
**when i build apk with **
flutter build apk --target-platform android-arm64 --analyze-size --release
the output comes:
app-arm64-v8a-release.apk (total compressed) 53 MB
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
META-INF/
CERT.SF 49 KB
CERT.RSA 1018 B
MANIFEST.MF 44 KB
assets/
dexopt 2 KB
flutter_assets 1 MB
classes.dex 3 MB
classes2.dex 3 MB
lib/
arm64-v8a 43 MB
Dart AOT symbols accounted decompressed size 9 MB
package:flutter 4 MB
package:image 778 KB
package:hookup4u2 423 KB
dart:core 326 KB
dart:ui 277 KB
package:agora_rtc_engine 255 KB
dart:typed_data 215 KB
package:vector_graphics_compiler 170 KB
dart:io 170 KB
dart:collection 158 KB
dart:async 148 KB
dart:ffi 84 KB
package:petitparser 75 KB
package:collection/
src 63 KB
package:agora_uikit 63 KB
dart:convert 61 KB
package:firebase_auth_platform_interface 58 KB
package:vector_math 55 KB
package:intl 49 KB
package:google_mobile_ads 48 KB
AndroidManifest.xml 8 KB
res/
04.png 2 KB
1Q.xml 1 KB
1k.png 126 KB
1r.png 126 KB
27.png 2 KB
33.9.png 2 KB
4F.png 126 KB
51.9.png 2 KB
5V.png 2 KB
7r.png 1 KB
Aj.xml 1 KB
CG.png 13 KB
D2.png 9 KB
D4.png 2 KB
E9.png 9 KB
EA.png 126 KB
EL.png 1 KB
ER.9.png 2 KB
EW.xml 1 KB
FM.9.png 1 KB
FU.png 1 KB
Fc.png 3 KB
Fo.png 126 KB
GY.png 5 KB
Gr.png 28 KB
Hg.png 2 KB
J6.9.png 2 KB
JQ.png 3 KB
Ji.png 149 KB
L1.png 149 KB
LN.xml 1 KB
LY.png 149 KB
Mr.9.png 1 KB
Mt.xml 1 KB
Ov.png 2 KB
Pi.9.png 3 KB
Q11.9.png 3 KB
Q2.png 8 KB
Rg.xml 1 KB
SD.png 3 KB
Tx.9.png 1 KB
VN.png 18 KB
Vq.png 1 KB
YM.9.png 1 KB
_R.png 7 KB
_c.png 1 KB
aO.9.png 1 KB
b8.png 11 KB
cQ.png 149 KB
color-v23 2 KB
color 5 KB
d4.png 1 KB
e1.xml 1 KB
eB.9.png 2 KB
eh.png 5 KB
g-.png 11 KB
gA.xml 2 KB
gV.9.png 1 KB
hI.mp3 166 KB
jZ.9.png 1 KB
jy.png 5 KB
kX.png 26 KB
le.png 2 KB
m3.9.png 1 KB
oL.png 6 KB
p4.png 4 KB
ra.png 149 KB
rc.png 1 KB
sB.png 126 KB
tI.png 1 KB
tj.9.png 2 KB
u3.png 2 KB
wi.9.png 2 KB
wi1.9.png 1 KB
y6.png 1 KB
yB.xml 1 KB
tried to find the actual size occupied by each library with running devtools
output:
you can see arm64-v8a is much bigger
could you please suggest me how can i reduce the apk size overall
thanks in advance
[sorry for my bad english]
答案1
得分: 1
所以最好的方式是使用Android App Bundle而不是APK来交付您的应用程序。这样,Play Store将仅向交付的应用程序添加必要的库,始终确保尽可能小的大小(尽管捆绑包本身有时可能较大)。
如果您被迫使用APK,因为您通过Play Store以外的渠道分发您的应用程序(例如Firebase分发或App Center),那么您可以尝试在应用程序清单的应用程序标签中添加属性android:extractNativeLibs="true"
。
这将减小您的APK大小,尽管会略微增加已安装应用程序的大小。将此参数设置为true后,生成的APK将会压缩本机库(arm64-v8a
是本机库),从而减小总大小。
<application
android:label="Welcome+"
android:icon="@mipmap/ic_launcher"
android:extractNativeLibs="true">
英文:
So the best way to go would be to use an Android App Bundle instead of an APK for delivering your application. That way the Play Store will only add the necessaries libraries to the delivered app always ensuring the smallest size as possible (although the bundle itself may be larger sometimes).
If you are forced to use APK because you are distributing your app trough other channels than the Play Store (i.e. Firebase distribution or App Center) than you could try to add, in the application tag of your app manifest, the property android:extractNativeLibs="true"
.
This will reduce the size of your APK although slightly increase the size of the installed app. With this parameter set to true the native libraries (arm64-v8a
is a native lib) will be compressed in the generated APK and the total size will be reduced.
<application
android:label="Welcome+"
android:icon="@mipmap/ic_launcher"
android:extractNativeLibs="true">
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论