2021-12-24 APP图标被覆盖问题The app ico

2021-12-24  本文已影响0人  我是小胡胡分胡

按照源代码方式集成flutter

 flutter_application_path = '../flutter_commercial'
 load File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')

 install_all_flutter_pods(flutter_application_path)

直接运行工程没问题,用脚本打包确报错:

Assets.xcassets图片资源冲突,app工程的图标被flutter插件依赖覆盖,居然是example下的图片
.ios/.symlinks/plugins/path_provider/example/ios/Runner/Assets.xcassets:./AppIcon.appiconset: warning: The app icon set name "AppIcon" is used by multiple app icon sets

打开
Pods-XXApp/Pods-XXApp-resources.sh

if [[ -n "${WRAPPER_EXTENSION}" ]] && [ "`xcrun --find actool`" ] && [ -n "${XCASSET_FILES:-}" ]
then
  # Find all other xcassets (this unfortunately includes those of path pods and other targets).
  OTHER_XCASSETS=$(find -L "$PWD" -iname "*.xcassets" -type d)
  while read line; do
    if [[ $line != "${PODS_ROOT}*" ]]; then
      XCASSET_FILES+=("$line")
    fi
  done <<<"$OTHER_XCASSETS"

  if [ -z ${ASSETCATALOG_COMPILER_APPICON_NAME+x} ]; then
    printf "%s\0" "${XCASSET_FILES[@]}" | xargs -0 xcrun actool --output-format human-readable-text --notices --warnings --platform "${PLATFORM_NAME}" --minimum-deployment-target "${!DEPLOYMENT_TARGET_SETTING_NAME}" ${TARGET_DEVICE_ARGS} --compress-pngs --compile "${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
  else
    printf "%s\0" "${XCASSET_FILES[@]}" | xargs -0 xcrun actool --output-format human-readable-text --notices --warnings --platform "${PLATFORM_NAME}" --minimum-deployment-target "${!DEPLOYMENT_TARGET_SETTING_NAME}" ${TARGET_DEVICE_ARGS} --compress-pngs --compile "${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" --app-icon "${ASSETCATALOG_COMPILER_APPICON_NAME}" --output-partial-info-plist "${TARGET_TEMP_DIR}/assetcatalog_generated_info_cocoapods.plist"
  fi
fi

这里是会扫描工程目录下面的所有.xcassets,把所有子目录下的xcassets都编译进资源了:

xargs -0 xcrun actool 
--output-format human-readable-text 
--notices --warnings 
--platform "${PLATFORM_NAME}" 
--minimum-deployment-target "${!DEPLOYMENT_TARGET_SETTING_NAME}" 
${TARGET_DEVICE_ARGS} 
--compress-pngs 
--compile "${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 
--app-icon "${ASSETCATALOG_COMPILER_APPICON_NAME}" 
--output-partial-info-plist 
"${TARGET_TEMP_DIR}/assetcatalog_generated_info_cocoapods.plist

app 打包过程中, 会提前把flutter项目下载到当前工程下buildProjects子目录。pod 用本地依赖方式集成。
解决方法就是替换那段代码,或者不要把其他依赖工程放到APP主工程子目录下。
本文使用替换代码方式,解决了问题;

post_install do |installer|
  installer.aggregate_targets.each do |target|
    puts "installer.aggregate_targets.each target.name=#{target.name}"
    copy_pods_resources_path = "Pods/Target Support Files/#{target.name}/#{target.name}-resources.sh"
    string_to_replace = "if [[ $line != \"${PODS_ROOT}*\" ]]; then"
    assets_compile_with_app_icon_arguments = "if [[ $line != \"${PODS_ROOT}*\" ]] && [[ $line != *HouseCommercialCube/buildProjects* ]];  then"
    text = File.read(copy_pods_resources_path)
    new_contents = text.gsub(string_to_replace, assets_compile_with_app_icon_arguments)
    File.open(copy_pods_resources_path, "w") {|file| file.puts new_contents }
  end
end
上一篇下一篇

猜你喜欢

热点阅读