How to build a react native project with cocoapods and workspace? - ios

Before I install Pods and add a workspace to my react native project I build my project successfully using this command:
xcodebuild -scheme [SchemeName] archive -archivePath ./build/[AppName].xcarchive -allowProvisioningUpdates
I installed RN Firebase using CocoaPods and it need a xcworkspace to manage packages. According this I added the workspace option to allow the xcodebuild to find Pods:
-workspace [AppName].xcworkspace
After adding this option, the build failed because it don't find main.jsbundle.
Loading dependency graph, done.
SHA-1 for file /Users/nicolas/development/git/availpro.mobile/index.js is not computed
ReferenceError: SHA-1 for file /Users/nicolas/development/git/availpro.mobile/index.js is not computed
at DependencyGraph.getSha1 (/Users/nicolas/development/git/availpro.mobile/node_modules/metro/src/node-haste/DependencyGraph.js:201:13)
at /Users/nicolas/development/git/availpro.mobile/node_modules/metro/src/DeltaBundler/Transformer.js:164:26
at Generator.next (<anonymous>)
at step (/Users/nicolas/development/git/availpro.mobile/node_modules/metro/src/DeltaBundler/Transformer.js:31:30)
at /Users/nicolas/development/git/availpro.mobile/node_modules/metro/src/DeltaBundler/Transformer.js:50:14
at new Promise (<anonymous>)
at /Users/nicolas/development/git/availpro.mobile/node_modules/metro/src/DeltaBundler/Transformer.js:28:12
at Transformer.transformFile (/Users/nicolas/development/git/availpro.mobile/node_modules/metro/src/DeltaBundler/Transformer.js:188:7)
at /Users/nicolas/development/git/availpro.mobile/node_modules/metro/src/Bundler.js:78:34
at Generator.next (<anonymous>)
+ [[ false != true ]]
+ [[ ! -f /Users/nicolas/Library/Developer/Xcode/DerivedData/AvailproMobile-gewuoxculvshvhehwwobcbkhdzba/Build/Intermediates.noindex/ArchiveIntermediates/AvailproMobile-staging/BuildProductsPath/Release-iphoneos/AvailproMobile.app/main.jsbundle ]]
+ echo 'error: File /Users/nicolas/Library/Developer/Xcode/DerivedData/AvailproMobile-gewuoxculvshvhehwwobcbkhdzba/Build/Intermediates.noindex/ArchiveIntermediates/AvailproMobile-staging/BuildProductsPath/Release-iphoneos/AvailproMobile.app/main.jsbundle does not exist. This must be a bug with'
error: File /Users/nicolas/Library/Developer/Xcode/DerivedData/AvailproMobile-gewuoxculvshvhehwwobcbkhdzba/Build/Intermediates.noindex/ArchiveIntermediates/AvailproMobile-staging/BuildProductsPath/Release-iphoneos/AvailproMobile.app/main.jsbundle does not exist. This must be a bug with
+ echo 'React Native, please report it here: https://github.com/facebook/react-native/issues'
React Native, please report it here: https://github.com/facebook/react-native/issues
+ exit 2
To quick fix the issue I generate the main.jsbundle manually before the xcodebuild:
react-native bundle --entry-file='index.js' --bundle-output='./ios/[AppName]/main.jsbundle' --dev=false --platform='ios' --assets-dest='./ios'
This fix seems to me a hack than a real solution.
Anyone can tell me why building the project using a .xcworkspace don't generate the main.jsbundle while building a .xcodeproj generate it ?
Thanks!

Related

Unable to resolve module "empty-module.js" error

For building an iOS React Native app, I am able to successfully run the following command in a MacOS terminal:
xcodebuild archive -workspace MyProject.xcworkspace -derivedDataPath build -scheme MyProject -archivePath $PWD/build-artifacts/MyProject.xcarchive -configuration Release CODE_SIGN_STYLE='Automatic' BITCODE_GENERATION_MODE='bitcode'
However when invoking the same command via a Jenkins "Execute shell" step, it results in the following error:
error Unable to resolve module /Users/mike/git/my-project/node_modules/react-native/node_modules/metro-runtime/src/modules/empty-module.js from /Users/mike/git/my-project/_:
None of these files exist:
* ../my-project/node_modules/react-native/node_modules/metro-runtime/src/modules/empty-module.js(.native|.native.js|.js|.native.json|.json|.native.ts|.ts|.native.tsx|.tsx)
* ../my-project/node_modules/react-native/node_modules/metro-runtime/src/modules/empty-module.js/index(.native|.native.js|.js|.native.json|.json|.native.ts|.ts|.native.tsx|.tsx)
at ModuleResolver.resolveDependency (/Users/mike/git/my-project/node_modules/react-native/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:136:15)
at ModuleResolver._getEmptyModule (/Users/mike/git/my-project/node_modules/react-native/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:49:26)
at ModuleResolver._getFileResolvedModule (/Users/mike/git/my-project/node_modules/react-native/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:195:21)
at ModuleResolver.resolveDependency (/Users/mike/git/my-project/node_modules/react-native/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:132:19)
at DependencyGraph.resolveDependency (/Users/mike/git/my-project/node_modules/react-native/node_modules/metro/src/node-haste/DependencyGraph.js:231:43)
at Object.resolve (/Users/mike/git/my-project/node_modules/react-native/node_modules/metro/src/lib/transformHelpers.js:129:24)
at resolve (/Users/mike/git/my-project/node_modules/react-native/node_modules/metro/src/DeltaBundler/traverseDependencies.js:396:33)
at /Users/mike/git/my-project/node_modules/react-native/node_modules/metro/src/DeltaBundler/traverseDependencies.js:412:26
at Array.reduce (<anonymous>)
at resolveDependencies (/Users/mike/git/my-project/node_modules/react-native/node_modules/metro/src/DeltaBundler/traverseDependencies.js:411:33)
I have ensured that the PATH is set consistently between the system and Jenkins for build tools like node and npm. I would appreciate any input from anyone who has experienced
similar issues.

How to use Fastlane with a CMake generated XCode project with dependency on WebP?

I have a project written in C++ where CMake is used to generate the build system for various platforms including iOS. The project has a dependency on WebP. You can find an example project on GitHub here that can be used to reproduce things & I've included the relevant source files at the end of this post for completeness.
The Xcode build system for iOS is generated using CMake as follows:
cmake -G Xcode -DCMAKE_TOOLCHAIN_FILE=third_party/ios-cmake/ios.toolchain.cmake -DPLATFORM=OS64 -DDEPLOYMENT_TARGET=15.0 -DENABLE_BITCODE=0 -S . -B cmake-build-release
We can now attempt to build/archive the app using Fastlane with the command from within the generated cmake-build-release directory:
bundle exec fastlane ios beta
However this fails due to being unable to locate various webp object files (that based on console output it appears to have previously successfully compiled):
...
▸ Compiling buffer_dec.c
▸ Compiling alpha_dec.c
▸ Building library libwebpdsp.a
...
** ARCHIVE FAILED **
▸ The following build commands failed:
▸ Libtool /Users/dbotha/Library/Developer/Xcode/DerivedData/CMakeFastlaneWebpTest-dlwvukebfiwjqvaqiepshuxqklhh/ArchiveIntermediates/CMakeFastlaneWebpTest/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/libwebpdecoder.a normal (in target 'webpdecoder' from project 'CMakeFastlaneWebpTest')
▸ (1 failure)
▸ ❌ error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: can't open file: /Users/dbotha/CLionProjects/CMakeFastlaneWebpTest/cmake-build-release/third_party/libwebp/CMakeFastlaneWebpTest.build/Release-iphoneos/webpdecode.build/Objects-normal/arm64/alpha_dec.o (No such file or directory)
▸ ❌ error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: can't open file: /Users/dbotha/CLionProjects/CMakeFastlaneWebpTest/cmake-build-release/third_party/libwebp/CMakeFastlaneWebpTest.build/Release-iphoneos/webpdecode.build/Objects-normal/arm64/buffer_dec.o (No such file or directory)
...
Internally Fastlane attempted to build/archive the project with the following command:
xcodebuild -scheme CMakeFastlaneWebpTest -project ./CMakeFastlaneWebpTest.xcodeproj -configuration Release -destination 'generic/platform=iOS' -archivePath ./out.xcarchive archive
Interestingly an archive can be successfully generated if I use the following xcodebuild command (note how -target flag is used instead of -scheme):
xcodebuild -project CMakeFastlaneWebpTest.xcodeproj archive -target CMakeFastlaneWebpTest -configuration Release
After this successful attempt bundle exec fastlane ios beta will now also succeed as the compiled object files are where it expected them to be.
Now I'd happily workaround this issue using my xcodebuild + -target flag approach and then use the fastlane command to push to Testflight, etc. but the real project (not this toy example) takes a very long time to build so building it twice is really wasteful from a cost point of view on CI platforms.
Does anyone have any idea what's going on here & how I can successfully build things in the first instance using fastlane without my own explicit call to xcodebuild first? Or alternatively how can I have Fastlane use the successfully built objects from my workaround so it doesn't need to rebuild the entire project from scratch?
CMakeLists.txt
cmake_minimum_required(VERSION 3.23)
project(CMakeFastlaneWebpTest)
set(CMAKE_CXX_STANDARD 14)
add_executable(CMakeFastlaneWebpTest src/main.cpp)
# Skip building of unused webp tools which fail for me under ios:
set(WEBP_BUILD_ANIM_UTILS OFF)
set(WEBP_BUILD_CWEBP OFF)
set(WEBP_BUILD_DWEBP OFF)
set(WEBP_BUILD_GIF2WEBP OFF)
set(WEBP_BUILD_IMG2WEBP OFF)
set(WEBP_BUILD_VWEBP OFF)
set(WEBP_BUILD_WEBPINFO OFF)
set(WEBP_BUILD_WEBPMUX OFF)
set(WEBP_BUILD_EXTRAS OFF)
set(WEBP_BUILD_WEBP_JS OFF)
add_subdirectory(third_party/libwebp EXCLUDE_FROM_ALL)
target_link_libraries(CMakeFastlaneWebpTest PRIVATE webpdecoder webpdemux)
include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/third_party/libwebp/src)
configure_file(${CMAKE_SOURCE_DIR}/fastlane/Appfile ${CMAKE_BINARY_DIR}/fastlane/Appfile COPYONLY)
configure_file(${CMAKE_SOURCE_DIR}/fastlane/Fastfile ${CMAKE_BINARY_DIR}/fastlane/Fastfile COPYONLY)
configure_file(${CMAKE_SOURCE_DIR}/Gemfile ${CMAKE_BINARY_DIR}/Gemfile COPYONLY)
configure_file(${CMAKE_SOURCE_DIR}/Gemfile.lock ${CMAKE_BINARY_DIR}/Gemfile.lock COPYONLY)
set_target_properties(CMakeFastlaneWebpTest PROPERTIES
XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET ${DEPLOYMENT_TARGET}
MACOSX_BUNDLE TRUE
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_SOURCE_DIR}/src/iOS-Info.plist.in
MACOSX_BUNDLE_GUI_IDENTIFIER com.dbotha.CMakeFastlaneWebpTest
MACOSX_BUNDLE_BUNDLE_NAME CMakeFastlaneWebpTest
MACOSX_BUNDLE_BUNDLE_VERSION "0.1"
MACOSX_BUNDLE_SHORT_VERSION_STRING "0.1"
)
set_xcode_property(CMakeFastlaneWebpTest PRODUCT_BUNDLE_IDENTIFIER "com.dbotha.CMakeFastlaneWebpTest" All)
set_xcode_property(CMakeFastlaneWebpTest CODE_SIGN_IDENTITY "iPhone Developer" All)
set_xcode_property(CMakeFastlaneWebpTest DEVELOPMENT_TEAM "GFP63373B2" All)
fastlane/Appfile
app_identifier("com.dbotha.CMakeFastlaneWebpTest") # The bundle identifier of your app
apple_id("REPLACE_ME") # Your Apple Developer Portal username
itc_team_id("REPLACE_ME") # App Store Connect Team ID
team_id("REPLACE_ME") # Developer Portal Team ID
fastlane/Fastfile
default_platform(:ios)
platform :ios do
desc "Push a new beta build to TestFlight"
lane :beta do
build_app(scheme: "CMakeFastlaneWebpTest", configuration: "Release")
upload_to_testflight
end
end
src/main.cpp
#include <iostream>
#include <webp/demux.h>
int main() {
WebPAnimDecoderOptions decOptions;
(void)decOptions;
std::cout << "Hello, World!" << std::endl;
return 0;
}
I'm not an expert in this topic but according to the documentation you should provide workspace to build your scheme.
To build an Xcode workspace, you must pass both the -workspace and
-scheme options to define the build. The parameters of the scheme will
control which targets are built and how they are built, although you may
pass other options to xcodebuild to override some parameters of the
scheme.
Scheme controls what target will be build, and guessing by your example, since you do not provide a workspace, it gets lost in the process.
The scheme is not lost anymore if you build the target manually. Since it is already build the scheme does not have to do a thing.
My proposals:
Option 1: Try adding workspace to build_app parameters in Fastfile.
Option 2: Don't bother with building scheme just use target in the
build_app parameters in Fastfile like so: build_app(target: "CMakeFastlaneWebpTest", configuration: "Release")

UnityWebRequest.mm missing '#include <pthread/sched.h>' while building Unity project for iOS

I am building a Unity app for iOS. I am using iOS Project Builder, which allows building iOS apps on Windows. It uses Cocoapods to install Frameworks.
I have this error:
Building the dependency project UnityFramework...
=============================================================================
WARNING: this project contains shell scripts, which CANNOT BE RUN on Windows
without being translated first.
WORKAROUND: for now, please remove your assets & plugins having shell scripts
in their build phases, or translate them to batch scripts and call them in a
pre-packaging script (or ignore this warning if the scripts are non-critical)
In Xcode project: Unity-iPhone.xcodeproj
-----------------------------------------------------------------------------
shell script found:
diff "${PODS_PODFILE_DIR_PATH}/Podfile.lock" "${PODS_ROOT}/Manifest.lock" > /dev/null
if [ $? != 0 ] ; then
# print error to STDERR
echo "error: The sandbox is not in sync with the Podfile.lock. Run pod install or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode outputs to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n
=============================================================================
These scripts might be non critical - attempting to proceed anyway.
+ Preparing output directory...
+ XCFrameworks: 0 supplied
+ Libraries: 9 supplied, 0 built
+ Frameworks: 0 supplied, 0 built
+ Pruning compilation results...
+ Pre-parsing project files...
+ Building UnityFramework for iphoneos (configuration: Release)
+ [armv7] Compiling ./Classes/Unity/UnityWebRequest.mm...
./Classes/Unity/UnityWebRequest.mm(99,13): error: missing '#include <pthread/sched.h>'; 'sched_yield' must be declared before it is used
sched_yield();
^
C:\Users\IRAKLI\iOS Project Builder for Unity\SDK\usr\include\pthread\sched.h(40,12): note: declaration here is not visible
extern int sched_yield(void);
^
1 error generated.
Full log: https://pastebin.com/Yb2RYzLp
OS: Windows 10 64 bit
Unity Version: 2020.3.12f1
iOS Builder: 3.35.4
iOS SDK: 14.5
Firebase: 9.0.0
Any help would be highly appreciated.

":CFBundleIdentifier", Does Not Exist: ReactNative 0.58 on Mac / iOS

I am following the ReactNative tutorial for 0.58. I do everything it says to do and I am crashing after running react-native run-ios. I have seen this extremely similar SO question from 2016.
I attempted react-native upgrade and it recommended doing react-native-git-upgrade.This did nothing. Same problem.
The bit on running ./configure in the question above after cd-ing into glog did nothing. There was no configure script there. In the path NewStupidProject/node_modules/react-native/scripts there is a script called ios-configure-glog.sh. I run bash ios-configure-glog.sh and it says ios-configure-glog.sh: line 31: ./configure: No such file or directory.
I have also attempted setting Xcode to use the legacy build system. This did not fix the issue. I am restarting my laptop now to see if that makes any of these changes take effect. No luck. At the top it says:
Found Xcode project NewStupidProject.xcodeproj Building using
"xcodebuild -project NewStupidProject.xcodeproj -configuration Debug
-scheme NewStupidProject -destination id=854019D1-8EE7-4D13-87E1-385E6CAC21BE -derivedDataPath build" User
defaults from command line:
IDEDerivedDataPathOverride = /Users/me/NewStupidProject/ios/build
Prepare build
note: Using legacy build system
=== BUILD TARGET double-conversion OF PROJECT React WITH CONFIGURATION Debug ===
When I go into the home directory and run react-native --version the output is:
[NewStupidProject](master)$ react-native --version
react-native-cli: 2.0.1
react-native: 0.58.4
[NewStupidProject](master)$
My output after crashing is:
** BUILD FAILED **
The following build commands failed:
PhaseScriptExecution Install\ Third\ Party /Users/me/native_react_apps/NewStupidProject/ios/build/Build/Intermediates.noindex/React.build/Debug-iphonesimulator/double-conversion.build/Script-190EE32F1E6A43DE00A8543A.sh
(1 failure)
Installing
build/Build/Products/Debug-iphonesimulator/NewStupidProject.app An
error was encountered processing the command
(domain=NSPOSIXErrorDomain, code=22): Failed to install the requested
application The bundle identifier of the application could not be
determined. Ensure that the application's Info.plist contains a value
for CFBundleIdentifier. Print: Entry, ":CFBundleIdentifier", Does Not
Exist
Command failed: /usr/libexec/PlistBuddy -c Print:CFBundleIdentifier
build/Build/Products/Debug-iphonesimulator/NewStupidProject.app/Info.plist
Print: Entry, ":CFBundleIdentifier", Does Not Exist
Error: Command failed: /usr/libexec/PlistBuddy -c
Print:CFBundleIdentifier
build/Build/Products/Debug-iphonesimulator/NewStupidProject.app/Info.plist
Print: Entry, ":CFBundleIdentifier", Does Not Exist
at checkExecSyncError (child_process.js:637:11)
at Object.execFileSync (child_process.js:655:13)
at Promise.then (/Users/me/native_react_apps/NewStupidProject/node_modules/react-native/local-cli/runIOS/runIOS.js:208:5)
How is it possible for the setup process to be this fraught with errors and this difficult?
WHY is this error message not in the Troubleshooting ReactNative setup?
HOW do I fix this? Is it possible to avoid this altogether in the future?
Other versioning info:
XCode: 10.1
Command Line Tools: 10.1
yarn: 0.27.5
watchman: 4.9.0
homebrew: 2.0.1
npm: 6.8.0
node: v11.9.0
macOS: 10.13.6
UPDATE:
I am trying to implement the solution in this issue in GitHub and I'm getting:
dyld: Library not loaded:
/usr/local/opt/readline/lib/libreadline.7.dylib Referenced from:
/usr/local/bin/awk Reason: image not found
./ios-install-third-party.sh: line 20: 24497 Broken pipe: 13
shasum -p "$cachedir/$file"
24498 Abort trap: 6 | awk -v hash="$hash" '{exit $1 != hash}' Incorrect hash: 61067502c5f9769d111ea1ee3f74e6ddf0a5f9cc
?/Users/me/.rncache/glog-0.3.5.tar.gz
UPDATE No. 2 I am trying to run the watchman watch-del-all command as recommended here to clear the cache for RN > 0.50 and the whole thing is hanging.
I tried modify the build system and it worked for me.
Detail:
Open your project workspace file in Xcode, and
File -> Workspace Settings -> Build system -> Legacy Build system

build alljoyn_darwin in Xcode 6.1.1 and get a No SConstruct file found error

Recently I am doing some AllJoyn development on iOS and OS X. When I run xcodebuild for alljoyn_darwin.xcodeproj using command line as below:
/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -project alljoyn_darwin.xcodeproj -scheme alljoyn_core_ios -sdk iphoneos -configuration Debug PLATFORM_NAME=iphoneos
I got an error like this:
export variant=normal
/opt/local/bin/scons -u OS=darwin CPU=arm BR=on BINDINGS=cpp SERVICES= WS=off VARIANT=Debug --
scons: *** No SConstruct file found.
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/scons-2.3.4/SCons/Script/Main.py", line 920, in _main
Command /opt/local/bin/scons failed with exit code 2
** BUILD FAILED **
The following build commands failed:
ExternalBuildToolExecution alljoyn_core_ios
(1 failure)
I really have no idea why I got this, I followed all the instruction in the official site--Build From Source and I am sure I set the correct OPENSSL_ROOT path. I installed scons using Macport and it was installed correctly. I tried double-click the alljoyn_darwin.xcodeproj from finder but I got the same error.
scons: *** No SConstruct file found.
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/scons-2.3.4/SCons/Script/Main.py", line 920, in _main
Command /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/scons-2.3.4 failed with exit code 2
So I am stuck here. But the thing is I can successfully run AllChatz sample in sdk_14.12 for iOS in iphonesimulator for iPhone6. openssl version is 1.0.2 and I tried build both for alljoyn sdks 14.06 and 14.12. same error happened. I don't know if this is related. Anyone can help here? Many thanks.
The problem is that scons cant find the root-level SConstruct script, which probably doesnt help much as you can see that in the error :)
When you use the "-u", that tells scons to look up the directory structure for the root-level SConstruct script.
SCons must be executed from within the project directory structure. Look for the root-level SConstruct, and make sure you're executing scons from within the project directory structure.

Resources