Skip to content

Reduce size of the agora_rtc_engine #1214

Closed as not planned
Closed as not planned
@littleGnAl

Description

@littleGnAl

You can remove the unnecessary extension libraries of the Agora native sdk to reduce the APP size
https://docs.agora.io/en/video-calling/reference/downloads?platform=android#remove-unneeded-plugins
https://docs.agora.io/en/video-calling/reference/downloads?platform=ios#remove-unneeded-plugins

Here's how it can do with the agora_rtc_engine

Android

Use the gradle packagingOptions.exclude to exclude unnecessary so files. (wildcards are supported)

https://stackoverflow.com/questions/37382057/android-apk-how-to-exclude-a-so-file-from-a-3rd-party-dependency-using-gradle

packagingOptions {
     exclude 'lib/armeabi-v7a/libagora_ai_denoise_extension.so'
     exclude 'lib/armeabi-v7a/libagora_spatial_audio_extension.so'
     exclude 'lib/armeabi-v7a/libagora_full_audio_format_extension.so'
 
     exclude 'lib/arm64-v8a/libagora_ai_denoise_extension.so'
     exclude 'lib/arm64-v8a/libagora_spatial_audio_extension.so'
     exclude 'lib/arm64-v8a/libagora_full_audio_format_extension.so'
}

iOS/macOS

NOTE: this way does not work for add to app scenario

Steps:

  1. Mark the unnecessary native sdk framewrok as weak_frameworks through the script
  2. Remove unnecessary frameworks through xcode build phase

1. Mark the unnecessary native sdk framewrok as weak_frameworks through the script

Add the following script to your project ios/Podfile to mark weak_frameworks for frameworks that are not needed in 'Pods-Runner', "agora_rtc_engine":

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"]
     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

The above script lists all frameworks with "Extension" suffixes marked as weak_framework in frameworks_to_weaklink, you can modify frameworks_to_weaklink to the frameworks you need to mark as needed.

2. Remove unnecessary frameworks through xcode build phase

image

Through the above screenshot, you can add Run Script to remove unnecessary frameworks, and the following script can be copied directly.

NOTE:Shell needs to specify as /usr/bin/ruby

$stderr.puts "Removing Unnecessary Frameworks"
# The value of `frameworks_to_weaklink` should be consistent with 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}"`
end

Note:

  • The value of frameworks_to_weaklink should be consistent with step 1
  • The script phase should put in the last step

Windows

TBD

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions