Accessing xcode variables in Cordova config - ios

I have an iOS application that has many different configurations all under the same Xcode project. I am using Targets to achieve this. My application utilizes Cordova. I am wondering if it is possible/best way to access Xcode variables within my Cordova config.xml file.
I am hoping to achieve having one shared config file with many targets in Xcode and when I select a target and build and run my variables for that target will be dynamically injected into my config.

Try to create 'Configuration Settings File' (.xcconfig) and configure variables from the info.plist with this pattern $(VARIABLE) and add into the .xcconfig file. This way you'll be able to set “Bundle Identifier”, “Bundle name”, “Bundle version” and other stuff you need to configure.
You may refer guide link to get more info: https://www.appcoda.com/xcconfig-guide/
Hope it helps!

Related

How to configure independent .xcconfig for every Configuration(Debug, Release) in each target on a project with CocoaPods added

I have a project which supports multiple Brands (used targets to configure appicon, Launch Screen .., etc) and each targets needs multiple environments where am using Configuration(Debug, Release) with schemes for every configuration.
Now to add environment variables am using .xcconfig files which am not sure how to configure for every target. The Configuration on Project level in Xcode has Cocoapods configured.
NOTE: While pod install, it shows warning in terminal to include pods config data into my custom config file. Any easy way to achieve this ?
Found a helpful link where it explains about import config into a config.
https://betterprogramming.pub/working-with-custom-xcconfigs-and-coccoapods-6b87ead94708

Xcode: Custom build configurations in Swift Package Manager

I'm trying to get SPM to work with different build configurations other than Debug and Release. Our iOS project has different schemes (e.g. Debug-Staging, Debug-Production, Alpha-Staging, Alpha-Production, etc.) where I set the bundle identifier, some flags, etc.
Is there a way to achieve that diversification even if SPM only "understands" Debug and Release?
Specify path to your custom config file when invoking generate-xcodeproj command.
Sample
swift-package generate-xcodeproj --xcconfig-overrides Config.xcconfig

Could not get GOOGLE_APP_ID in Google Services file from build environment

For setting up firebase i am using two config 1.GoogleService-Info-test.plist, 2.GoogleService-Info-prdn.plist for UAT and Production. For installing crashlytics using firebase i have followed firebase documentation https://firebase.google.com/docs/crashlytics/get-started?authuser=1#ios. But when i try to run, it throws error in build phase while running script.
I tried without changing config file name and it worked.
Error msg at build phase while running fabric run script "Could not get GOOGLE_APP_ID in Google Services file from build environment".
Can anyone suggest better solution to achieve my requirement.
This is one way you can do it, by having your projects environments separated by targets, by doing so you can then add your different plist files and just check the target that they belong to, that way when you compile the target it will take it's corresponding plist file
Another way to do it, or to look up how to do it, it's called multiple environments with firebase, here are some helpful links
Use different GoogleService-Info.plist for different build schemes
https://medium.com/rocket-fuel/using-multiple-firebase-environments-in-ios-12b204cfa6c0
This worked for me:
When install Crashlytic with Firebase, for multiple scheme, you can have error Could not get GOOGLE_APP_ID in Google Services file from build environment. You can fix it by:
In Build Settings, add a user define for file name in User Defined:
In Build Phases, tap plus button, New Run Script Phase above your Crashlytic build phase, and type this code to the text field. Remember to rename %YOUR_CUSTOM_PATH_TO_FOLDER% to your path to Plist files:
GOOGLE_SERVICE_INFO_PLIST_FROM="${PROJECT_DIR}/%YOUR_CUSTOM_PATH_TO_FOLDER%/${FIREBASE_CONFIG_FILE}.plist"
BUILD_APP_DIR="${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}"
GOOGLE_SERVICE_INFO_PLIST_TO="${BUILD_APP_DIR}/GoogleService-Info.plist"
cp "${GOOGLE_SERVICE_INFO_PLIST_FROM}" "${GOOGLE_SERVICE_INFO_PLIST_TO}"
This worked for me:
Make sure you add the Xcode Crashlytics build phase after Copy Bundle Resources.
I had this in my "Build Phases" and it's works
"${PODS_ROOT}/FirebaseCrashlytics/run"
"${PODS_ROOT}/FirebaseCrashlytics/upload-symbols" -gsp "${PROJECT_DIR}/MyApp/GoogleService-Info.plist" -p ios "${DWARF_DSYM_FOLDER_PATH}/${DWARF_DSYM_FILE_NAME}"
Our project only one target, but we need to use two Firebase config files GoogleService-Info-Prod.plist and GoogleService-Info-Dev.plist.
I had this in my "Build Phases" and it works.
if [ "${CONFIGURATION}" = "Release" ]; then
${PODS_ROOT}/FirebaseCrashlytics/run -gsp ${PROJECT_DIR}/RushCard/FirebaseConfig/GoogleService-Info-Prod.plist
else
${PODS_ROOT}/FirebaseCrashlytics/run -gsp ${PROJECT_DIR}/RushCard/FirebaseConfig/GoogleService-Info-Dev.plist
fi
In my case I created New Run Script Phrase above Compile Sources, that's why I always see
Could not get GOOGLE_APP_ID in Google Services file from build environment
When I moved Crashlytic's run script at the end of list bug was disappear. Please look the following screen shot:
And article about it is here
I use multiple configurations for several white-labelled apps. I added a User-Defined variable FIREBASE_SUFFIX and changed my script to the following:
${PODS_ROOT}/FirebaseCrashlytics/run -gsp ${PROJECT_DIR}/Firebase/GoogleService-Info-${FIREBASE_SUFFIX}.plist
NOTE: I use Carthage for firebase here: https://github.com/firebase/firebase-ios-sdk/blob/master/Carthage.md. If you're this same setup, you should use something like this instead (replace the path to where you put your script files):
${PROJECT_DIR}/scripts/run -gsp ${PROJECT_DIR}/Firebase/GoogleService-Info-${FIREBASE_SUFFIX}.plist
Another way is to make sure one plist keeps the original name GoogleService-Info.plist
Different targets meant more work to update CI for me.
This is valid for Xcode 11 at least, not tested on any other versions
I was using new Firebase/Crashlytics which beta and getting error "No Google App ID or Google Services file provided" when I try to upload manually dSYMS
Here is command:
/path/to/pods/directory/FirebaseCrashlytics/upload-symbols
-gsp/path/to/GoogleService-Info.plist -p ios /path/to/dSYMs
Then I reliaze there should be space between "-gsp" and path to Google.plist after that It worked.
The solution for me was removing the call to upload-symbols script.
One of the Crashlytics guides mentions you should add this:
${PODS_ROOT}/FirebaseCrashlytics/run
/path/to/pods/directory/FirebaseCrashlytics/upload-symbols <- Not needed
I misinterpreted this... the run script already calls upload-symbols so there's no need to add a second call.
Make sure in Xcode file explorer (i.e on the left side) "GoogleService-Info.plist" is showing. If not you have to drag and drop "GoogleService-Info.plist" in the Xcode panel.
In my case problem is I copy-pasted the file in the project location, due to this file reference is missing in the Project info.
Well all above answers purpose a possible solution for this issue, in my case GoogleService.plist file was missing from 'Copy Bundle Resources' by adding into it worked in my case..
To check the file goto
Project Directory >> Build Phases >> Copy Bundle Resources
add it add here if you find missing.
If these solutions provided above do not work, I solved mine by going to Build phases as shown on this image. Click on plus and add Google plist
I was able to fix this by locate where is my GoogleService-Info.plist, copy it to ios folder in Flutter and run with this script
"$PODS_ROOT/FirebaseCrashlytics/upload-symbols" --flutter-project "$PROJECT_DIR/firebase_app_id_file.json" -gsp "$PROJECT_DIR/GoogleService-Info.plist" -p ios "$DWARF_DSYM_FOLDER_PATH/$DWARF_DSYM_FILE_NAME"
Update:
I found a better solution:
Just upgrade all firebase package to lastest version
Remove Crashlytics build script
Run flutter clean, flutter pub get
pod install (in ios folder)
I had this issue because I didn't download GoogleService-Info.plist file from Firebase console.
If you have your project on Firebase but missing this file in Xcode, don't worry, you don't need to do the setup again from the beginning. Just go to:
Project Settings > General > Scroll down and in the "Your Apps" panel you will see the file and you can download it and import it in the Xcode project.
I had the same error, also due to the fact that I have multiple bundle identifier and therefore I have a build phase script called Firebase Script (that pinpoints to the correct GoogleService-Info.plist ) that was running after the Crashlytics script.
The solution is to run Firebase Script before the Crashlytics script.
In my case I had a different name in my file, his name was GoogleService-Enterprise-Info.plis when I change it to the normal name GoogleService-Info.plist, IT WORK FINE !!
I faced the same issue for #react-native-firebase/crashlytics
In case you are facing this issue, you probably have missed the 'ios setup' instruction mentioned in below link. Please follow the instruction to fix the issue.
https://rnfirebase.io/#generating-ios-credentials
Just download from Settings of your projects and place for your correct target which you are running.
This error would be shown if there is a space in your project name or in the path of your project.
Read more in this GitHub Issue
Additionally to other answers..
I faced that problem with exact same error message and in my case everything was ok with file GoogleService-Info.plist except that it was genereated with wrong Bundle ID for application (it was changed in XCode much later than initial Firebase setup happened), so I had to create new app in Firebase Console with correct Bundle ID (it's not able to edit) and download new GoogleService-Info.plist
If you are using one of the popular build scripts going around for handling multiple different environments, it is probably useful to know that you should use a different GoogleService-Info.plist destination based on the target platform:
// iOS
PLIST_DESTINATION=${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app
// watchOS
PLIST_DESTINATION=${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.appex
// macOS
PLIST_DESTINATION=${BUILT_PRODUCTS_DIR}/${CONTENTS_FOLDER_PATH}/Resources
Ultimate guide:
Assure that in Runner folder you have file GoogleService-Info.plist and it is attached in your project
If you don't have this file go to Firebase Console, add you IOS app and download the GoogleService-Info.plist file, then add it to you project's Runner folder by XCode.
If there is no such file in XCode but it exists physically in the folder then right click on Runner folder (in Runner project) -> Add files to Runner -> Select that file
If you want to use multiple flavors add ENV_SUFFIX in Runner (target) -> Build Settings -> User-Defined (on the bottom)
Still in the target's Runner change tab to Build Phases -> Press Plus button -> New Run Script Phase -> Name it as Copy GoogleService-Info.plist and add this line
cp Runner/GoogleService-Info_${ENV_SUFFIX}.plist Runner/GoogleService-Info.plist
IMPORTANT! This script has to be before Initialize Crashlytics step or any other Firebase related script (you can drag it to the top)
Add other GoogleService-Info.plist files with suffix for the env. In my case those would be the _dev _prod and _tst files from the first screen shot
Enjoy multiflavor app
Try downgrading, it worked for me!
I used:
'Fabric', '1.9.0'
'Crashlytics', '3.12.0'

Xcode SwiftGen: build fails in project with multiple targets

How should I configure SwiftGen when using Cocoapods and multiple targets?
I have a project with two targets (MyProject and MyProject Dev) which has SwiftGen integrated with Cocoapods.
I can build the first target with no problems whatsoever. However the 'Dev' target always fails. The script phase is the last step in Build Phases, however running it earlier or later seems to make no difference.
On failure, I've observed the following:
The generated .swift file has an import statement, 'import MyProject' which shouldn't be there
'No type named [ClassName] in module [MyProject]' OR 'No such module [MyProject]'
SwiftGen version I'm using is 5.2.1
Xcode 9.2, targeting iOS 10.0
SwiftGen from version 5 onwards requires a configuration file, so I've set one up as follows:
output_paths: Sources/Generated
storyboards:
- paths: MyProject/Storyboards/Base.lproj
templateName: swift4
output: MyProject/Storyboards/Storyboards.swift
params:
ignoreTargetModule: true
So far I've looked up documentation and the following issue:
https://github.com/SwiftGen/SwiftGen/issues/273
However the difference is that I'm using a different type of SG installation and my project fails to build (rather than simply not generating any resources)
Cleaning project, build folder and deleting derived data had no effect. I'm assuming that I may have missed something in configuration setup, but I can't see what that would be.
First question on here, so apologies if I missed something, will be happy to edit.
I had the same issue with generating Storyboard file. Try to modify your config file:
params:
ignoreTargetModule: true
module: <YOUR_PROJECT_NAME>
Hope it will help.
Hesitant to call this a solution, it's more of a workaround, but the following approach has at least allowed the projects to be built and run.
Remove the SwiftGen script phase from the 'Dev' target
Build the project using the main scheme that includes SwiftGen to generate all the necessary objects and constructs
Switch to Dev scheme and run the project.
The Strings.swift file created by SwiftGen is linked to both targets, so even after running the script in one scheme the resources within that file will be available to both regular and Dev targets.
Hope this helps someone.

Xcode: How to remove a target dependency from the build phase for a specific configuration

I have an app that includes a Watch Extension and App target. I would to be able to have one of my configurations (for a beta) exclude these targets from the target dependencies so that I can distribute the build without the Watch Extension/App. However I still want my debug configuration to include them. Is this possible? Perhaps there is some run script that could add Target Dependencies manually? Thanks.
Duplicate your "Release" Configuration, that will include your Watch Extension. Here the official resource: https://developer.apple.com/library/ios/recipes/xcode_help-project_editor/Articles/BasingBuildConfigurationsonConfigurationFiles.html
In this configuration.
Remove the WatchKit extension from Target Dependencies
Remove WatchKit extension from Embed App Extensions
Duplicate your main target and remove the dependencies from the copy. Then duplicate your scheme and set its target to your new target.
Another solution would be to wrap the build and embedding into a separate script and run it manually, you can see how cocoapods are doing that.

Resources