zoontek / react-native-permissions

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

config plugin is malform #841

Closed chanphiromsok closed 9 months ago

chanphiromsok commented 9 months ago

Before submitting a new issue

Bug summary

error in app.config.ts when run yarn expo prebuild { "name": "My awesome app", "plugins": [ [ "react-native-permissions", { // uncomment wanted permissions "iosPermissions": [ // "AppTrackingTransparency", // "Bluetooth" // "Calendars", // "CalendarsWriteOnly", // "Camera", // "Contacts", // "FaceID", // "LocationAccuracy", // "LocationAlways", // "LocationWhenInUse", // "MediaLibrary", // "Microphone", // "Motion", // "Notifications", // "PhotoLibrary", // "PhotoLibraryAddOnly", // "Reminders", // "Siri", // "SpeechRecognition", // "StoreKit" ] } ] ] } Screenshot 2024-01-31 at 9 17 12 in the morning

running

Library version

4.1.0

Environment info

System:
  OS: macOS 14.1.2
  CPU: (8) arm64 Apple M1
  Memory: 81.33 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.19.0
    path: ~/.asdf/installs/nodejs/18.19.0/bin/node
  Yarn:
    version: 1.22.21
    path: ~/.asdf/installs/nodejs/18.19.0/bin/yarn
  npm:
    version: 10.2.5
    path: ~/node_modules/.bin/npm
  Watchman:
    version: 2023.12.04.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.14.3
    path: /usr/local/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.2
      - iOS 17.2
      - macOS 14.2
      - tvOS 17.2
      - watchOS 10.2
  Android SDK:
    API Levels:
      - "29"
      - "31"
      - "33"
      - "34"
    Build Tools:
      - 30.0.2
      - 30.0.3
      - 33.0.0
      - 33.0.1
      - 34.0.0
    System Images:
      - android-34 | Google APIs ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: 2023.1 AI-231.9392.1.2311.11076708
  Xcode:
    version: 15.1/15C65
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.9
    path: /Users/rom/.asdf/shims/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.72.6
    wanted: 0.72.6
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found

Steps to reproduce

  1. add react-native-permissions to app.config.ts
  2. run yarn expo prebuild got an error plugin can not plug

Reproducible sample code

{
  "name": "My awesome app",
  "plugins": [
    [
      "react-native-permissions",
      {
        // uncomment wanted permissions
        "iosPermissions": [
          // "AppTrackingTransparency",
          // "Bluetooth"
          // "Calendars",
          // "CalendarsWriteOnly",
          // "Camera",
          // "Contacts",
          // "FaceID",
          // "LocationAccuracy",
          // "LocationAlways",
          // "LocationWhenInUse",
          // "MediaLibrary",
          // "Microphone",
          // "Motion",
          // "Notifications",
          // "PhotoLibrary",
          // "PhotoLibraryAddOnly",
          // "Reminders",
          // "Siri",
          // "SpeechRecognition",
          // "StoreKit"
        ]
      }
    ]
  ]
}
zoontek commented 9 months ago

Don't put comments, it' not valid JSON. https://github.com/zoontek/react-native-permissions/commit/d36e0349f9b8b2a82c72acb5e2bff1d30da1d9ee

pierguinzani commented 2 months ago

@zoontek, I don't have comments in app.json, but I'm facing the same problem.

Basically, when I run npx expo prebuild, it adds some settings to the Podfile:

# @generated begin require - expo prebuild (DO NOT MODIFY) sync-0b3d11245f758d271ec25750612913aa85ad0f45
require File.join(File.dirname(`node --print ‘require.resolve(’react-native-permissions/package.json‘)’`), ‘scripts/setup’)
# @generated end require
# @generated begin setup - expo prebuild (DO NOT MODIFY) sync-aef63821df58f3f9287e46b77c11c725ef295e89
setup_permissions([
  ‘Camera’,
  ‘Microphone’,
  ‘Contacts’,
  ‘Notifications’,
])
# Final configuration of @generated

and when I run the npx expo prebuild again it gives the following error:

ERROR: Cannot add react-native-permissions to the project's ios/Podfile because it's malformed. Please report this with a copy of your project Podfile.

my app.json looks like this:

{
  "expo": {
    "name": "MyApp",
    "slug": "myapp",
    "version": "1.6.0",
    "scheme": "com.company.myapp",   
    "orientation": "portrait",
    "owner": "company",
    "icon": "./assets/app_icon.png",
    "backgroundColor": "#ffffff",
    "splash": {
      "image": "./assets/splash_bluebackground.png",
      "backgroundColor": "#117AF7",
      "resizeMode": "cover"
    },
    "jsEngine": "hermes",
    "assetBundlePatterns": [
      "**/*"
    ],
    "android": {
      "package": "com.company.myapp",
      "googleServicesFile": "./google-services.json",
      "adaptiveIcon": {
        "foregroundImage": "./assets/app_icon.png",
        "backgroundColor": "#ffffff"
      },
      "allowBackup": false,
      "versionCode": 173,
      "permissions": [
        "BIND_TELECOM_CONNECTION_SERVICE",
        "ACTION_MANAGE_OVERLAY_PERMISSION",
        "CALL_PHONE",
        "FOREGROUND_SERVICE",
        "READ_PHONE_STATE",
        "FOREGROUND_SERVICE_DATA_SYNC",
        "FOREGROUND_SERVICE_MICROPHONE",
        "CAPTURE_AUDIO_HOTWORD",
        "CAPTURE_AUDIO_OUTPUT",
        "CAPTURE_MEDIA_OUTPUT",
        "CAPTURE_TUNER_AUDIO_INPUT",
        "CAPTURE_VOICE_COMMUNICATION_OUTPUT"
      ]
    },
    "ios": {
      "bundleIdentifier": "com.company.myapp",
      "googleServicesFile": "./GoogleService-Info.plist",
      "supportsTablet": true,
      "infoPlist": {
        "UIBackgroundModes": [
          "fetch",
          "processing",
          "remote-notification",
          "voip",
          "audio"
        ],
        "BGTaskSchedulerPermittedIdentifiers": [
          "com.company.myapp"],
        "OS_ACTIVITY_MODE": "disable",
        "NSMicrophoneUsageDescription": "[REASON]",
        "NSContactsUsageDescription": "[REASON]",
        "NSCameraUsageDescription": "[REASON]",
        "NSPhotoLibraryUsageDescription": "[REASON]",
      },
      "config": {
        "usesNonExemptEncryption": false
      }
    },
    "plugins": [
      [
        "@config-plugins/react-native-webrtc"
      ],
      [
        "expo-build-properties",
        {
          "android": {
            "compileSdkVersion": 34,
            "targetSdkVersion": 34,
            "buildToolsVersion": "33.0.0",
            "minSdkVersion": 26,
            "kotlinVersion": "1.8.10"
          },
          "ios": {
            "deploymentTarget": "13.0",
            "useFrameworks": "static"
          }
        }
      ],
      [
        "expo-contacts",
        {
          "contactsPermission": "[REASON]",
        }
      ],
      [
        "@react-native-firebase/app"
      ],
      [
        "expo-image-picker"
      ],
      [
        "react-native-permissions",
        {
          "iosPermissions": [
            "Camera",
            "Microphone",
            "Contacts",
            "Notifications"
          ]
        }
      ]
    ]
  }
}

and here's my Podfile:

require File.join(File.dirname(`node --print "require.resolve('expo/package.json')"`), "scripts/autolinking")
require File.join(File.dirname(`node --print "require.resolve('react-native/package.json')"`), "scripts/react_native_pods")
# @generated begin require - expo prebuild (DO NOT MODIFY) sync-0b3d11245f758d271ec25750612913aa85ad0f45
require File.join(File.dirname(`node --print "require.resolve('react-native-permissions/package.json')"`), "scripts/setup")
# @generated end require
require File.join(File.dirname(`node --print "require.resolve('@react-native-community/cli-platform-ios/package.json')"`), "native_modules")

require 'json'
podfile_properties = JSON.parse(File.read(File.join(__dir__, 'Podfile.properties.json'))) rescue {}

ENV['RCT_NEW_ARCH_ENABLED'] = podfile_properties['newArchEnabled'] == 'true' ? '1' : '0'

platform :ios, podfile_properties['ios.deploymentTarget'] || '13.0'
install! 'cocoapods',
  :deterministic_uuids => false

prepare_react_native_project!
# @generated begin setup - expo prebuild (DO NOT MODIFY) sync-aef63821df58f3f9287e46b77c11c725ef295e89
setup_permissions([
  'Camera',
  'Microphone',
  'Contacts',
  'Notifications',
])
# @generated end setup

# If you are using a `react-native-flipper` your iOS build will fail when `NO_FLIPPER=1` is set.
# because `react-native-flipper` depends on (FlipperKit,...), which will be excluded. To fix this,
# you can also exclude `react-native-flipper` in `react-native.config.js`
#
# ```js
# module.exports = {
#   dependencies: {
#     ...(process.env.NO_FLIPPER ? { 'react-native-flipper': { platforms: { ios: null } } } : {}),
#   }
# }
# ```
flipper_config = FlipperConfiguration.disabled
if ENV['NO_FLIPPER'] == '1' then
  # Explicitly disabled through environment variables
  flipper_config = FlipperConfiguration.disabled
elsif podfile_properties.key?('ios.flipper') then
  # Configure Flipper in Podfile.properties.json
  if podfile_properties['ios.flipper'] == 'true' then
    flipper_config = FlipperConfiguration.enabled(["Debug", "Release"])
  elsif podfile_properties['ios.flipper'] != 'false' then
    flipper_config = FlipperConfiguration.enabled(["Debug", "Release"], { 'Flipper' => podfile_properties['ios.flipper'] })
  end
end

target 'myapp' do
  use_expo_modules!
  config = use_native_modules!

  use_frameworks! :linkage => podfile_properties['ios.useFrameworks'].to_sym if podfile_properties['ios.useFrameworks']
  use_frameworks! :linkage => ENV['USE_FRAMEWORKS'].to_sym if ENV['USE_FRAMEWORKS']

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

  use_react_native!(
    :path => config[:reactNativePath],
    :hermes_enabled => podfile_properties['expo.jsEngine'] == nil || podfile_properties['expo.jsEngine'] == 'hermes',
    :fabric_enabled => flags[:fabric_enabled],
    # An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/..",
    # Note that if you have use_frameworks! enabled, Flipper will not work if enabled
    :flipper_configuration => flipper_config
  )

  post_install do |installer|
    react_native_post_install(
      installer,
      config[:reactNativePath],
      # Set `mac_catalyst_enabled` to `true` in order to apply patches
      # necessary for Mac Catalyst builds
      :mac_catalyst_enabled => false
    )
    __apply_Xcode_12_5_M1_post_install_workaround(installer)

    # This is necessary for Xcode 14, because it signs resource bundles by default
    # when building for devices.
    installer.target_installation_results.pod_target_installation_results
      .each do |pod_name, target_installation_result|
      target_installation_result.resource_bundle_targets.each do |resource_bundle_target|
        resource_bundle_target.build_configurations.each do |config|
          config.build_settings['CODE_SIGNING_ALLOWED'] = 'NO'
        end
      end
    end

    installer.pods_project.targets.each do |target|
      target.build_configurations.each do |config|
        config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = podfile_properties['ios.deploymentTarget']
      end
    end

  end

  post_integrate do |installer|
    begin
      expo_patch_react_imports!(installer)
    rescue => e
      Pod::UI.warn e
    end
  end
end
vishva-simform commented 1 month ago

@chanphiromsok @zoontek @pierguinzani I am facing the same issue in my project. Does anyone have any solution?

image
zoontek commented 1 month ago

@vishva-simform Your Podfile is incorrect

vishva-simform commented 1 month ago

@zoontek My podfile is auto generating with prebuild ios command npx expo prebuild and I've added pluging in app.json file

zoontek commented 1 month ago

Still malformed, or you are using a version of Expo that is too old.

vishva-simform commented 1 month ago

I am using Expo version 51 but still facing the same error with malformed

zoontek commented 1 month ago

Another plugin might mess with it.

chanphiromsok commented 1 month ago

I am using Expo version 51 but still facing the same error with malformed

I think you must double to make sure your code does not have a comment on the code check this commit https://github.com/zoontek/react-native-permissions/commit/d36e0349f9b8b2a82c72acb5e2bff1d30da1d9ee try to clean and run expo prebuild incase your code not generate new

pelinche commented 1 month ago

Any updates on this? I'm having the same issues.

If I clear the auto-generated lines on Podfile from expo prebuild, and run npx expo prebuild again, I don't get the error (the lines are added to the Podfile). This only happens when react-native-permissions added the lines to the file, and doesn't seem to know how to properly handle updating them.

I tried using the newly released version (5.0.0), but the problem is the same.

zoontek commented 1 month ago

@pelinche By:

If I clear the auto-generated lines on Podfile from expo prebuild

You mean "I run npx expo prebuild --clean? Or are you updating the files manually?

pelinche commented 1 month ago

Manually image

and when i run npx expo prebuild ,

✔ Created native directories | reusing /android, /ios
✔ Updated package.json | no changes
✔ Finished prebuild
✨  Done in 2.45s.

But if I run again npx expo prebuild

$ npx expo prebuild
✔ Created native directories | reusing /android, /ios
✔ Updated package.json | no changes
ERROR: Cannot add react-native-permissions to the project's ios/Podfile because it's malformed. Please report this with a copy of your project Podfile.
✔ Finished prebuild
✨  Done in 2.32s.
pelinche commented 1 month ago

@zoontek , If I comment out the code that causes the error (results of withSetup.didMerge or withRequire.didMerge = false), the Podfile is updated.

This way, I can say that the problem must be in the _generateCode.mergeContents function.

image
zoontek commented 1 month ago

@pelinche It's highly recommanded not to perform manual updates in prebuilt files (instead, local plugins to perform the updates is the way to go), but I allowed it in 5.0.1.

pelinche commented 1 month ago

Thanks @zoontek . This worked for me.