Ruby Xcodeproj: Add file to non-group folder - ruby

I am trying to add the Google-Service.json (for Google Social Login) to my Xcode Project. As the project is build in a CI machine I cannot do it through Xcode.
I used Cocoapod's Xcodeproj package in order to help me add the json to my Xcode proj. The Runner folder seen below is not a group folder as Fluter or Products. With my created script I only achieve for the file to be added to the root of the project as seen in the picture. Can anyone tell me what to change so the project gets inside the Runner folder (as requested from Google_sign_in flutter plugin)
Here is my script:
require "xcodeproj"
project_path = "Runner.xcodeproj"
project = Xcodeproj::Project.open(project_path)
file = project.new_file("Google.json", "Runner")
main_target = project.targets.first
main_target.add_resources([file])
project.save
Thanks for any inputs

Don't know if it is still relevant. BUT i stumbled upon the same issue.
You need to add them inside the project root with ruby's FileUtils first.
FileUtils.cp(File.path(config_path), 'Runner')
I made a GitHub Gist with the whole script. With an example of my Run script also.

Related

Unable to create a new module (module already exists) Intellij

I am trying to create a new module in my project. As soon as I specify the name of the module, Intellij throws "That this module already exists". After I exit the wizard it creates a directory with same module name but doesn't make it a module. I delete the directory and I perform "Invalidate Caches and Restart" but still the error persists.
I had this issue and went to .idea/modules.xml, found the path with the name I wanted, and deleted that line (just did ctrl+f with the name). After deleting that line and saving the file, I was able to create the module with that name.
You can try to perform the following actions:
Close the IDE and manually remove the module.
Remove .idea folder.
Open IDE and reimport the project.
Try adding the module once again according to official guide.
If the problem remains contact JetBrains support and attach a compressed log folder along with the project structure tree.
I had the same problem when I moved the code to a different directory. Detaching the workspaces, removing .idea, invalidating caches and so on did not help then.
For me what helped was this: Go to File -> Settings -> Project: workspace -> Project Structure. There you will see the all the projects you ever opened. And you will also see a button Add Content Root. There you can specify the new location of the (old) project.
It is a caching issue .
So try something on those lines
Invalidate cache and restart worked for me
But in case it doesn't you can try manually deleting .idea files or re-importing the project .
If you are using Gradle and this is a multi-project layout, which is looks like it is, you shouldn't create modules directly in IntelliJ.
Rather, create the directory manually if it doesn't already exists, create a gradle.build[.kts] file in it if needed, and then add an import statement for it in settings.gradle[.kts]. Then just refresh the Gradle configuration in IntelliJ ("Reimport All Gradle Projects").
I've started the project on Linux with root account and then this problem appeared when I've switched to user account.
For me changing the ownership of files in project directory worked.
sudo chown -R your_username:your_user_group project_directory
When this issue happens during import of existing project, then
--close intellij ide
--delete the project in explorer
--clone it again
--open intellij ide
--and try to reimport

Xamarin.UITest AppCenter Cannot find test-cloud.exe

I have created Xamarin.UITest that can run locally on my desktop. My goal is to execute these test as a part of a post-build script to run UITest after the app has built as mentioned in this article below:
https://tomsoderling.github.io/AppCenter-Automated-UI-tests-on-build/
Below is my script
appcenter test run uitest --app "MY-APP" --devices 168683d9 --app-path $APPCENTER_OUTPUT_DIRECTORY/MyApp.Mobile.Droid.apk --test-series "myapp-mobile-test" --locale "en_US" --build-dir $APPCENTER_SOURCE_DIRECTORY/MyApp.Mobile.UITests/bin/Release --token MY-TOKEN --uitest-tools-dir $APPCENTER_SOURCE_DIRECTORY/packages/Xamarin.UITest.*/tools
When the script above is apart of my appcenter post build script, I get the following error:
Error: Cannot find test-cloud.exe, the path specified by "--uitest-tools-dir" was not found.
Please check that "/Users/vsts/agent/2.141.1/work/1/s/packages/Xamarin.UITest.2.2.6/tools" is a valid directory and contains test-cloud.exe.
Minimum required version is "2.2.0".
I think a lot of people are having trouble dealing with this actually and I know it has something to do with --uitest-tools-dir OR --build-dir variables.
Keep in mind this I am first trying to do this with Xamarin.Android, if successful I will try the Xamarin.iOS
One clue i do see is when Tom says "I had to chose to build the app solution file in my App Center CI build - not simply the iOS project like I normally would" in the noted article, but I am not quite sure how to do that or if is connected to why AppCenter cannot locate my test-cloud.exe I will also say that test-cloud.exe somehow comes from the Xamarin.UITest nuget, but I do not see any test-cloud.exe file in my Xamarin.Forms project.
This answer works, but it's pretty fragile.
The test-cloud.exe can't be located at packages/Xamarin.UITest.2.X.X/tools in projects that uses the old project structure (projects that use packages.config). For new projects (new .csproj formats), there is no such file in the path of the project. The only way I found to make it work on AppCenter is to use it from the NuGet package cache (/Users/vsts/.nuget/packages/xamarin.uitest/2.X.X)
Kudos to AppCenter Agents for helping me to resolve this. 2 things were required as indicated below:
Agent Anvesh says
Hi there, Thanks for the details, So seems like you are using a nuget as a PackageReference in your project(this means that there will be no package folder in your project, packages will be there at user profile).
So when you are trying to run the test as part of the app center build. Then in the shell script used the --uitest-tools-dir value as below
/Users/vsts/.nuget/packages/xamarin.uitest/2.2.6/lib/tools
So I modified my above script to add the below:
--uitest-tools-dir /Users/vsts/.nuget/packages/xamarin.uitest/2.2.6/tools \
Agent Shawn says
So I added the below
msbuild $APPCENTER_SOURCE_DIRECTORY/MyApp.Mobile.UITestProject.csproj

Xcode: add files to project in a build phase

In my Xcode project I have a custom build phase which runs a script and downloads some images for use by the app. What I want to do is to automatically add those image to the project during the build. Right now, I have to build once (which downloads the files), and then manually add those files to the project. It works as long as the file names don't change. Instead, I'd like to add all the files in a specific directory to the project.
I've tried setting the Output Files value, as suggested here, like this:
$(PROJECT_DIR)/$(PROJECT_NAME)/External Assets/*
but it doesn't work. Any idea if this can be done?
Create a directory with the .bundle extension. Add this bundle to your app's resources. When the project builds, it will automatically copy every file in the bundle, even if they are changed or added after you first add the bundle to the project.

How to bundle an openframeworks application in xcode (relative resource linking?)

An trying to get openframeworks to build me my application so that i can open it from anywhere and it will load the needed images from within the apps Resources folder.
I believe this is relative linking?
I have done it before, on an older xcode and oF 61.
To do this i dragged the needed images into the project file on the left and added it to the executable target, with in a 'build phase' -> 'copy files'.
Been trying all sorts of methods, ofSetDataPathRoot() which solved the problem last time isnt working for me this time.
Any ideas/help would be appreciated!
Thanks
First you need to tell xCode to copy your /bin/data directory into your application bundle by adding a build phase:
1. Click on your project in the Project Navigator
2. Select "Build Phases"
3. Toggle open the "Run Script" section and paste in the following:
cp -r bin/data "$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/Resources";
Then tell your app where to find the data folder relative to itself within the bundle.
Inside the setup method of your oF app:
ofSetDataPathRoot("../Resources/data/");
ofSetDataPathRoot() should solve this problem. Perhaps you are setting the replacement root path incorrectly?
Try calling ofToDataPath() yourself on a string path and print out the result, then use Terminal and cd inside the .app bundle to check if the path sounds correct. Paths are expressed relative to the location of the actual executable inside the .app bundle, so if the executable is at myApp.app/Contents/MacOS/myApp and the data files are at myApp.app/Contents/Resources then ofToDataPath( "texture.png" ) should return something like ../Resources/texture.png.
You can double-check the current working directory (myApp.app/Contents/MacOS in my example) by calling getcwd(), open up a terminal and type man getcwd for more info on that.
oF now sets data path root and does internal calls to ofToDataPath() by default. What version are you using?
Have you looked inside the product's package contents to make sure your resources are getting copies in the proper build phase?

How to compile a project with app and library in the same workspace with different configuration names?

I am developing an app and I am using an open source component.
I have a workspace containing both MyApp.xcodeproj and Component.xcodeproj. My app has three configurations: Debug, App Store and In House but the component has only two: Debug and Release
In the Debug configuration, everything works fine, but I can't compile my app in App Store or In House configuration because the configuration names do not match. I get a file not found error when trying to #import <Component/Component.h>
I need both App Store and In House configurations and I would really like to avoid modifying the component's configurations in order to ease future updates of the component.
I know I could use CocoaPods to solve this issue but I would like to know if there is a simple solution in Xcode
You can get your project to compile with some tweaks to your app’s settings.
I suggest you to modify all settings at the project level so that all your targets can inherit these settings.
Add a new DEFAULT_CONFIGURATION user-defined setting and define your configuration mapping. This is how it should look like:
Set FRAMEWORK_SEARCH_PATHS to $(BUILD_DIR)/$(DEFAULT_CONFIGURATION)-$(PLATFORM_NAME) for all configurations, add Any OS X SDK variants and set the value to $(BUILD_DIR)/$(DEFAULT_CONFIGURATION). Set HEADER_SEARCH_PATHS to $(FRAMEWORK_SEARCH_PATHS)/include and LIBRARY_SEARCH_PATHS to $(FRAMEWORK_SEARCH_PATHS). This is how it should look like:
This step is quite tedious, it can be automated with the xcproj tool and by running this script in your project directory. Edit your configurations mapping as needed.
#!/bin/bash
CONFIGURATIONS=( "App Store:Release" "In House:Release" "Debug:Debug" )
for CONFIGURATION in "${CONFIGURATIONS[#]}"; do
xcproj --configuration "${CONFIGURATION%%:*}" write-build-setting DEFAULT_CONFIGURATION "${CONFIGURATION#*:}"
done
xcproj write-build-setting 'FRAMEWORK_SEARCH_PATHS' '$(BUILD_DIR)/$(DEFAULT_CONFIGURATION)-$(PLATFORM_NAME)'
xcproj write-build-setting 'FRAMEWORK_SEARCH_PATHS[sdk=macosx*]' '$(BUILD_DIR)/$(DEFAULT_CONFIGURATION)'
xcproj write-build-setting 'HEADER_SEARCH_PATHS' '$(FRAMEWORK_SEARCH_PATHS)/include'
xcproj write-build-setting 'LIBRARY_SEARCH_PATHS' '$(FRAMEWORK_SEARCH_PATHS)'
If the component is distributed as a static library, you are done here. If the component comes as a framework you have to update its path reference by editing your project.pbxproj file in a text editor. In the PBXFileReference section (under /* Begin PBXFileReference section */) find Component.framework and update its path like this:
name = Component.framework; path = "../$(DEFAULT_CONFIGURATION)/Component.framework"; sourceTree = BUILT_PRODUCTS_DIR; };
Also make sure that the sourceTree is set to BUILT_PRODUCTS_DIR, i.e. relative to built products. Once you edited the project file, this should look like:
Your project should now build as expected.
I had this same problem, but I had multiple configurations (Debug, TestFlight, Release, Enterprise) in my app, and the bolded configurations would always fail to build cause it couldn't find the frameworks. I really didn't want to mess with the project settings of my sub projects in order to make updating them easy.
The answer I found was to just update the framework search path to account for the fact that the frameworks would be dropped in Release (or whatever the default configuration is set to) of the sub projects.
Specifically I set it to:
$(BUILD_DIR)/Release-$(PLATFORM_NAME)
I set it to be recursive too. This works both for Simulator and Device, building in Xcode and command line.
I solved it in the following way,
In my dependency project,
Project -> Target -> Build Phases, added new Run Script
TARGET_DIR="Build"
TARGET_FILE="${TARGET_DIR}/${FULL_PRODUCT_NAME}"
mkdir -p ${TARGET_DIR}
rm -rf ${TARGET_FILE}
cp -rf "${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}" ${TARGET_DIR}
After the every build, I copy the build to my Build directory inside the project.
And from the main project,
Project -> Target -> General, I drag and dropped the dependency Framework (which is inside dependency project's Build folder)
then,
Project -> Target -> Build Settings -> Framework Search Paths, under my custom Build Configuration, I added the following
$(PROJECT_DIR)/../DependencyProject/Build
The folder is relative to my main project, and this should be relative to your project.
Then in my all the schemes, I added a Pre-actions script for Build with
rm -Rf "${PROJECT_DIR}/../DependencyProject/Build"
Also you need to select the app against Provide build settings from drop down.

Resources