CocoaPods / CocoaPods

The Cocoa Dependency Manager.
https://cocoapods.org/
Other
14.47k stars 2.62k forks source link

Privacy file: no implicit conversion of nil into Array #12374

Closed tapz closed 1 month ago

tapz commented 1 month ago

Report

What did you do?

Run pod install

What did you expect to happen?

Install all pod dependencies correctly.

What happened instead?

[Privacy Manifest Aggregation] Reading .xcprivacy files to aggregate all used Required Reason APIs.
[!] An error occurred while processing the post-install hook of the Podfile.

no implicit conversion of nil into Array

/Users/tapani/projects/tapani/myapp/node_modules/react-native/scripts/cocoapods/privacy_manifest_utils.rb:115:in `+'
/Users/tapani/projects/tapani/myapp/node_modules/react-native/scripts/cocoapods/privacy_manifest_utils.rb:115:in `block (5 levels) in get_used_required_reason_apis'
/Users/tapani/projects/tapani/myapp/node_modules/react-native/scripts/cocoapods/privacy_manifest_utils.rb:111:in `each'
/Users/tapani/projects/tapani/myapp/node_modules/react-native/scripts/cocoapods/privacy_manifest_utils.rb:111:in `block (4 levels) in get_used_required_reason_apis'
/Users/tapani/projects/tapani/myapp/node_modules/react-native/scripts/cocoapods/privacy_manifest_utils.rb:106:in `each'
/Users/tapani/projects/tapani/myapp/node_modules/react-native/scripts/cocoapods/privacy_manifest_utils.rb:106:in `block (3 levels) in get_used_required_reason_apis'
/Users/tapani/projects/tapani/myapp/node_modules/react-native/scripts/cocoapods/privacy_manifest_utils.rb:105:in `each'
/Users/tapani/projects/tapani/myapp/node_modules/react-native/scripts/cocoapods/privacy_manifest_utils.rb:105:in `block (2 levels) in get_used_required_reason_apis'
/Users/tapani/projects/tapani/myapp/node_modules/react-native/scripts/cocoapods/privacy_manifest_utils.rb:104:in `each'
/Users/tapani/projects/tapani/myapp/node_modules/react-native/scripts/cocoapods/privacy_manifest_utils.rb:104:in `block in get_used_required_reason_apis'
/Users/tapani/projects/tapani/myapp/node_modules/react-native/scripts/cocoapods/privacy_manifest_utils.rb:102:in `each'
/Users/tapani/projects/tapani/myapp/node_modules/react-native/scripts/cocoapods/privacy_manifest_utils.rb:102:in `get_used_required_reason_apis'
/Users/tapani/projects/tapani/myapp/node_modules/react-native/scripts/cocoapods/privacy_manifest_utils.rb:18:in `add_aggregated_privacy_manifest'
/Users/tapani/projects/tapani/myapp/node_modules/react-native/scripts/react_native_pods.rb:301:in `react_native_post_install'
/Users/tapani/projects/tapani/myapp/ios/Podfile:83:in `block (3 levels) in from_ruby'
/opt/homebrew/Cellar/cocoapods/1.15.2/libexec/gems/cocoapods-core-1.15.2/lib/cocoapods-core/podfile.rb:196:in `post_install!'
/opt/homebrew/Cellar/cocoapods/1.15.2/libexec/gems/cocoapods-1.15.2/lib/cocoapods/installer.rb:1013:in `run_podfile_post_install_hook'
/opt/homebrew/Cellar/cocoapods/1.15.2/libexec/gems/cocoapods-1.15.2/lib/cocoapods/installer.rb:1001:in `block in run_podfile_post_install_hooks'
/opt/homebrew/Cellar/cocoapods/1.15.2/libexec/gems/cocoapods-1.15.2/lib/cocoapods/user_interface.rb:149:in `message'
/opt/homebrew/Cellar/cocoapods/1.15.2/libexec/gems/cocoapods-1.15.2/lib/cocoapods/installer.rb:1000:in `run_podfile_post_install_hooks'
/opt/homebrew/Cellar/cocoapods/1.15.2/libexec/gems/cocoapods-1.15.2/lib/cocoapods/installer.rb:337:in `block (2 levels) in create_and_save_projects'
/opt/homebrew/Cellar/cocoapods/1.15.2/libexec/gems/cocoapods-1.15.2/lib/cocoapods/installer/xcode/pods_project_generator/pods_project_writer.rb:61:in `write!'
/opt/homebrew/Cellar/cocoapods/1.15.2/libexec/gems/cocoapods-1.15.2/lib/cocoapods/installer.rb:336:in `block in create_and_save_projects'
/opt/homebrew/Cellar/cocoapods/1.15.2/libexec/gems/cocoapods-1.15.2/lib/cocoapods/user_interface.rb:64:in `section'
/opt/homebrew/Cellar/cocoapods/1.15.2/libexec/gems/cocoapods-1.15.2/lib/cocoapods/installer.rb:315:in `create_and_save_projects'
/opt/homebrew/Cellar/cocoapods/1.15.2/libexec/gems/cocoapods-1.15.2/lib/cocoapods/installer.rb:307:in `generate_pods_project'
/opt/homebrew/Cellar/cocoapods/1.15.2/libexec/gems/cocoapods-1.15.2/lib/cocoapods/installer.rb:183:in `integrate'
/opt/homebrew/Cellar/cocoapods/1.15.2/libexec/gems/cocoapods-1.15.2/lib/cocoapods/installer.rb:170:in `install!'
/opt/homebrew/Cellar/cocoapods/1.15.2/libexec/gems/cocoapods-1.15.2/lib/cocoapods/command/update.rb:63:in `run'
/opt/homebrew/Cellar/cocoapods/1.15.2/libexec/gems/claide-1.1.0/lib/claide/command.rb:334:in `run'
/opt/homebrew/Cellar/cocoapods/1.15.2/libexec/gems/cocoapods-1.15.2/lib/cocoapods/command.rb:52:in `run'
/opt/homebrew/Cellar/cocoapods/1.15.2/libexec/gems/cocoapods-1.15.2/bin/pod:55:in `<top (required)>'
/opt/homebrew/Cellar/cocoapods/1.15.2/libexec/bin/pod:25:in `load'
/opt/homebrew/Cellar/cocoapods/1.15.2/libexec/bin/pod:25:in `<main>'

CocoaPods Environment

### Stack

   CocoaPods : 1.15.2
        Ruby : ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
    RubyGems : 3.5.4
        Host : macOS 14.4.1 (23E224)
       Xcode : 15.3 (15E204a)
         Git : git version 2.39.3 (Apple Git-146)
Ruby lib dir : /opt/homebrew/Cellar/ruby/3.3.0/lib
Repositories : trunk - CDN - https://cdn.cocoapods.org/

### Installation Source

Executable Path: /opt/homebrew/Cellar/cocoapods/1.15.2/libexec/bin/pod

### Plugins

cocoapods-deintegrate : 1.0.5
cocoapods-plugins     : 1.0.0
cocoapods-search      : 1.0.1
cocoapods-trunk       : 1.6.0
cocoapods-try         : 1.2.0

### Podfile

# Resolve react_native_pods.rb with node to allow for hoisting
require Pod::Executable.execute_command('node', ['-p',
  'require.resolve(
    "react-native/scripts/react_native_pods.rb",
    {paths: [process.argv[1]]},
  )', __dir__]).strip

platform :ios, '14.0'
prepare_react_native_project!

linkage = ENV['USE_FRAMEWORKS']

project 'MyApp.xcodeproj'

target 'MyApp' do
  config = use_native_modules!
  use_frameworks! :linkage => :static

  use_react_native!(
    :path => config[:reactNativePath],
    :production => true,
    # An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )

  pod 'RNVectorIcons', :path => '../node_modules/react-native-vector-icons'

  def find_and_replace(dir, findstr, replacestr)
    Dir[dir].each do |name|
      text = File.read(name)
      replace = text.gsub(findstr,replacestr)
      if text != replace
        puts "Fix: " + name
        File.open(name, "w") { |file| file.puts replace }
        STDOUT.flush
      end
    end
    Dir[dir + '*/'].each(&method(:find_and_replace))
  end

  post_install do |installer|
    find_and_replace("./node_modules/react-native-date-picker/ios/RNDatePicker/DatePicker.m", "setHighlightsToday", "setHighlightsTodayFoo")

    # https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202
    react_native_post_install(
      installer,
      config[:reactNativePath],
      :mac_catalyst_enabled => false,
      # :ccache_enabled => true
    )
    installer.pods_project.targets.each do |target|
      target.build_configurations.each do |config|
        config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
      end

      if (target.name&.eql?('FBReactNativeSpec'))
        target.build_phases.each do |build_phase|
          if (build_phase.respond_to?(:name) && build_phase.name.eql?('[CP-User] Generate Specs'))
            target.build_phases.move(build_phase, 0)
          end
        end
      end
    end

    # Flipper requires a crude patch to bump up iOS deployment target, or "error: thread-local storage is not supported for the current target"
    # I'm not aware of any other way to fix this one other than bumping iOS deployment target to match react-native (iOS 11 now)
    installer.pods_project.targets.each do |target|
      target.build_configurations.each do |config|
        config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '14.0'
        config.build_settings['ENABLE_BITCODE'] = 'NO',
        config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
        end
    end

    installer.generated_projects.each do |project|
      project.targets.each do |target|
          target.build_configurations.each do |config|
              config.build_settings["DEVELOPMENT_TEAM"] = "xxxxxxx"
            end
      end
    end

    # ...but if you bump iOS deployment target, Flipper barfs again "Time.h:52:17: error: typedef redefinition with different types"
    # We need to make one crude patch to RCT-Folly - set `__IPHONE_10_0` to our iOS target + 1
    # https://github.com/facebook/flipper/issues/834 - 84 comments and still going...
    `sed -i -e  $'s/__IPHONE_10_0/__IPHONE_12_0/' Pods/RCT-Folly/folly/portability/Time.h`
  end
end

PrivacyInfo.xcprivacy

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>NSPrivacyAccessedAPITypes</key>
    <array>
        <dict>
            <key>NSPrivacyAccessedAPIType</key>
            <string>NSPrivacyAccessedAPICategoryFileTimestamp</string>
            <key>NSPrivacyAccessedAPITypeReasons</key>
            <array>
                <string>C617.1</string>
            </array>
        </dict>
        <dict>
            <key>NSPrivacyAccessedAPIType</key>
            <string>NSPrivacyAccessedAPICategoryUserDefaults</string>
            <key>NSPrivacyAccessedAPITypeReasons</key>
            <array>
                <string>CA92.1</string>
            </array>
        </dict>
        <dict>
            <key>NSPrivacyAccessedAPIType</key>
            <string>NSPrivacyAccessedAPICategorySystemBootTime</string>
            <key>NSPrivacyAccessedAPITypeReasons</key>
            <array>
                <string>35F9.1</string>
            </array>
        </dict>
    </array>
    <key>NSPrivacyCollectedDataTypes</key>
    <array/>
    <key>NSPrivacyTracking</key>
    <false/>
</dict>
</plist>

Project that demonstrates the issue

liy010 commented 1 month ago

same issue, 截屏2024-05-05 11 28 31 It feels like an issue with RN. I have modified this line of code to not generate PrivacyInfo.xcprivacy privacy_file_aggregation_enabled: false

emmanuel-keller commented 1 month ago

Indeed a React Native issue, tracked (and fixed) here: https://github.com/facebook/react-native/issues/44401