Cocos2dx v.4 iOS - adding new files

Cocos2dx v.4 iOS - adding new files
0

I wanted to post in this topic:


but it’s already closed. I have the same problem with cocos v4 with my iOS project - when I add new resources, then no matter what I do (whether I add them as groups, or folder refs, whether I mark copy bundle resources or not, whether I manually add “copy files” to build phases), the game cannot see the files when I want to create Sprites.

So I tried the solution from the topic - running cmake … . It worked, but then the whole Info.plist file is cleared, the bundle identifier is cleared, all my settings like setting the targeted device family to universal, setting build only active architecture to no etc. need to be set up again.

What am I doing wrong?

The only thing I can think of is that I forgot to create the iosbuild folder and my xcodeproj file and others are in cocos2d dir. Unelegant, but can it be the reason?

Is there any other way to force the iOS game to see new resources? Or to force cmake … not to reset build settings?

Can you not set these build settings in CMakeLists.txt?

set(DEVELOPMENT_PROJECT_NAME "project")                     # <== Set to your project name, e.g. project.xcodeproj
set(DEVELOPMENT_TEAM_ID "AAAAAAAAAA")                       # <== Set to your team ID from Apple
set(APP_NAME "YOURAPP")                                     # <== Set To your app's name
set(APP_BUNDLE_IDENTIFIER "com.company.app")                # <== Set to your app's bundle identifier
set(FRAMEWORK_NAME "FooBar")                                # <== Set to your framework's name
set(FRAMEWORK_BUNDLE_IDENTIFIER "com.company.framework")    # <== Set to your framework's bundle identifier (cannot be the same as app bundle identifier)
set(TEST_NAME "Tests")                                      # <== Set to your test's name
set(TEST_BUNDLE_IDENTIFIER "com.company.tests")             # <== Set to your tests's bundle ID
set(CODE_SIGN_IDENTITY "iPhone Developer")                  # <== Set to your preferred code sign identity, to see list:
                                                            # /usr/bin/env xcrun security find-identity -v -p codesigning
set(DEPLOYMENT_TARGET 8.0)                                  # <== Set your deployment target version of iOS
set(DEVICE_FAMILY "1")                                      # <== Set to "1" to target iPhone, set to "2" to target iPad, set to "1,2" to target both
set(LOGIC_ONLY_TESTS 0)                                     # <== Set to 1 if you do not want tests to be hosted by the application, speeds up pure logic tests but you can not run them on real devices
1 Like

It just occurred to me that I could try it :). I’m totally inexperienced in cmake. I guess handling v4 will make me more experienced :D. Thank you! I’ll let you know if I was able to add everything.

Right. I’m almost there. I’ve managed to set the device families and build only active arch to what I wanted. Here’s a link to Apple’s doc about exact Xcode variable names, if anyone needs it. https://help.apple.com/xcode/mac/8.0/#/itcaec37c2a6

The only remaining weird thing is that the plist file still gets re-generated as totally clean after running cmake and added to the project, even though the plist variable theoretically is set to an existing plist file.

Relevant excerpts from the CMakeLists.txt file, if anyone needs it:

if(XCODE)
  if(NOT DEFINED CMAKE_XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET)
      SET (CMAKE_XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET 10.0)
  endif()
  SET (CMAKE_XCODE_ATTRIBUTE_PRODUCT_NAME "App Name")                                     
  SET (CMAKE_XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "com.company.app")                
  SET (CMAKE_XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY 1,2)                                      
  SET (CMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH OFF)
endif()

(…)

set_xcode_property(${APP_NAME} INFOPLIST_FILE "${CMAKE_CURRENT_SOURCE_DIR}/proj.ios_mac/ios/Info.plist")
set_xcode_property(${APP_NAME} ASSETCATALOG_COMPILER_APPICON_NAME "AppIcon")
set_xcode_property(${APP_NAME} DEVELOPMENT_TEAM "A1A1A1A1A")

Will keep fighting tomorrow.

not sure if this is still used for v4 but seems to be in the test projects,

have you checked if you have this property set (MACOSX_BUNDLE_INFO_PLIST )

set_target_properties(${APP_NAME} PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/proj.ios/Info.plist")

I remember having similar issues in 3.17.x with the cocos_pak_xcode macro, which isn’t used anymore

1 Like

How are you editing info.plist?

This file is outside the generated projects by cmake, it should not be overwritten by cmake.
I have however noticed something strange. If I open the file from xcode, by going to Resources/info.plist (this isn’t the real path, its a references generated by xcode) and edit it my changes won’t be detected by git.
However If I open info.plist from finder going to the real path in proj.ios_mac/ios/info.plist and edit it then git will detect the changes and I can commit to share with my team.

Thanks a lot, this line indeed was missing, adding it worked! The only thing remaining to solve is that the Bundle Name and Executable File properties in the plist disappeared in the process :open_mouth: :smiley: .

My guess is that the Resources group references a copy of the file, placed under proj.ios_mac/CMakeFiles/MyProjectName.dir/ (at least this is my case). This file seems to get re-generated upon each build by the way. The one that you have added to your repo is probably the template file that gets copied.

hmm maybe it’s the wrong way to do it then, not sure.
https://cmake.org/cmake/help/v3.17/prop_tgt/MACOSX_BUNDLE_INFO_PLIST.html
mby this helps, it’s possible to define the bundle name etc with this, but seems like you’d use this together with an template.
(this was the way how they did it in 3.17.1, so probably v4 will use it differently)

have you checked the test examples? they did some bugfixes in january for the CFBundleExecutable


" [bugfix] set CFBundleExectuable in template info.plist (#20425)"

1 Like

@Sleicreider

Oh my, you are so helpful. The link to the bug fix diff totally saved my bony arse.

Thank you guys, now everything’s solved! (or so it seems).

To sum up all these cmake-newbie experiences, in v.4.:

  1. To add a resource file to the project, instead of adding it directly to Xcode, just put it in the res folder and re-run cmake.

  2. If you change any build settings in Xcode, like targeted device family, you will have to include them in the CMakeLists.txt in order not to lose them upon re-running cmake.

  3. If you change anything in the plist file, make sure you do it with the “template” file (the one under proj.ios_mac/ios). The one referenced by the Resources group in Xcode might not be the right one and will get rewritten upon next build. Probably you will also have to rerun cmake in order for these changes to take effect.

  4. Watch out for the plist file itself. Make sure the right file is being copied, the right variable is being set (in CMakeLists.txt) and that the Info.plist file itself is well-configured, in particular these properties:

     <key>CFBundleExecutable</key>
     <string>${MACOSX_BUNDLE_EXECUTABLE_NAME}</string>
     <key>CFBundleIdentifier</key>
     <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
     <key>CFBundleName</key>
     <string>${PROJECT_NAME}</string>
    

Here are relevant portions of my final CMakeLists.txt, in case anyone needs some reference:

if(XCODE)
    if(NOT DEFINED CMAKE_XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET)
        SET (CMAKE_XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET 10.0)
    endif()
    SET (CMAKE_XCODE_ATTRIBUTE_PRODUCT_NAME “My “App Name)  
   # SET (CMAKE_XCODE_ATTRIBUTE_EXECUTABLE_NAME “My”ProjectName)                                     
    SET (CMAKE_XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER “my.bundle.identifier”)                
    SET (CMAKE_XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY 1,2)                                      
    SET (CMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH OFF)
    
endif()

(…)

    if(APPLE)
        set_target_properties(${APP_NAME} PROPERTIES RESOURCE "${APP_UI_RES}")
   
        if(IOS)
 #the line below is relevant for the Info.plist file
            set_target_properties(${APP_NAME} PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/proj.ios_mac/iOS/Info.plist")
            set_xcode_property(${APP_NAME} ASSETCATALOG_COMPILER_APPICON_NAME "AppIcon")
        endif()

    # For code-signing, set the DEVELOPMENT_TEAM:
    set_xcode_property(${APP_NAME} DEVELOPMENT_TEAM "6FS6P34PDK")

endif()

Disclaimer: I haven’t checked everything against potential sneaky bugs.
Hope posting my own solution post is not a faux pas :D.

2 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.