使用(Fastlane-)脚本在“目标>常规”(不是Info.plist)中更改“应用程序图标源”

时间:2019-03-21 15:59:32

标签: ios xcode fastlane

我刚刚开始使用Fastlane自动部署我们的iOS应用。我们有几个白色标签(相同的应用程序,不同的样式,内容,图标等)。

使用Fastlane,我可以在开始构建之前更改几乎所有设置(版本和内部版本号,启动屏幕文件等)。

我苦苦挣扎的是应用程序图标源。我们使用图片集(每个应用一个AppIcon-NAME.appiconset)。请参阅下图以获取设置位置的参考: enter image description here

如何使用Fastlane,任何其他自定义脚本或在构建阶段更改此属性?这似乎是xcodeproj.pbxproj中的变化,而不是Info.plist中的变化,这使得查找起来非常困难。

谢谢。

2 个答案:

答案 0 :(得分:1)

我假设您正在使用gym来构建应用,对吗?

您可以使用xcargs参数,并使用.appiconset键将路径传递到ASSETCATALOG_COMPILER_APPICON_NAME文件。

gym(
  xcargs: "ASSETCATALOG_COMPILER_APPICON_NAME=./path/to/your/icon/file"
)

您可以找到gym https://docs.typo3.org/typo3cms/extensions/fluid_styled_content/Configuration/OverridingFluidTemplates/Index.html的文档,很遗憾,ASSETCATALOG_COMPILER_APPICON_NAME构建设置没有官方文档。

答案 1 :(得分:0)

对我来说,我做了一个名为update_appicon.rb的自定义操作。

# coding: utf-8
module Fastlane
  module Actions
    class UpdateAppicon < Action
      def self.run(params)
        require 'plist'
        require 'xcodeproj'

        info_plist_key = 'INFOPLIST_FILE'
        appicon_name = 'ASSETCATALOG_COMPILER_APPICON_NAME'

        # Load .xcodeproj
        project_path = params[:xcodeproj]
        project = Xcodeproj::Project.open(project_path)

        # Fetch the build configuration objects
        configs = project.objects.select { |obj| obj.isa == 'XCBuildConfiguration'}
        UI.user_error!("Not found XCBuildConfiguration from xcodeproj") unless configs.count > 0

        configs = configs.select { |obj| obj.build_settings[info_plist_key] == params[:plist_path] }
        UI.user_error!("Xcodeproj doesn't have configuration with info plist #{params[:plist_path]}.") unless configs.count > 0

        # For each of the build configurations, set app identifier
        configs.each do |c|
          c.build_settings[appicon_name] = params[:appicon_name]
        end

        # Write changes to the file
        project.save

        UI.success("Updated #{params[:xcodeproj]} ?.")
      end

      #####################################################
      # @!group Documentation
      #####################################################

      def self.is_supported?(platform)
        [:ios].include?(platform)
      end

      def self.description
        "Update the project's bundle identifier"
      end

      def self.details
        "Update an app identifier by either setting `ASSETCATALOG_COMPILER_APPICON_NAME`."
      end

      def self.available_options
        [
          FastlaneCore::ConfigItem.new(key: :xcodeproj,
                                       env_name: "FL_UPDATE_APPICON_PROJECT_PATH",
                                       description: "Path to your Xcode project",
                                       default_value: Dir['*.xcodeproj'].first,
                                       verify_block: proc do |value|
                                         UI.user_error!("Please pass the path to the project, not the workspace") unless value.end_with?(".xcodeproj")
                                         UI.user_error!("Could not find Xcode project") unless File.exist?(value)
                                       end),
          FastlaneCore::ConfigItem.new(key: :plist_path,
                                       env_name: "FL_UPDATE_APPICON_PLIST_PATH",
                                       description: "Path to info plist, relative to your Xcode project",
                                       verify_block: proc do |value|
                                         UI.user_error!("Invalid plist file") unless value[-6..-1].casecmp(".plist").zero?
                                       end),
          FastlaneCore::ConfigItem.new(key: :appicon_name,
                                       env_name: 'FL_APPICON_ID',
                                       description: 'appicon name')
        ]
      end

      def self.authors
        ['ruman']
      end

      def self.category
        :project
      end
    end
  end

它应用于fastfile

update_appicon(
    xcodeproj: "YourProjectName.xcodeproj",
    plist_path: "Info.plist",
    appicon_name: "AppIcon#{options[:app_icon]}"
)

希望它能对您有所帮助!