Phenomenon
The recent project team in the integration of some third-party functions, more than once encountered a third-party library conflict problems, the following error:
| 123456 |
Duplicate symbol _objc_metaclass_$_jkserializer in:/users/tony/desktop/xxxproject/lib/libmipushsdk.a (JSONKIT.O)/U sers/tony/library/developer/xcode/deriveddata/xxxproject-boqkajmzatzxohbyrrhklfiuknic/build/products/ DEBUG-IPHONEOS/LIBPODS.A (JSONKIT.O) ld:24 duplicate symbols for Architecture armv7clang:error:linker command failed wit H Exit code 1 (use-v to see invocation) |
In this error, the reason is that the third party has packaged the Jsonkit library itself, and we have used the library in our project. This situation requires that we remove the conflicting libraries in the third-party SDK and repackage them after unpacking.
Resolution Steps
First locate the library file according to the path mentioned in the above error: /Users/tony/Desktop/XXXProject/Lib/libMiPushSDK.a copy it out for further processing.
| 12 |
Cd~/&&mkdirlibrepack&&cdlibrepackcp/users/tony/desktop/xxxproject/lib/libmipushsdk.a./libx.a |
To view package information:lipo -info libx.a
If the FAT file is prompted, then the package is supported on multiple platforms, such as ARMV7,ARMV7S,I386, which requires us to unpack the package one by one. Otherwise we just need to do one [1-6] operation
-
Create a temporary folder to hold the. o files extracted from the ARMV7 platform:mkdir armv7
-
Remove the ARMV7 platform package:lipo libx.a -thin armv7 -output armv7/libx-armv7.a
-
To view a list of the files that are contained in the library:ar -t armv7/libx-armv7.a
-
Extract the object file (that is, the. o suffix file):cd armv7 && ar xv libx-armv7.a
-
Find the conflicting package (jsonkit), deleterm JSONKit.o
-
Repackage Object file: cd .. && ar rcs libx-armv7.a armv7/*.o You can use the command in [2] again to confirm that the file was removed successfully
-
Each of the other platforms (armv7s, i386) to do the above [1-6] operation
-
To re-merge the. A file as a FAT file:
lipo -create libx-armv7.a libx-armv7s.a libx-i386.a -output libMiPushSDK-new.a
-
Copy to project to overwrite the source file:
cp libMiPushSDK-new.a /Users/tony/Desktop/XXXProject/Lib/libMiPushSDK.a
iOS programming: Third-party static libraries (. a files) processing
When you reference a third-party library, you occasionally encounter issues such as library conflicts, libraries containing some disabled APIs, and these libraries are often packaged into static library files (that is,. a files) to use. At this point we need to be able to make some necessary processing adjustments to the object file. such as retrieving information, removing conflicting libraries, and so on. Here are some common ways to do this:
First, find out if the. A file contains relevant information, such as the unique Identifier that Apple has disabled.
Find. -name *.a |xargs grep uniqueidentifier
To view the object file information:
NM XXX.A | grep ". O:" | Sed "s/. (//g "| sed" s/).//g "| Uniq
Second, remove the different. A files that contain conflicting libraries, such as Openudid library conflicts.
1. View Architectures
Lipo-info libx.a
2. If it is a FAT file, it is processed into Non-fat
Lipo Libx.a-thin Armv7-output libx-armv7.a
3. Extract the Object file
AR XV libx-armv7.a
4. Package the object file
AR RCS libx.a *.O
5. Generating a FAT file
Lipo-create Libarmv7.a-output libx.a
6. Merging. A files
Lipo-create libarmv6.a libarmv7.a-output LIB.A
Handling IOS third-party library conflicts