Mobile Development 16 min read

Refactoring NetEase Media Advertising SDK for Source Code Integration and Static Library Packaging with CocoaPods

The NetEase Media Advertising SDK was refactored to meet source‑code and static‑library integration needs by splitting into Core and Demo modules, converting Core into a Development Pod, centralizing build settings in xcconfig files, and adding CocoaPods post‑install hooks that automate header copying and configuration, enabling seamless use across the News client and other products.

NetEase Media Technology Team
NetEase Media Technology Team
NetEase Media Technology Team
Refactoring NetEase Media Advertising SDK for Source Code Integration and Static Library Packaging with CocoaPods

This article describes the engineering restructuring of the NetEase Media Advertising SDK to satisfy two business requirements: source‑code integration and static‑library integration for the NetEase News client.

Background : Previously the SDK was only distributed as a compiled .a static library. Business teams that needed to debug or customize the SDK required source‑code access, which was not possible with the existing Remote Pod setup.

First Phase – Source‑code integration : The SDK was split into two logical parts – SDK Core and SDK Demo . Using CocoaPods, SDK Core was turned into a Development Pod, physically separating it from the Demo. The Remote Pod still points to the whole SDK project, allowing both source‑code and static‑library consumption.

The podspec was updated to expose the Core sources: s.source_files = "NEAdSDKCore/**/*"

Key benefits of this approach:

Development Pods avoid duplicate repository updates.

Remote Pods give the News client fine‑grained permission control.

Other products (Open Course, Mail Master, Red Color) can also consume the same Remote Pod.

The Core directory was reorganized into Public (exposed .h/.m files) and Private (internal implementation).

Static‑library packaging challenges :

Before the refactor the SDK used three Xcode targets ( NEAdSDK , NEAdSDKLib , Merge ). Maintaining Compile Sources and Copy Files manually was error‑prone, especially for MRC files that required the -fno-objc-arc flag.

To address this, the team introduced a second phase focusing on automation.

Second Phase – Automation via CocoaPods hooks :

1. Build Settings were centralized in an .xcconfig file. The SDK version macro was defined as: s.version = '12.5.1' s.pod_target_xcconfig = { 'GCC_PREPROCESSOR_DEFINITIONS' => "NEADSDKVERVSION=@\"#{s.version.to_s}\"" }

2. A post_install hook in the Podfile was added to inject the custom .xcconfig into the Core target: post_install do |installer| installer.pods_project.targets.each do |target| if target.name == "NEAdSDKCore" target.build_configurations.each do |config| xcconfig_path = config.base_configuration_reference.real_path File.open(xcconfig_path, "a") { |f| f.puts '#include "../../../LibNEAdSDK.xcconfig"' } end end end end

3. To generate a Copy Files phase and add public headers automatically, another post_install hook used the CocoaPods Ruby API: post_install do |installer| installer.pods_project.targets.each do |target| if target.name == "NEAdSDKCore" phase = target.new_copy_files_build_phase("Copy Files") phase.dst_subfolder_spec = "16" phase.dst_path = "include/$(PRODUCT_NAME)" # Add each public header public_headers.each do |header_path| file_ref = target.project.reference_for_path(header_path) phase.add_file_reference(file_ref, true) end end end end

4. A shell‑script build phase was also added to run custom packaging scripts depending on the build configuration.

After these changes, the SDK project now consists of a single target that can be built in Debug mode for development or in Release mode to produce a static library, with all necessary headers automatically copied.

Conclusion : By leveraging Development Pods, xcconfig files, and CocoaPods post‑install hooks, the team eliminated manual maintenance of Compile Sources and Copy Files , streamlined version synchronization, and provided both source‑code and static‑library integration paths for multiple downstream products.

SDKiOSautomationCocoaPodsPodSpecstatic libraryBuild Settings
NetEase Media Technology Team
Written by

NetEase Media Technology Team

NetEase Media Technology Team

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.