Flutter: Upload dsym symbols to Firebase crashlytics with flavors - ios

I want to upload dsym symbols from Flutter app with multiple flavors. Each GoogleService-Info is places inside config/flavor_name folder. What script should I add to "Build Phases" to upload dsym to Firebase Crashlytics?
Try script from another thread but it seems it doesn't work

I found a script
environment="default"
if [[ $CONFIGURATION =~ -([^-]*)$ ]]; then
environment=${BASH_REMATCH[1]}
fi
GOOGLESERVICE_INFO_PLIST=GoogleService-Info.plist
GOOGLESERVICE_INFO_FILE=${PROJECT_DIR}/config/${environment}/${GOOGLESERVICE_INFO_PLIST}
if [ ! -f $GOOGLESERVICE_INFO_FILE ]
then
echo "No GoogleService-Info.plist found. Please ensure it's in the proper directory."
exit 1
fi
google_app_id=$(cat $GOOGLESERVICE_INFO_FILE | grep -oEi '\d:\d*?:ios:[[:alnum:]]*')
echo $google_app_id
$PODS_ROOT/FirebaseCrashlytics/upload-symbols --build-phase --validate -ai $google_app_id
$PODS_ROOT/FirebaseCrashlytics/upload-symbols --build-phase -ai $google_app_id

Related

xcode command line to configure "embed frameworks"

As showed in the screen above, I couldn't find any xcodebuild command line to add/remove the embed frameworks, is there any way we can do so via command line (to remove or add the line)? As I need to automate the build process.
For conditionally embedding frameworks to your app you should make a script under Build Phases that copies your dynamic library to Frameworks folder of your app and then sign it e.g.:
# Path to your framework to copy. You must have two compiled versions: Debug(arm64, x86_64) and Release(arm64).
FRAMEWORK=".../$CONFIGURATION/MyFramework.framework"
# Frameworks folder of your app
NAME=$(basename $FRAMEWORK)
DESTINATION=${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/$NAME
# Copy (if needed) and sign
if [ ! -d $DESTINATION ]; then
cp -r $FRAMEWORK $DESTINATION
codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} ${OTHER_CODE_SIGN_FLAGS:-} --preserve-metadata=identifier,entitlements $DESTINATION
fi
For xcframework you can specify subfolder path in additional for a target arch:
# Release device only
if [ $PLATFORM_PREFERRED_ARCH == "arm64" ]; then
FRAMEWORK=".../MyFramework.xcframework/ios-arm64/MyFramework.framework"
fi

com.crashlytics.mac.error-domain.process-dsym Code=4 "This version of OSX is not able to perform the necessary dSYM transformations

I tried multiple time however no luck getting ...pls help me
Using Xcode 10.1 and Objective c
Thanks in advance
I put in script
"${PODS_ROOT}/Fabric/run"
echo "UPLOADING DSYM FILE ON FIREBASE CONSOLSE"
INFO_PLIST="$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH"
if [ -f "$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH" ] ; then
ENVIRONMENT_NAME=`/usr/libexec/PlistBuddy -c "Print :EnvironmentName" "$INFO_PLIST"`
if [ "$ENVIRONMENT_NAME" = "PROD" ] || [ "$ENVIRONMENT_NAME" = "prod" ]; then
echo "PROD CONFIGURATION"
"${PODS_ROOT}/Fabric/upload-symbols" -gsp "${PROJECT_DIR}/DBS/SupportingFiles/Production/ProdGoogleService-Info.plist" -p ios "${DWARF_DSYM_FOLDER_PATH}/${DWARF_DSYM_FILE_NAME}"
elif [ "$ENVIRONMENT_NAME" = "UAT" ] || [ "$ENVIRONMENT_NAME" = "uat" ]; then
echo "UAT CONFIGURATION"
"${PODS_ROOT}/Fabric/upload-symbols" -gsp "${PROJECT_DIR}/DBS/SupportingFiles/UAT/UATGoogleService-Info.plist" -p ios "${DWARF_DSYM_FOLDER_PATH}/${DWARF_DSYM_FILE_NAME}"
else
echo "DEV CONFIGURATION"
"${PODS_ROOT}/Fabric/upload-symbols" -gsp "${PROJECT_DIR}/DBS/SupportingFiles/SITUAT/SITUATGoogleService-Info.plist" -p ios "${DWARF_DSYM_FOLDER_PATH}/${DWARF_DSYM_FILE_NAME}"
fi
fi
Getting error while running in device
[31merror: could not complete submission of dSYM at /Users/XXUSERXX/Library/Developer/Xcode/DerivedData/ProjectName-flcoueeibbfifebpxptgzctdsqel/Build/Intermediates.noindex/ArchiveIntermediates/ProjectNameAlpha/BuildProductsPath/ProjectNameAlpha-iphoneos/ProjectName.app.dSYM:
Error Domain=com.crashlytics.mac.error-domain.process-dsym Code=4 "This version of OSX is not able to perform the necessary dSYM transformations."
UserInfo={NSLocalizedFailureReason=This version of OSX is not able to perform the necessary dSYM transformations.}
[0m Command PhaseScriptExecution failed with a nonzero exit code
This version of OSX is not able to perform the necessary dSYM transformations.
You got your answer basically. Is it an old project? You should update at least the mac os to a newer version and try again. xCode 10 is old, too.
On the other hand, crashlytics is bought up by Google and now called Firebase Crashlytics. It has a new version 4.0.0 (Not beta), so I suggest to install that pod if it is possible. Fabric service has been shut down completely since April of 2020.
https://firebase.google.com/docs/crashlytics/get-started

xcodebuild is not compiling the project unless it is opened using Xcode atleast only once for cocoapods integrated project

I have a project with cocoa pods.
Here is the command that I use to build the project.
/usr/bin/xcodebuild -scheme Jenkins -workspace
/Users/Shared/Jenkins/Documents/Jenkins/Jenkins2/Jenkins.xcworkspace
-configuration Release clean build CONFIGURATION_BUILD_DIR=/Users/Shared/Jenkins/Documents/JenkinsTestNuu/app
'CODE_SIGN_IDENTITY=iPhone Distribution: XXXX yay (3G5FKTZJ2K)'
PRODUCT_BUNDLE_IDENTIFIER=com.XXXX.two
PROVISIONING_PROFILE=6e6506e9-8233-4886-9084-ce21e8f8bbae
The above script works good only if the project has been opened using Xcode atleast once after that Xcode can be closed no issues.
If the project has not been opened then If I run the script
the wheel is spinning below without any progress forever for example in the below image
if its opened once instead of the spinning wheel below texts would be shown below
=== CLEAN TARGET XWebView OF PROJECT Pods WITH CONFIGURATION Release ===
Check dependencies
Clean.Remove clean
/Users/Shared/Jenkins/Documents/JenkinsTestNuu/app/XWebView.framework.dSYM
builtin-rm -rf /Users/Shared/Jenkins/Documents/JenkinsTestNuu/app/XWebView.framework.dSYM
Clean.Remove clean
/Users/Shared/Jenkins/Library/Developer/Xcode/DerivedData/appanme-bqjwbjcqisegldeaonpytprisnig/Build/Intermediates/Pods.build/Release-iphoneos/XWebView.build
builtin-rm -rf /Users/Shared/Jenkins/Library/Developer/Xcode/DerivedData/appanme-bqjwbjcqisegldeaonpytprisnig/Build/Intermediates/Pods.build/Release-iphoneos/XWebView.build
Clean.Remove clean
/Users/Shared/Jenkins/Documents/JenkinsTestNuu/app/XWebView.framework
builtin-rm -rf /Users/Shared/Jenkins/Documents/JenkinsTestNuu/app/XWebView.framework
=== CLEAN TARGET Pods OF PROJECT Pods WITH CONFIGURATION Release ===
Check dependencies
etc...
The problem is not observed in any non-cocoapods project.
So what would be the cause and how to solve it ?
Why it happens ?
A quick diffMerge tool analysis between a project opened by Xcode Vs a same project not opened by Xcode so far
From this we can see lots of scheme related files being created once opened by Xcode inside .xcodeproj
so xcodebuild creates .app by using the scheme related meta data but as there is no scheme to build against its failing
How to solve this ?
As there is lack of meta data it couldn't build and so it requires Xcode to be opened so that the files get automactically created by Xcode and so there will be some schemes to build against.
But when you open the Xcode this Scheme related files gets created under xcuserdata which is for particular user. i.e each user gets their own file that saves state folders opened,last file opened etc...
Its not wise idea to keep this file with us.
The problem can be solved by checking the Shared Check box under Manage Schemes
This moves schemes out from under your individual xcuserdata into a shared folder that can be committed via source control and you can safely ignore xcuserdata and keep the shared folder in source control
Now we can build the code without opening the Xcode even for only one time.
Branding
(UI,Build settings and functional)
UI
App icon & other icons
iTunes Artwork
Build settings
App Name
Bundle Identifier
Provisioning profile
Code signing identity
Functional
Brand specific URLs(login,logout,resource-fetch etc...)
Using Terminal
Branding.sh
#Author: Durai Amuthan(h.duraiamuthan#gmail.com)
#This is to achieve multiple branding of an iOS app by configuring the variables below
#************ Configuring the brand starts ************
#Directory path where .xcworkspace or .xcodeproj exists
PathOfProjectDirectory=/Users/Shared/Jenkins/Documents/JenkinsTestNuu/New/
#Path where info.plist exists
PathOfInfoPlist=$PathOfProjectDirectory/XxYyZz
#Path to icons where new iTunesArtwork and application icon exixts
#Note: Make sure proper naming conventions of file has been followed
PathOfNewIcons=/Users/Shared/Jenkins/Documents/icons-two
#Path to asset resource where you have kept your application icon.
PathOfAppIconSet=$PathOfProjectDirectory/XxYyZz/Icon.xcassets/AppIcon.appiconset
#Path where do you want the .app file has to be kept
PathToApp=/Users/Shared/Jenkins/Documents/JenkinsTestNuu/app
#Path where do you want the .ipa file has to kept
PathToIpa=/Users/Shared/Jenkins/Documents/JenkinsTestNuu/ipa
#Cocoapods project or project that involves more than one modules are scheme based
isWorkspaceBased=true
#Path of the Project (.xcodeproj) - applicable for workspace(.xcworkspace) based project
PathofProjectFile=$PathOfProjectDirectory/XxYyZz.xcodeproj
#Path of the Workspace (.xcworkspace)
PathofWorkspaceFile=$PathOfProjectDirectory/XxYyZz.xcworkspace
#Name of the target - applicable only for non-workspace(.xcodeproj) based projects
Target=XxYyZz
#Scheme of the iOS app
Scheme=XxYyZz
#To ascertain Cocoapods has been used or not
isCocoaPodsBased=true
#Configuration of the app (Debug -(Development) or Release(Adhoc or Distribution))
Config=Release
#For giving access to signing idetity found in KeyChain
LoginKeychainPath=/Users/Shared/Jenkins/Library/Keychains/login.keychain
LoginKeyChainPassword=xxyyzz
#Name of the code signing identity.You can find the name in Keychain or xcode build setting
CodeSigningIdentity='iPhone Distribution: Xx Yy Zz Limited (3Z5MHUYJ2L)'
#Path of the provisioning profile
PathToMobileProvision=/Users/Shared/Jenkins/Desktop/BrandingTest.mobileprovision
#UUID value found inside Provisioning profile has to be given
#Do not forget to install provisiong profile in the system
ProvisioningProfileIdentity=6e6506e9-8233-4886-9084-zf21e8f8bbae
#Bundle identifier of the app
BundleIdentifier=com.xxyy.zz
#AppVersion of the app
AppVersion=2.2.2
#App Name
Appname=Two
#************ Configuring the brand ends ************
#** Creatting the build based on configuration starts **
cd $PathOfInfoPlist
echo "****************** Setting App Name ******************"
/usr/libexec/PlistBuddy -c "Set :CFBundleName $Appname" info.plist
/usr/libexec/PlistBuddy -c "Set :CFBundleDisplayName $Appname" info.plist
echo "app name has been set as $Appname"
cd $PathOfProjectDirectory
echo "****************** Setting AppVersion ******************"
/usr/bin/agvtool new-marketing-AppVersion $AppVersion
/usr/bin/agvtool new-AppVersion -all $AppVersion
echo "****************** Changing app icons & iTunes Artwork ******************"
cp -R $PathOfNewIcons/*.png $PathOfAppIconSet
echo "App icons has been changed at $PathOfNewIcons"
cp -R $PathOfNewIcons/iTunesArtwork#2x $PathOfProjectDirectory/XxYyZz
cp -R $PathOfNewIcons/iTunesArtwork $PathOfProjectDirectory/XxYyZz
echo "iTunesArtwork has been changed at $PathOfProjectDirectory"
#Unlock login keychain
security unlock-keychain -p $LoginKeyChainPassword $LoginKeychainPath
if $isCocoaPodsBased == 'true'
then
echo "****************** Installing Cocoapods **********************"
/usr/local/bin/pod install
echo "Cocoapods has been installed"
fi
echo "****************** Creating .app ******************"
if $isWorkspaceBased == 'true'
then
/usr/bin/xcodebuild -scheme $Scheme -workspace $PathofWorkspaceFile -configuration $Config clean build CONFIGURATION_BUILD_DIR=$PathToApp "CODE_SIGN_IDENTITY=$CodeSigningIdentity" "PRODUCT_BUNDLE_IDENTIFIER=$BundleIdentifier" "PROVISIONING_PROFILE=$ProvisioningProfileIdentity"
else
/usr/bin/xcodebuild -target $Target -project $PathofProjectFile -configuration $Config clean build CONFIGURATION_BUILD_DIR=$PathToApp "CODE_SIGN_IDENTITY=$CodeSigningIdentity" "PRODUCT_BUNDLE_IDENTIFIER=$BundleIdentifier" "PROVISIONING_PROFILE=$ProvisioningProfileIdentity"
fi
echo ".app has been generated at $PathToApp"
echo "****************** Creating .ipa *******************"
/usr/bin/xcrun -sdk iphoneos PackageApplication -v $PathToApp/XxYyZz.app -o $PathToIpa/$Appname.ipa --embed $PathToMobileProvision --sign "$CodeSigningIdentity"
echo "$Appname.ipa has been generated at $PathToIpa"
#** Creatting the build based on configuration ends **
The file is self-descriptive you can understand easily.
Just configure the values of variable in the file and call it like below
sh Branding.sh
FYI:
If you want some other icons also to be changed besides App Icon and iTunesArtwork
use cp command e.g
cp path/to/source path/to/destination
To know more info do cp man
With the above file you can do Branding for UI and Build Settings.
For functional branding , you have to keep
Brand specific URLs
Other inputs respective to a brand
in a separate plist file so that this things also can be changed according to respective brand while building the app
In coding side you can customise your application to read the values from plist like this
Function defintion:
func getPlistFile()->Dictionary<String,AnyObject>? {
var dictPlistFile:Dictionary<String,AnyObject>?
if let path = NSBundle.mainBundle().pathForResource("plistfile", ofType: "plist") {
if let dictValue = NSDictionary(contentsOfFile: path) as? Dictionary<String, AnyObject> {
dictPlistFile=dictValue
}
}
return dictPlistFile
}
Function calling:
var Value=getPlistFile()?["Key"]
You can change the values of the key according to brand using the PlistBuddy while building the app
Here is the syntax
/usr/libexec/PlistBuddy -c "Set :Key Value" plistfile.plist
Using Jenkins
We can effectively re-use the shell script here in jenkins
1.You have to parameterise all the variables in shell script in jenkins using Add Parameter... like in the below screenshot I have done for one variable like that you have to do it for all others
2.Choose Execute shell in the Build Step
3.Copy the script that is there in between Creating the build based on configuration starts and Creating the build based on configuration ends and paste it in Execute Shell
Note:
Resource Rules
There is a known bug Regarding ResourceRules of Xcode in some versions while building and packaging the app through non-xcode interface.
So it has to be run once to deactivate a validation for resource rules path in xcode.The resource rules path is deprecated feature and apple doesn't accept apps that comes with resource rules but if we build an app without using Xcode the validation error saying resource rules has not been found will arise to counter that we have to run the script only once.
xcode_fix_PackageApplicationResourceRules.sh
#!/bin/sh
# A script to patch xcrun PackageInstallation so that it doesn't use the deprecated --resource-rules
# See "Do not use the --resource-rules flag or ResourceRules.plist. They have been obsoleted and will be rejected."
# under https://developer.apple.com/library/mac/technotes/tn2206/_index.html#//apple_ref/doc/uid/DTS40007919-CH1-TNTAG205
# Reported as Apple bug #19384243
#
# should be run as a user who can modify the PackageApplication file
xcodedir=$1
function usage {
# FIXME we cannot parse args properly because 2 are optional...
echo "USAGE: $0 xcodedir"
echo " xcodedir: an install dir like /Application/Xcode6.1.1.app"
}
if [[ $# -ne 1 ]]; then
echo "ERROR: invalid number of arguments"
usage
exit -1
fi
pi="$xcodedir/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/PackageApplication"
piorig="$piOrig"
if [[ ! -f "$pi" ]]; then
echo "$pi file not found. Invalid argument ?"
usage
exit -1
fi
grep resource-rules "$pi"
if [[ $? -ne 0 ]]; then
echo "PackageApplication doesn't use resource-rules. Skipping"
exit 0
fi
if [[ -f "$piorig" ]]; then
echo "Backup file $piorig already exist. Aborting"
exit -1
fi
perl -p -i'Orig' -e 'BEGIN{undef $/;} s/,resource-rules(.*sign}).*ResourceRules.plist"/$1/smg' "$pi"
echo $?
Unlock keychain
Whenever you run Branding.sh in terminal it will prompt username and password as its accessing system keychain
Whenever you run the Job in jenkins you will get "User Interaction Is Not Allowed" error
so to tackle this you have to follow the below steps
Open the Keychain Access
Right click on the private key
Select "Get Info"
Select "Access Control" tab
Click "Allow all applications to access this item"
Click "Save Changes"
Enter your password
Provisioning profile
if you ever get "No Matching Provisioning Profile Found" make sure you have double clicked and installed it via Xcode.
The moment you install you'll see UUID.mobileprovision in ~/Library/MobileDevice/Provisioning Profiles/
This UUID is the value inside mobile provision that means the provisioning profile is installed.
I hope this helps you
You need to run pod install before building the project so that CocoaPods fetches the Pods specified in your Podfile within the Jenkins workspace.

How to use cocoapods integrated project with OCLint?

I can build the project and generate OCLint report on a project without cocoapods but when integrated with cocoapods the build for project is successful but the build for OCLint results into errors for the file which are present into cocoapods and build fails.
So how to make build successful for cocoapods with OCLint?
Any help would be appreciated.
Below is the script I am using to generate html file for cocoapods integrated project with OCLint.
OCLINT_HOME is the path for oclint downloaded folder. I have renamed the folder to oclintrelease.
OCLINT_HOME=/Users/Dheeraj/Downloads/oclintrelease
export PATH=$OCLINT_HOME/bin:$PATH
hash oclint &> /dev/null
if [ $? -eq 1 ]; then
echo >&2 "oclint not found, analyzing stopped"
exit 1
fi
cd ${TARGET_TEMP_DIR}
if [ ! -f compile_commands.json ]; then
echo "[*] compile_commands.json not found, possibly clean was performed"
echo "Workspace Path : ${MY_WORKSPACE}"
echo "[*] starting xcodebuild to rebuild the project.."
# clean previous output
if [ -f xcodebuild.log ]; then
rm xcodebuild.log
echo "Oclint Clean performed"
fi
cd ${SRCROOT}
xcodebuild clean
#build xcodebuild.log
xcodebuild ONLY_ACTIVE_ARCH=NO -workspace ${PROJECT_NAME}.xcworkspace -scheme ${PROJECT_NAME} -configuration Debug clean build| tee ${TARGET_TEMP_DIR}/xcodebuild.log
#xcodebuild <options>| tee ${TARGET_TEMP_DIR}/xcodebuild.log
echo "[*] transforming xcodebuild.log into compile_commands.json..."
cd ${TARGET_TEMP_DIR}
#transform it into compile_commands.json
oclint-xcodebuild
fi
echo "[*] starting analyzing"
cd ${TARGET_TEMP_DIR}
oclint-json-compilation-database -e /Users/Dheeraj/Desktop/sampleCocoaPods/Pods/ -v oclint_args "-report-type html -o /Users/Dheeraj/NewHTMLREPORT.html" | sed 's/\(.*\.\m\{1,2\}:[0-9]*:[0-9]*:\)/\1 warning:/'
It will exclude all the Pods related files.
If you want to include Pods file as well then replace last line in script by :
oclint-json-compilation-database -v oclint_args "-report-type html -o /Users/Dheeraj/NewHTMLREPORT.html" | sed 's/\(.*\.\m\{1,2\}:[0-9]*:[0-9]*:\)/\1 warning:/'
Notes :
Please try first with a short sample Application including cocoapods and once you have generated report for sample application then integrate script into your real application as building with OCLint takes a lot of time to generate the report.
Always clean application and then build with OCLint.
Link for reference

How to symbolicate crash logs using the .xcarchive file?

I am having issues extracting the dsym file from .xcarchive to symbolicate crash logs. I understand that .xcarchive contains both the .app files and .dsym files. Normally you should be able to right click on the xcarchive file and selecct "Show Package Contents" (link). However "Show Package Contents" does not show up for me.
I also attempted to symbolicate the crash logs manually by using symbolicatecrash and giving it the xcarchive file (link). However it would still return crash logs that were not symbolicated.
Would anyone know what could be going on here? Any help is appreciated, Thank you!
I have prepared a script which takes two parameters,
MyApp.crash
MyApp.xcarchive
And gracefully output the MyApp_symbolicated.crash
Scripts:
#!/bin/bash
if [ "$#" -ne 2 ]; then
echo "Argument missing [symbolicate #logLocation #xcarchiveLocation]"
exit 0
fi
if test -e "$1"; then
echo "$1 exists"
else
echo "$1 does not exist!"
exit 1
fi
if test -e "$2"; then
echo "$2 exists"
else
echo "$2 does not exist!"
exit 1
fi
parentdir=`pwd`
export DEVELOPER_DIR=`xcode-select -p`
PATH=$PATH:$DEVELOPER_DIR
echo $PATH
cd $DEVELOPER_DIR
cd ../SharedFrameworks/
commanddir=`pwd`
command=$commanddir/`find . -name symbolicatecrash`
cd $parentdir
crashlog="$1"
archive="$2"
outputdir=`dirname "$crashlog"`
nfile=$(echo $1 | rev | cut -f 2- -d '.' | rev)
outputfile="$nfile"_symbolicated.crash
echo $nfile
desymfile="$archive"/dSYMs/*.dSYM
$command -v "$crashlog" "$desymfile" > "$outputfile"
How to use:
create a file symbolicate in /usr/local/bin/
Put the above code in symbolicate file
set execute permission with chmod 777 symbolicate
Run from wherever in your location with proper params
output will be generated in same directory of crash file.
Plug an iOS Device into the Machine that contains the archive in the designated archives folder.
Open the devices window in Xcode.
Open device logs.
Drag an drop your crash report into the list of logs of the device. Wait until it gets resymbolicated.

Resources