zoontek / react-native-permissions

An unified permissions API for React Native on iOS, Android and Windows.
MIT License
4.04k stars 828 forks source link

Invalid `Podfile` file: undefined method `prepare_react_native_project!' #863

Closed birat-pandey closed 6 months ago

birat-pandey commented 6 months ago

Before submitting a new issue

Bug summary

React native version 0.68.2

I followed the documentation as I had to upgrade the permission due to customer io upgrade , I encountered this error:

[!] Invalid Podfile file: undefined method `prepare_react_native_project!' for #<Pod::Podfile:0x00000001048eea18 @defined_in_file=#<Pathname:/Users/.../projectname/ios/Podfile>, @internal_hash={}, @root_target_definitions=[#], @current_target_definition=#>.

This is how my podfile looks like:

require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
require_relative '../node_modules/react-native-permissions/scripts/setup'

platform :ios, '13.0'
prepare_react_native_project!

install! 'cocoapods', :deterministic_uuids => false
use_frameworks! :linkage => :static

setup_permissions([
  'Calendars',
  'Camera',
  'LocationAccuracy',
  'LocationAlways',
  'LocationWhenInUse',
  'MediaLibrary',
  'Microphone',
  'Notifications',
  'PhotoLibrary',
  'PhotoLibraryAddOnly',
  'Reminders',
])

target 'project' do
  config = use_native_modules!

  # Flags change depending on the env values.
  flags = get_default_flags()

  use_react_native!(
    :path => config[:reactNativePath],
    # to enable hermes on iOS, change `false` to `true` and then install pods
    :hermes_enabled => true,
    :fabric_enabled => flags[:fabric_enabled],
    # An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )

  permissions_path = '../node_modules/react-native-permissions/ios'

  pod 'react-native-video', :path => '../node_modules/react-native-video'
  pod 'Permission-Calendars', :path => "#{permissions_path}/Calendars"
  pod 'Permission-Camera', :path => "#{permissions_path}/Camera"
  pod 'Permission-LocationAccuracy', :path => "#{permissions_path}/LocationAccuracy"
  pod 'Permission-LocationAlways', :path => "#{permissions_path}/LocationAlways"
  pod 'Permission-LocationWhenInUse', :path => "#{permissions_path}/LocationWhenInUse"
  pod 'Permission-MediaLibrary', :path => "#{permissions_path}/MediaLibrary"
  pod 'Permission-Microphone', :path => "#{permissions_path}/Microphone"
  pod 'Permission-Notifications', :path => "#{permissions_path}/Notifications"
  pod 'Permission-PhotoLibrary', :path => "#{permissions_path}/PhotoLibrary"
  pod 'Permission-PhotoLibraryAddOnly', :path => "#{permissions_path}/PhotoLibraryAddOnly"
  pod 'Permission-Reminders', :path => "#{permissions_path}/Reminders"
  pod 'react-native-in-app-review', :path => '../node_modules/react-native-in-app-review'
  # pod 'CleverTap-iOS-SDK'
  # pod 'clevertap-react-native', :path => '../node_modules/clevertap-react-native'

  pod 'react-native-add-calendar-event', :path => '../node_modules/react-native-add-calendar-event'
  pod 'react-native-appsflyer', :path => '../node_modules/react-native-appsflyer'

  pod 'customerio-reactnative/fcm', :path => '../node_modules/customerio-reactnative'
  # pod 'CustomerIO/MessagingPushFCM', '~> 2'
  pod 'Firebase', :modular_headers => true
  pod 'FirebaseMessaging', :modular_headers => true
  pod 'Firebase/Crashlytics', :modular_headers => true
  pod 'Firebase/Analytics', :modular_headers => true

  target 'projectTests' do
    inherit! :complete
    # Pods for testing
  end

  # Enables Flipper.
  #
  # Note that if you have use_frameworks! enabled, Flipper will not work and
  # you should disable the next line.
  # use_flipper!()
  # use_flipper!({ 'Flipper' => '0.166.0' })

  post_install do |installer|
    react_native_post_install(installer)
    __apply_Xcode_12_5_M1_post_install_workaround(installer)
    installer.pod_targets.each do |pod|
      if pod.name.eql?('RNPermissions') || pod.name.start_with?('Permission-')
        def pod.build_type;
          # Uncomment the line corresponding to your CocoaPods version
           Pod::BuildType.static_library # >= 1.9
          # Pod::Target::BuildType.static_library # < 1.9
        end
      end
    end
     # https://github.com/facebook/react-native/issues/32451
    installer.pods_project.targets.each do |target|
      if target.name == 'RCT-Folly'
        target.build_configurations.each do |config|
          config.build_settings['HEADER_SEARCH_PATHS'] = "$(inherited) ${PODS_ROOT}/fmt/include"
        end
      end
    end
  end
end

target 'NotificationServiceExtension' do
  # pod 'CustomerIO/MessagingPushFCM', '~> 2'
  pod 'customerio-reactnative-richpush/fcm', :path => '../node_modules/customerio-reactnative'
end

Library version

4.1.5

Environment info

System:
    OS: macOS 13.6.4
    CPU: (4) x64 Intel(R) Core(TM) i5-7267U CPU @ 3.10GHz
    Memory: 22.80 MB / 8.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.16.1 - ~/.nvm/versions/node/v18.16.1/bin/node
    Yarn: 1.22.22 - ~/Desktop/projects/project/node_modules/.bin/yarn
    npm: 8.19.4 - ~/Desktop/projects/project/node_modules/.bin/npm
    Watchman: 2023.12.04.00 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.12.1 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 23.0, iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0
    Android SDK: Not Found
  IDEs:
    Android Studio: 2022.2 AI-222.4459.24.2221.10121639
    Xcode: 15.0.1/15A507 - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.21 - /usr/local/opt/openjdk@11/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.2 => 17.0.2 
    react-native: 0.68.2 => 0.68.2 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Steps to reproduce

  1. Upgrade the react-native-permissions@latest
  2. Add these lines on the podfile as the docs say
    • require_relative '../node_modules/react-native-permissions/scripts/setup' platform :ios, min_ios_version_supported prepare_react_native_project!

Reproducible sample code

require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
require_relative '../node_modules/react-native-permissions/scripts/setup'

platform :ios, '13.0'
prepare_react_native_project!

install! 'cocoapods', :deterministic_uuids => false
use_frameworks! :linkage => :static

setup_permissions([
  'Calendars',
  'Camera',
  'LocationAccuracy',
  'LocationAlways',
  'LocationWhenInUse',
  'MediaLibrary',
  'Microphone',
  'Notifications',
  'PhotoLibrary',
  'PhotoLibraryAddOnly',
  'Reminders',
])

target 'project' do
  config = use_native_modules!

  # Flags change depending on the env values.
  flags = get_default_flags()

  use_react_native!(
    :path => config[:reactNativePath],
    # to enable hermes on iOS, change `false` to `true` and then install pods
    :hermes_enabled => true,
    :fabric_enabled => flags[:fabric_enabled],
    # An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )

  permissions_path = '../node_modules/react-native-permissions/ios'

  pod 'react-native-video', :path => '../node_modules/react-native-video'

  pod 'Permission-Calendars', :path => "#{permissions_path}/Calendars"
  pod 'Permission-Camera', :path => "#{permissions_path}/Camera"
  pod 'Permission-LocationAccuracy', :path => "#{permissions_path}/LocationAccuracy"
  pod 'Permission-LocationAlways', :path => "#{permissions_path}/LocationAlways"
  pod 'Permission-LocationWhenInUse', :path => "#{permissions_path}/LocationWhenInUse"
  pod 'Permission-MediaLibrary', :path => "#{permissions_path}/MediaLibrary"
  pod 'Permission-Microphone', :path => "#{permissions_path}/Microphone"
  pod 'Permission-Notifications', :path => "#{permissions_path}/Notifications"
  pod 'Permission-PhotoLibrary', :path => "#{permissions_path}/PhotoLibrary"
  pod 'Permission-PhotoLibraryAddOnly', :path => "#{permissions_path}/PhotoLibraryAddOnly"
  pod 'Permission-Reminders', :path => "#{permissions_path}/Reminders"
  pod 'react-native-in-app-review', :path => '../node_modules/react-native-in-app-review'
  # pod 'CleverTap-iOS-SDK'
  # pod 'clevertap-react-native', :path => '../node_modules/clevertap-react-native'

  pod 'react-native-add-calendar-event', :path => '../node_modules/react-native-add-calendar-event'
  pod 'react-native-appsflyer', :path => '../node_modules/react-native-appsflyer'

  pod 'customerio-reactnative/fcm', :path => '../node_modules/customerio-reactnative'
  # pod 'CustomerIO/MessagingPushFCM', '~> 2'
  pod 'Firebase', :modular_headers => true
  pod 'FirebaseMessaging', :modular_headers => true
  pod 'Firebase/Crashlytics', :modular_headers => true
  pod 'Firebase/Analytics', :modular_headers => true

  target 'kiindredTests' do
    inherit! :complete
    # Pods for testing
  end

  # Enables Flipper.
  #
  # Note that if you have use_frameworks! enabled, Flipper will not work and
  # you should disable the next line.
  # use_flipper!()
  # use_flipper!({ 'Flipper' => '0.166.0' })

  post_install do |installer|
    react_native_post_install(installer)
    __apply_Xcode_12_5_M1_post_install_workaround(installer)
    installer.pod_targets.each do |pod|
      if pod.name.eql?('RNPermissions') || pod.name.start_with?('Permission-')
        def pod.build_type;
          # Uncomment the line corresponding to your CocoaPods version
           Pod::BuildType.static_library # >= 1.9
          # Pod::Target::BuildType.static_library # < 1.9
        end
      end
    end
     # https://github.com/facebook/react-native/issues/32451
    installer.pods_project.targets.each do |target|
      if target.name == 'RCT-Folly'
        target.build_configurations.each do |config|
          config.build_settings['HEADER_SEARCH_PATHS'] = "$(inherited) ${PODS_ROOT}/fmt/include"
        end
      end
    end
  end
end

target 'NotificationServiceExtension' do
  # pod 'CustomerIO/MessagingPushFCM', '~> 2'
  pod 'customerio-reactnative-richpush/fcm', :path => '../node_modules/customerio-reactnative'
end
zoontek commented 6 months ago

React native 0.68 is nearly two years old not supported anymore. Neither by the React native team or by this library.

Please update, or use an old release.

EDIT: Don't add platform :ios, min_ios_version_supported, prepare_react_native_project!, they are in supported versions Podfile and only serve as a landmark here (for the context). Only setup_permissions must be added

anniewey commented 6 days ago

I'm using an even lower version 0.67.4 but able to run following the docs. just add these two lines below:

require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
require_relative '../node_modules/react-native-permissions/scripts/setup' //1. add this

platform :ios, '13.0'

$RNFirebaseAnalyticsWithoutAdIdSupport = true

setup_permissions(['Notifications']) //2. add this
...