I am having a problem migrating my framework from cocoapods to SPM (Swift Package Manager).
Framework is actually dependent on SQLite.swift library via cocoapods.
The framework itself is precompiled as a xcframework like:
xcodebuild archive \
-workspace ${FRAMEWORK_NAME}.xcworkspace \
-scheme ${SCHEME} \
-archivePath ${SIMULATOR_ARCHIVE_PATH} \
-sdk iphonesimulator \
-destination "generic/platform=iOS Simulator" \
SKIP_INSTALL=NO \
BUILD_LIBRARIES_FOR_DISTRIBUTION=YES \
DEFINES_MODULE=YES \
| xcpretty
xcodebuild archive \
-workspace ${FRAMEWORK_NAME}.xcworkspace \
-scheme ${SCHEME} \
-archivePath ${IOS_DEVICE_ARCHIVE_PATH} \
-destination "generic/platform=iOS" \
-sdk iphoneos \
SKIP_INSTALL=NO \
BUILD_LIBRARIES_FOR_DISTRIBUTION=YES \
DEFINES_MODULE=YES \
| xcpretty
xcodebuild -create-xcframework \
-framework ${SIMULATOR_ARCHIVE_PATH}/Products/Library/Frameworks/${FRAMEWORK_NAME}.framework \
-framework ${IOS_DEVICE_ARCHIVE_PATH}/Products/Library/Frameworks/${FRAMEWORK_NAME}.framework \
-output ${FRAMEWORK_NAME}.xcframework \
| xcpretty
Now i want to make it possible to distribute framework via SPM but unfortunately can't make it happen.
Looking into the internet I found out that my case is fairly similar to the one firebase had with FirebaseAnalytics so I came up with the same approach with my Package.swift manifest file and created wrapper target:
let package = Package(
name: "REDACTED",
products: [
.library(
name: "REDACTED",
targets: ["REDACTEDSPMTarget"]
),
],
dependencies: [
.package(name: "SQLite.swift", url: "https://github.com/stephencelis/SQLite.swift.git", from: "0.13.3")
],
targets: [
.target(
name: "REDACTEDSPMTarget",
dependencies: [
.target(name: "REDACTEDSPMWrapper", condition: .when(platforms: [.iOS])),
],
path: "SwiftPM-PlatformExclude/REDACTEDSPMTarget"
),
.target(
name: "REDACTEDSPMWrapper",
dependencies: [
.target(name: "REDACTED", condition: .when(platforms: [.iOS])),
.product(name: "SQLite", package: "SQLite.swift")
],
path: "REDACTEDSPMWrapper"
),
.binaryTarget(
name: "REDACTED",
path: "Framework/REDACTED.xcframework"
),
]
)
Unfortunately i can't make it work when trying to add the package locally via SPM. The project builds just fine but the app can't start due to the error:
Library not loaded: #rpath/SQLite.framework/SQLite
Reason: tried: '{...}/Build/Products/Debug-iphonesimulator/SQLite.framework/SQLite' (no such file)
It looks like at some point compiler is not linking SQLite.framework file. I think cocoapods does that using one of the Build phase script file.
What may be the case here?
Somehow i did make it to work...
removed cocoapods using pod deintegrate
added SQLite.swift via SPM
added #_implementationOnly import for every SQLite reference in framework's target
archived using slighty different parameters:
xcodebuild archive \
-scheme ${SCHEME} \
-archivePath ${SIMULATOR_ARCHIVE_PATH} \
-sdk iphonesimulator \
-destination "generic/platform=iOS Simulator" \
SKIP_INSTALL=NO \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES \
DEFINES_MODULE=YES \
| xcpretty
Framework works now as expected, without crashing. Only one thing left to take care of is that the dependency is added to both framework as well as to the app itselt causing:
Class _TtC6SQLite6Backup is implemented in both
.../demo.app/Frameworks/REDACTED.framework/REDACTED
and
.../spmdemo.app/spmdemo.
One of the two will be used. Which one is undefined.
Related
I'm trying to compile my framework into an xcframework, which I do with the following script:
xcodebuild archive \
-scheme CleanUI \
-configuration Release \
-destination 'generic/platform=iOS' \
-archivePath './build/CleanUI.framework-iphoneos.xcarchive' \
SKIP_INSTALL=NO \
BUILD_LIBRARIES_FOR_DISTRIBUTION=YES
xcodebuild archive \
-scheme CleanUI \
-configuration Release \
-destination 'generic/platform=iOS Simulator' \
-archivePath './build/CleanUI.framework-iphonesimulator.xcarchive' \
SKIP_INSTALL=NO \
BUILD_LIBRARIES_FOR_DISTRIBUTION=YES
xcodebuild -create-xcframework \
-framework './build/CleanUI.framework-iphonesimulator.xcarchive/Products/Library/Frameworks/CleanUI.framework' \
-framework './build/CleanUI.framework-iphoneos.xcarchive/Products/Library/Frameworks/CleanUI.framework' \
-output './build/CleanUI.xcframework'
This works completely fine until I import the CleanUI.xcframework into a test project. I get the following errors:
All those errors make no sense, at all. When I build the framework as a normal framework, with Cmd + B, everything works fine.
I deleted the derived data folder, cleaned every build folder and restarted my Mac like a thousand times. I have been working on this for the past 10 hours, I feel like I searched the entire web and tried every single possible solution.
I have been trying to compile the aws-sdk-ios for Mac Catalyst but I wasn't successful yet. Below there is the script that I use to compile for armv7 and x86_64 (simulator).
# Build .a files
xcodebuild ARCHS="i386 x86_64" \
ONLY_ACTIVE_ARCH=NO \
-configuration Debug \
-project "${project_path}" \
-target "${project_name}" \
-sdk iphonesimulator \
SYMROOT=$(PWD)/builtFramework
xcodebuild ARCHS="armv7 arm64" \
ONLY_ACTIVE_ARCH=NO \
-configuration Release \
-project "${project_path}" \
-target "${project_name}" \
-sdk iphoneos \
SYMROOT=$(PWD)/builtFramework
This correctly compiles the project and results into these folders:
I tried to compile the project for Mac Catalyst with multiple variations of the code below (based in multiple examples on the internet):
xcodebuild ONLY_ACTIVE_ARCH=NO \
-project "${project_path}" \
-target "${project_name}" \
-destination "generic/platform=macOS,variant=Mac Catalyst,name=Any Mac"
SYMROOT=$(PWD)/builtFramework
This seems to not create any Release-maccatalyst folder or anything else, even adding these flags:
SKIP_INSTALL=NO BUILD_LIBRARIES_FOR_DISTRIBUTION=YES SUPPORTS_MACCATALYST=YES
Or these:
ARCHS="x86_64" VALID_ARCHS="x86_64"
(Also tried with x86_64h, no luck)
With the ARCHS flags above, the compilation fails with these errors:
I am not sure what I need to do to compile the project, anyone could please help me to find the correct script to create the .framework for Catalyst?
Regards,
Pedro
I was doing some refactoring on a Xcode Swift project. We had a spelling mistake in the name of a class which I corrected, both in the name of the class and in its declaration. Of course I changed every occurence as well.
The iOS projects builds and runs fine on my machine, but it does not on Travis. When I take a look into the travis logs I can see that the old file name is still in the build path – of course then it has to fail cause it won't be able to find that file.
Here's the .travis.yml
language: objective-c
osx_image: xcode9.2
before_install:
- gem install cocoapods
- pod setup
- pod install
script:
- export LC_ALL=en_US.UTF-8
- xcodebuild clean -project DQ-iOS-App.xcodeproj \
-scheme DQ-iOS-App CODE_SIGNING_REQUIRED=NO
- xcodebuild -verbose -workspace "DQ-iOS-App.xcworkspace" \
-scheme "DQ-iOS-App" -destination "platform=iOS Simulator,name=iPhone 8,\
OS=11.2" CODE_SIGNING_REQUIRED=NO
What am I missing here?
You can try to delete derrived data:
rm -rf ~/Library/Developer/Xcode/DerivedData
I don't know how to edit my .travis.yml. Every time travis-ci check fail, I am almost crazy!
This is my travis-ci link: https://travis-ci.org/liman123/DebugMan
This is my .travis.yml, is there anything wrong? Thanks!
osx_image: xcode8.3
language: objective-c
script:
- set -o pipefail && xcodebuild test -enableCodeCoverage YES -workspace
DebugMan.xcworkspace -scheme DebugMan -sdk iphonesimulator -destination
'platform=iOS Simulator,name=iPhone 6,OS=latest' ONLY_ACTIVE_ARCH=NO |
xcpretty
- pod lib lint
language: objective-c
script:
- xctool -project example.xcodeproj -scheme exampleTests build test -sdk
iphonesimulator GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES
GCC_GENERATE_TEST_COVERAGE_FILES=YES
after_success:
- bash <(curl -s https://codecov.io/bash)
Wrap your first script command in double quotes:
"set pipefail ... | xcpretty"
Can any One Tell me how do i integrate FFMPEG in my iphone/ ipad project.i m using Xcode 4.
i searched a lot but did not find any useful Link .please tell me step by step procedure to integrate FFMpeg in my project.
thanks,
Prerequisites
MacPorts to install:open terminal and type
sudo port install pkgconfig
Launch Terminal and download FFmpeg source
The location of the directory is up to your personal preference and I chose to save it in a ffmpeg folder under my Home folder for easy access later on.
git clone git://source.ffmpeg.org/ffmpeg.git ~/ffmpeg
Before we go further, we need to think ahead and realize that we are likely to do some simulation on Mac itself along with actual testing on iPhone. What we need to do is that we need to build libraries for 3 architectures: armv7 (iPhone 3Gs or later), armv7s (iPhone 5) and i386 (iPhone Simulator).
Let’s create some folders inside ffmpeg folder to hold 3 different builds so that we can lipo those together into one universal build.
cd ffmpeg
mkdir armv7
mkdir armv7s
mkdir i386
mkdir -p universal/lib
To Install gas-preprocessor
Click on the ZIP icon to download gas-preprocessor.
Copy gas-preprocessor.pl to /usr/bin directory.
Change permission of gas-preprocessor.pl by setting the privilege to Read & Write for all.
Configure FFmpeg for armv7 build
Before configuring,
You may refer to the detailed options by going in to the ffmpeg folder and type:
./configure --help
list of options for your reference: FFmpeg Configure Options. The “Components options” will be up to you depending on what you want to do with FFmpeg.
Now run the following configure options:
./configure \
--prefix=armv7 \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-ffserver \
--enable-avresample \
--enable-cross-compile \
--sysroot="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk"
\
--target-os=darwin \
--cc="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc"
\
--extra-cflags="-arch armv7 -mfpu=neon -miphoneos-version-min=6.0" \
--extra-ldflags="-arch armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk
-miphoneos-version-min=6.0" \
--arch=arm \
--cpu=cortex-a9 \
--enable-pic \
You may get a warning such as:
WARNING: Compiler does not indicate floating-point ABI, guessing soft.
No worries. You should be fine to continue to next steps.
Build FFmpeg for armv7
Run the build commands:
make clean && make && make install
Now you should be able to see files are populated inside the ffmpeg/armv7 folder. We now move onto building for armv7s for iPhone 5.
Configure and Install FFmpeg for armv7s architecture (iPhone 5)
.
/configure \
--prefix=armv7s \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-ffserver \
--enable-avresample \
--enable-cross-compile \
--sysroot="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk"
\
--target-os=darwin \
--cc="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc"
\
--extra-cflags="-arch armv7s -mfpu=neon -miphoneos-version-min=6.0" \
--extra-ldflags="-arch armv7s -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk
-miphoneos-version-min=6.0" \
--arch=arm \
--cpu=cortex-a9 \
--enable-pic \
Then build with:
make clean && make && make install
Configure FFmpeg for i386 build
./configure \
--prefix=i386 \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-ffserver \
--enable-avresample \
--enable-cross-compile \
--sysroot="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.0.sdk"
\
--target-os=darwin \
--cc="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc"
\
--extra-cflags="-arch i386" \
--extra-ldflags="-arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.0.sdk"
\
--arch=i386 \
--cpu=i386 \
--enable-pic \
--disable-asm \
Please note the last --disable-asm tag. If you forget to include this tag, you will likely to receive this error:
cc1: error in backend: Ran out of registers during register
allocation! make: *** [libavcodec/h264_cabac.o] Error 1
Build FFmpeg for i386
make clean && make && make install
Create universal library
The lipo commands (assuming you are still under the ffmpeg folder):
(Please note that Mountain Lion-supplied lipo knows nothing about armv7s as of yet. So we need to use xcrun to find the lipo supplied with the SDK.)
cd armv7/lib for file in *.a do cd ../.. xcrun -sdk iphoneos lipo
-output universal/lib/$file -create \
-arch armv7 armv7/lib/$file \
-arch armv7s armv7s/lib/$file \
-arch i386 i386/lib/$file echo "Universal $file created." cd - done cd ../..
Look under universal/lib, you will find all FAT libs freshly baked there. We now turn our attention to linking these static libraries to the Xcode project.
if you are getting error like this Error: No developer directory found at /Developer”? then type
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
Linking static libraries in Xcode
Firstly, we pull in the .a files.
Create a new Empty Application using Xcode. Assign a Product Name and Company Identifier. Then click Next and save the project.
Locate the universal libs that we created (the .a files) under ffmpeg/universal/lib.
Drag the .a files into the Frameworks folder in the Project Navigator pane.
Tick “Copy items into destination group’s folder (if needed)”. And click Finish.
Now we take care of the include files.
Locate the include files under ffmpeg/armv7/include.
Drag and drop the content of that folder onto the Project Name folder in the Project Navigator pane.
Again, tick “Copy items into destination group’s folder (if needed)”. Then click Finish.
Finally, we need to set the Header Search Paths for the project.
Click on the Project in the Project Navigator pane.
In the Standard Editor in the middle of the screen, click on Build Settings.
Search for “Header Search Paths”.
Add your project path and set it to Recursive. i.e. $(SRCROOT)
Click on Build Phases.
Under Link Binary With Libraries, add libbz2.dylib and libz.dylib.
Test and verify the working of library
We are not going to be in-depth here. Just to verify that the library is functioning.
Go to your AppDelegate.m, and add:
> #include "avformat.h"
And in the didFinishLaunchingWithOptions function, add:
av_register_all();
if suppose you are getting this errors means
Undefined symbols for architecture i386:
"_iconv", referenced from:
_mail_iconv in libmailcore.a(charconv.o)
"_iconv_open", referenced from:
_charconv in libmailcore.a(charconv.o)
_charconv_buffer in libmailcore.a(charconv.o)
"_iconv_close", referenced from:
_charconv in libmailcore.a(charconv.o)
_charconv_buffer in libmailcore.a(charconv.o)
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status
then add libiconv.dylib framework
you are now ready to dive in to develop using FFmpeg on iOS.
./configure script:
./configure --extra-ldflags=-L/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib/system --disable-bzlib --disable-doc --disable-ffmpeg --disable-ffplay --disable-ffserver --enable-cross-compile --arch=arm --target-os=darwin --cc=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc --as='gas-preprocessor/gas-preprocessor.pl /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc' --sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk --cpu=cortex-a8 --extra-cflags='-arch armv7' --extra-ldflags='-arch armv7' --enable-pic
this works fine. since the default FFMPEG configuration script has the default Library path set to /usr/lib/system so it can not find library libcache.dylib, so here I have set it to the latest sdk path.