Is resource copying for mac broken?

I have started with a v3.9 template generated project, and was able to see the hello world example when running cocos run -p mac. I was going through the documentation and wanted to start with adding sprites, so I added a pair of plist and png files to ./Resources and added the following four lines of code to the end of HellowWorld::init():

auto shadowSpriteCache = SpriteFrameCache::getInstance();
shadowSpriteCache->addSpriteFramesWithFile("shadow.plist");
auto shadowSprite = Sprite::createWithSpriteFrameName("standing.png");
this->addChild(shadowSprite, 1);

Here is a directory list of the files in Resources:

ls
CMakeLists.txt		MyGame.xcworkspace	bin			proj.android		proj.ios_mac		proj.win10		proj.win8.1-universal
Classes			Resources		cocos2d			proj.android-studio	proj.linux		proj.win32
Adams-MacBook-Pro:MyGame adam$ ls -l Resources/
total 120
-rw-r--r--  1 adam  staff   3596 Nov 30 13:12 CloseNormal.png
-rw-r--r--  1 adam  staff   2810 Nov 30 13:12 CloseSelected.png
-rw-r--r--  1 adam  staff  37864 Nov 30 13:12 HelloWorld.png
drwxr-xr-x  4 adam  staff    136 Nov 30 13:12 fonts
drwxr-xr-x  3 adam  staff    102 Nov 30 13:12 res
-rw-r--r--  1 adam  staff   6720 Nov 30 10:39 shadow.plist
-rw-r--r--@ 1 adam  staff   1838 Nov 30 10:39 shadow.png

After running cocos run -p mac again, I found that the new code ran, but the new resources were not copied from MyGame/Resources to the build directory in MyGame/bin/debug/mac/MyGame-desktop.app/Contents/Resources/. So of course the app fails with:

cocos2d: fullPathForFilename: No file found at shadow.plist. Possible missing file.
cocos2d: SpriteFrameCache: can not find shadow.plist

cocos run -p mac kicks off xcodebuild referencing the xcodeproject file in proj.ios_mac, which has each resource file hard-coded. I was not planning on using Xcode and wasn’t able to figure out Xcode how/if those hard-coded references get automatically updated or not by Xcode.

In MyGame/proj.ios_mac/MyGame.xcodeproj/project.pbxproj I found references to the template HelloWorld resources, with lovely lines like so:

46880B8119C43A67006E1F66 /* HelloWorld.png in Resources */ = {isa = PBXBuildFile; fileRef = 46880B7A19C43A67006E1F66 /* HelloWorld.png */; };

Since codos run -p mac is just doing a run like so:

running: 'xcodebuild -project "/Users/adam/projects/MyGame/proj.ios_mac/MyGame.xcodeproj" -configuration Debug -target "MyGame-desktop" CONFIGURATION_BUILD_DIR="/Users/adam/projects/MyGame/bin/debug/mac"'

I know the xcodeproj file is the culprit, but I’m not sure how to update it as I add new files, or why I should have to. Any advice on this issue would be greatly appreciated!

I saw a comment by @Mazyod about using FileUtil in AppDelegate to add a search path, but it didn’t have an impact. I tried in the constructor and the beginning of applicationDidFinishLaunching. I gave it a try, but I see this as being a temporary fix to get local development working, since it still wouldn’t be in the build output.

AppDelegate::AppDelegate() {
    FileUtils::getInstance()->addSearchPath("Resources");
}

I think I am starting to remember … That comment was from more than 2 years ago, after all!

Why don’t you use the script I posted in that comment?

I saw the script you mentioned in another thread (copied below), but wasn’t sure if the project could be worked on and built without needing to manage the build with Xcode.

@
find ~~L “\${SRCROOT}/Resources” ~~type f ~~not~~name “.*” | xargs ~~t~~I {} cp {} “\${CONFIGURATION_BUILD_DIR}/\${UNLOCALIZED_RESOURCES_FOLDER_PATH}”@

The same code and cocos run -p linux on ubuntu just worked. So it looks like developing on osx is tied to Xcode, even if I just wanted to use vim and cocos run?

I’ve added a project on github that shows the minimal amount of changes for me to encounter this issue. I can run this project just fine on Ubuntu with cocos run -p linux but when I run it on mac I get:

libpng warning: iCCP: known incorrect sRGB profile
cocos2d: fullPathForFilename: No file found at shadow.plist. Possible missing file.
cocos2d: SpriteFrameCache: can not find shadow.plist
Assert failed: Invalid spriteFrameName: standing.gif

https://github.com/ab712/OsxBuildExample

I’m unfamiliar with Xcode, so I’m not sure if it’s possible to make the “xcodebuild” command kicked off by “cocos run” to just copy all /Resources. Fyi, I also tried copying the Resources manually from the /Resources directory to the built .app’s Resources folder, after it was built by cocos run and it still didn’t work.

Looks like the same issue as this:

Sounds like I will be tied to Xcode and can’t code in vim

Xcode has two ways of adding resources:

  • “Virtual Folders” (yellow ones): They are folders only in Xcode, but not in your game.
  • “References Folders” (blue ones): Real folders in your game.

I think you should use the blue ones.

You can think of the blue folders as symlinks. If you put files in the folder, when you build in Xcode, everything is pulled in. You don’t have to touch Xcode to get new assets.

yellow folders, if you add files on the file system and go look in Xcode, they are not automatically there. You have to right click and say “add files…”

The problem is:
-Even if you add the files , they will not appear in final build if they not appear in Build Phases->Copy Bundle Resources in Xcode project .
Even if add the file logically to the project, this will only add the files to bundle to active product (desktop or mobile)
You will need to add manually to Bundle in Xcode product properties.

When adding resources as folder references you just need to make sure all relevant targets are checked, this will automatically add them to the Copy Bundle Resources build phase:

Hi @almax27,

I built for iOS and everything went fine. Then I built for Android and it seems assets inside sub-folders are not copied? I am Cocos studio and there is a scene in which I added 4 images and some text label on top of those. then in code, loading that scene using CSLoader method. It works fine on iOS device.

But when I run on Android, only text labels are seen from that scene. None of image loaded (all are PNG).

If I need to make any change in default proj.android setup other than adding my CPP files in jni/Android.mk file ?

Thanks

hi,

Hopefully its helpful for everyone who is using cocos studio to create CSB scenes and loading in android.

Once we published scenes from studio, it created a sub-folder in Resources folder named res. Inside that it copies all assets which we had in our scene including CSB file. In order to organize some random assets we had a folder named assets in which some images, (which were used in scene) were stored.

Everything worked fine on iOS. But when compiled for Android, found that scene loaded but no image was displayed.

Later on discovered that FileUtils is actually having some issue with assets/ in resource path and thus images was not loaded.

So don’t use assets as any sub-folder name for your assets and it will work fine.

Thanks,