Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce size of the agora_rtc_engine #1214

Open
littleGnAl opened this issue Jul 13, 2023 · 8 comments
Open

Reduce size of the agora_rtc_engine #1214

littleGnAl opened this issue Jul 13, 2023 · 8 comments

Comments

@littleGnAl
Copy link
Contributor

littleGnAl commented Jul 13, 2023

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

@MuhammadIbrahim001

This comment was marked as resolved.

@littleGnAl

This comment was marked as resolved.

@MuhammadIbrahim001

This comment was marked as resolved.

@littleGnAl

This comment was marked as resolved.

@MuhammadIbrahim001

This comment was marked as resolved.

@coryswainston

This comment was marked as resolved.

@littleGnAl

This comment was marked as resolved.

@coryswainston

This comment was marked as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants