App size optimization
Updated
Reduce the size of apps that integrate Agora SDK
Reducing the app size is of great significance in improving user experience. A smaller package size means that users consume less bandwidth and time to download the app. Consider the following use-cases where app size optimization is critical:
-
There are strict requirements on the size of the app. For example, running the app on smart wearable devices with limited storage space.
-
The target user group of the app is located in underdeveloped areas. The poor network connectivity causes the app download time to be too long.
This page shows you how to optimize the size of apps with integrated Video SDK.
Remove unnecessary extensions
Video SDK provides optional extension dynamic libraries. The name of the extension is suffixed with extension. See the extension list for details on the function and size of the extensions. Refer to the following ways to exclude these extensions to reduce the size of the app.
If your target platform is Android, use Gradle's packagingOptions.exclude properties to exclude unnecessary extension dynamic libraries from the final APK or AAR file. Removing these files during the packaging process reduces the app size and improves app performance.
In the build.gradle file in the project root directory, find the android configuration block. Under the module packagingOptions, use the exclude attribute to specify the extension dynamic libraries you want to exclude. Refer to the following example to exclude specific extensions:
android {
// ...
packagingOptions {
// Exclude AI denoise extension for the armeabi-v7a architecture
exclude 'lib/armeabi-v7a/libagora_ai_denoise_extension.so'
// Exclude AI denoise extension for the arm64-v8a architecture
exclude 'lib/arm64-v8a/libagora_ai_denoise_extension.so'
// Exclude spatial audio extension for the armeabi-v7a architecture
exclude 'lib/armeabi-v7a/libagora_spatial_audio_extension.so'
// Exclude spatial audio extension for the arm64-v8a architecture
exclude 'lib/arm64-v8a/libagora_spatial_audio_extension.so'
}
}If your target platform is iOS or macOS, follow these steps to reduce the size of your app:
- Add the following script to the Podfile under the target section for the
agora_rtc_enginedependency. This script marks unnecessary extensions as weak frameworks:
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
targets_to_weaklink=['Pods-Runner', "agora_rtc_engine"]
# Add more -weak_framework flags for other unnecessary extensions if needed
frameworks_to_weaklink=["AgoraAiEchoCancellationExtension", "AgoraAiNoiseSuppressionExtension", "AgoraAudioBeautyExtension", "AgoraClearVisionExtension", "AgoraContentInspectExtension", "AgoraDrmLoaderExtension", "AgoraReplayKitExtension", "AgoraSpatialAudioExtension ", "AgoraSuperResolutionExtension", "AgoraVideoQualityAnalyzerExtension", "AgoraVideoSegmentationExtension"]
next unless targets_to_weaklink.include?(target.name)
target.build_configurations.each do |config|
base_config_reference = config.base_configuration_reference
unless base_config_reference. nil?
xcconfig_path = base_config_reference.real_path
xcconfig = File.read(xcconfig_path)
frameworks_to_weaklink.each do |framework|
xcconfig = xcconfig.gsub(/-framework "#{framework}"/, "-weak_framework \"#{framework}\"")
end
File.open(xcconfig_path, "w") { |file| file << xcconfig }
end
end
end
end-
To remove unnecessary extensions, follow these steps in Xcode:
-
Navigate to the Build Phases tab.
-
Click the
+button at the bottom left corner of the Build Phases tab and select New Run Script Phase. -
Specify Shell as
/usr/bin/rubyand replace the code part with the following script:
$stderr.puts "Removing Unnecessary Frameworks"
# The extensions listed in frameworks_to_weaklink here should match those in Step 1.
frameworks_to_weaklink=["AgoraAiEchoCancellationExtension", "AgoraAiNoiseSuppressionExtension", "AgoraAudioBeautyExtension", "AgoraClearVisionExtension", "AgoraContentInspectExtension", "AgoraDrmLoaderExtension", "AgoraReplayKitExtension", "AgoraSpatialAudioExtension ", "AgoraSuperResolutionExtension", "AgoraVideoQualityAnalyzerExtension", "AgoraVideoSegmentationExtension"]
for framework in frameworks_to_weaklink
framework_path = "#{ENV['BUILT_PRODUCTS_DIR']}/#{ENV['FRAMEWORKS_FOLDER_PATH']}/#{framework}.framework"
`rm -Rf "#{framework_path}"`
endThe following figure shows the required steps:
Reference
This section contains content that completes the information in this page, or points you to documentation that explains other aspects to this product.
Extension list
Refer to the following information for an introduction to each Video SDK extension and the increase in the size of your app after integration.
The information in this section is based on version 4.4.0 of the Video SDK.
