iOS - watchOS App publishing issue CFBundleIdentifier collision

Deadly 提交于 2019-12-03 12:16:13

As a temporary workaround I have manually renamed the bundle identifier in the watchOS extension then the app publishing is working fine but it does not look like a nice solution, especially if you are running the build on a CI system.

A better option is to add a specific post install operation in pod file:

post_install do |installer|
 installer.pods_project.targets.each do |target|
  if target.name == 'CocoaLumberjack-watchOS'
   target.build_configurations.each do |config|       
    config.build_settings['PRODUCT_BUNDLE_IDENTIFIER'] = 'org.cocoapods.${PRODUCT_NAME:rfc1034identifier}-$(PLATFORM_NAME)'
   end
  end
 end
end

or if you have to handle multiple libraries:

post_install do |installer|
 watchosLibs = ['Lib1-watchOS', 'Lib2-watchOS', 'Lib3-watchOS']
 installer.pods_project.targets.each do |target|
  if watchosLibs.include? target.name
   target.build_configurations.each do |config|
    config.build_settings['PRODUCT_BUNDLE_IDENTIFIER'] = "org.cocoapods.${PRODUCT_NAME:rfc1034identifier}.${PLATFORM_NAME}"
   end
  end
 end
end

Pay attention to rename pods bundle identifier because some libraries don't behave correctly otherwise.

I suggest to rename only the libraries rejected by Apple in order to minimize the possible issues.

Currently there are some different open threads about this issue:

A similar issue is present also using Carthage instead of Cocoapods

If Apple will not change this new policy about bundle identifier then a more clean solution will probably come from cocoapods team.

Apparently Apple changed the validation process. It looks like they don't allow to platform specific frameworks within an app to have the same identifier.

There's a post on the forum about this as well: https://forums.developer.apple.com/thread/122048

If you're running into this issue because you're using Cocoapods you could patch your Podfile to append the Platform Name to the bundle identifier so that they'll be always unique (source):

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['PRODUCT_BUNDLE_IDENTIFIER'] = 'org.cocoapods.${PRODUCT_NAME:rfc1034identifier}-$(PLATFORM_NAME)'
    end
  end
end

If you have multiple targets in your app you can change the watchOS targets in your scheme in XCode and append .watchos to the identifier as well.

You don't need to change every target, its cleaner to write something like this:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    if target.platform_name == :watchos
      target.build_configurations.each do |config|
        config.build_settings['PRODUCT_BUNDLE_IDENTIFIER'] = 'org.cocoapods.${PRODUCT_NAME:rfc1034identifier}-$(PLATFORM_NAME)'
      end
    end
  end
end

Here is how I've worked around the problem for Carthage.

1) create a Carthage build script that separates out the different Carthage build phases

2) when you do the actual framework builds; first build the problem frameworks for iOS (I only had one), then modify your project files to change the bundle identifier, then build those frameworks for watchOS, then build the rest of your frameworks

carthage bootstrap --no-checkout
carthage checkout
#undo previous CFBundleIdentifier changes
sed -i '' 's/com.someco.MyFramework.watchOS;/com.someco.MyFramework;/g' Carthage/Checkouts/MyFramework/MyFramework.xcodeproj/project.pbxproj
carthage build --cache-builds --platform iOS
#set a unique CFBundleIdentifier
sed -i '' 's/com.someco.MyFramework;/com.someco.MyFramework.watchOS;/g' Carthage/Checkouts/MyFramework/MyFramework.xcodeproj/project.pbxproj
carthage build --no-use-binaries --platform watchOS --configuration $CONF $VERBOSE MyFramework

One option is - you can add ".watchos"(abc.asd.alomofire.watchos) to the watch bundle identifier manually.

Just remove the embed frameworks build phase from your extension.

Click on extension in target section -> Build phases -> remove the embed pods frameworks

See attached picture:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!