RevenueCat / react-native-purchases

React Native in-app purchases and subscriptions made easy. Support for iOS and Android.
https://www.revenuecat.com
MIT License
722 stars 81 forks source link

Unable to build PurchasesHybridCommon #200

Closed CouplenessTech closed 3 years ago

CouplenessTech commented 3 years ago

Describe the bug

Production build of the app fails with the following error:

could not build Objective-C module 'PurchasesHybridCommon'

with the underlying error:

/ios/Pods/PurchasesHybridCommon/ios/PurchasesHybridCommon/PurchasesHybridCommon/RCPurchases+HybridAdditions.h:12:12: error: declaration of 'RCPurchases' must be imported from module 'Purchases' before it is required

Context Platform: Azure DevOps Hosted Pool (macos-10.15) SDK: react-native-purchases@4.0.0 (latest) Software: XCode 12.2

Details Building using the command line: /xcodebuild -sdk iphoneos -configuration Release -workspace /ios/XX.xcworkspace -scheme XX build CODE_SIGN_STYLE=Manual CODE_SIGN_IDENTITY=iPhone Distribution: XX (XX) PROVISIONING_PROFILE=XX PROVISIONING_PROFILE_SPECIFIER=

aboedo commented 3 years ago

@CouplenessTech lmk how it goes! FWIW I think the important bit is upgrading to React Native 0.63.4, since that sets the ENABLE_MODULES flag to YES, and not having had that might easily have been the problem, and I think RN might actually overwrite whatever value your project is set to

valdrox commented 3 years ago

I had this problem too and tried a few things and now the problem is gone. I reduced react-native-purchases to 4.0.0 from 4.0.1 and npx react-native unlink react-native-purchases, and after reinstalling dependencies the problem was gone. Hopefully one of these two things solves your issue too.

CouplenessTech commented 3 years ago

Neither upgrading to React Native 0.63.4 nor unlinking and reinstalling dependencies worked

NiklasMencke commented 3 years ago

I had the exact same problem.

React Native 0.63.4 react-native-purchases 4.0.1

Before i was using 3.xx and it was working without issues. I then deleted the Pods folder, deleted the Podfile.lock and built again and it works now

aboedo commented 3 years ago

@NiklasMencke that makes sense, thanks for posting. @iDuuck @EricWiener were you able to get it working?

EricWiener commented 3 years ago

@aboedo I will try to check soon. Sorry for the delay

EricWiener commented 3 years ago

@aboedo the solution @NiklasMencke mentioned worked for me. Thanks!

aboedo commented 3 years ago

that's great to hear! thanks for reporting back!

EricWiener commented 3 years ago

@aboedo I spoke too soon. I was able to build, but when I just archived to try to release, it fails with the same error as before.

louiechristie commented 3 years ago

Trying to archive in XCode ~fails for me too.~ Update: it works for me see https://github.com/RevenueCat/react-native-purchases/issues/200#issuecomment-789830622

For anyone reading this to save you some time, here's all the things I tried. (And to make my last few hours seem worthwhile.)

I was working with an app I generated using Expo about a year ago and then ejected to be an Expo bare app a couple of months ago.

Upgrade npm dependencies

npx npm-check-updates -u

Reference: https://stackoverflow.com/a/16074029/3469524

Use compatible dependencies for Expo Bare App and Expo Web

expo upgrade

(This will also remove and reinstall your node_modules folder and package-lock.json file for you.) Reference: https://dev.to/expo/expo-sdk-40-is-now-available-1in0#bare-workflow

Upgrade Cocoapods

sudo gem install Cocoapods

References: https://guides.cocoapods.org/using/getting-started.html https://stackoverflow.com/questions/39481636/updating-to-latest-version-of-cocoapods/51103633#51103633

Update Flipper

ios/Podfile

use_flipper!('Flipper' => '0.78.0')

android/gradle.properties

FLIPPER_VERSION=0.78.0

Reference: https://github.com/facebook/react-native/issues/30836#issuecomment-789368146

Update RNPurchases dependencies

react-native link react-native-purchases

Manually update RNPurchases

  pod 'RNPurchases', :path => '../node_modules/react-native-purchases', :inhibit_warnings => true, :modular_headers => false

Reference: https://github.com/RevenueCat/react-native-purchases/commit/ef2b786dec9421c84045f5d038cc84f85434fbbe#r47791138

Look at your git diff and manually remove duplicates lines that have been generated in ios/Podfile and android/app/src/main/java/[your/package/name]/MainApplication.java

Reinstall iOS Dependencies

rm ios/Podfile.lock
pod install --repo-update

Clean React Native build files

cd android && ./gradlew clean && cd ../
cd ios && xcodebuild clean && cd ../

Reference: https://stackoverflow.com/a/56941424/3469524

Remove old version of the app from your iPhone

On home screen click and hold icon -> 'Remove App' -> 'Delete App'

Re-pair your device in Xcode

In Xcode go to Window -> Devices and Simulators right click your device click 'Unpair device'. Then unplug the device and plug it back in again and tap to trust it when popup displays.

Run in Xcode

Open in Xcode at the top if it says Any iOS Device (arm64, armv7) click on it and select your actual iPhone device. (Note: you need an actual iPhone, you can't use a simulator with react-native-purchases.) Click the big play button ▶

[optional] Ask yourself about your life choices when you next upgrade to a version x.0.0 or x.0.1 of a piece of software and wether you can wait a bit for someone else to be the guinea pig.

[optional] While waiting for React Native to build watch this video by the inventor of WhatsApp's Erlang language on 'the mess we're in' with dependencies and fantasise about building his condenser idea:

https://www.youtube.com/watch?v=lKXe3HUG2l4

Build in Release mode

Product -> Scheme -> Edit Scheme click on 'Run' on the left, change Build Configuration to 'Release' Press that play button again ▶

Get original error

error: declaration of 'RCPurchases' must be imported from module 'Purchases' before it is required

[optional] Despair. Really question those life choices

Actually read through all the comments on this issue and found that someone had some luck with this command and run it:

pod cache clean --all

Reference: https://github.com/RevenueCat/react-native-purchases/issues/200#issuecomment-758538322

Build in release mode

Press that play button again ▶ It works!

Make archive in Xcode

Product -> Archive

Get same error as before.

Update: then I reinstalled Pods see below and it worked

louiechristie commented 3 years ago

Update: it worked for me 🎉

Was able to make an archive in Xcode by reinstalling Pods (iOS dependencies Cocoapods)

cd ios
rm -rf Pods
rm Podfile.lock
pod install 

Then I was then able to make an archive in XCode XCode -> Product -> Archive

Reference: I did this after I read this comment by @NiklasMencke : https://github.com/RevenueCat/react-native-purchases/issues/200#issuecomment-788065699

I don't know why this works. I thought previously deleting Podfile.lock would be enough. I speculate either:

Also see: all the things I did first before this worked for me

aboedo commented 3 years ago

Closing out this issue due to inactivity. If you're still running into issues, try following our SDK troubleshooting guide and open up a new issue if the steps described there don't help.

runna-app commented 2 years ago

I am still getting this issue on my repo. Every time I want to do a release build I have to delete the pods and re-install. Did anyone solve this issue permanently without having to do cd ios rm -rf Pods rm Podfile.lock pod install

imekinox commented 2 years ago

This is something I've been experiencing for a while, it starts working after doing some random changes (listed above ) and spending days to fix it, then out of the blue, it starts failing again. This happens on our CI/CD pipeline without any big changes to Xcode config or code.

No other library happens to behave like this one. Have any of you moved out to something else?

aboedo commented 2 years ago

We recently re-wrote our PurchasesHybridCommon (and the Purchases module it uses under the hood), and the re-write will very likely get rid of those issues. We're working on porting those changes over to React-Native soon, stay tuned!

imekinox commented 2 years ago

So we could use the native SDKs? That's an option we are considering, we have a bunch of native integrations so we could pull this off too. Do you think it's a better approach?

aboedo commented 2 years ago

You can use the native SDKs directly, of course, although it will take some extra work. All of what react-native-purchases does is to bridge over the native SDKs to React-Native, so you'd essentially be doing the same as what react-native-purchases does

kdthomas2121 commented 1 year ago

Is there an update to this @aboedo? I'm still seeing it almost every month

aboedo commented 1 year ago

@kdthomas2121 could you clarify exactly what you're running into? We've made quite a few changes since this issue was posted, including migrating the entire internal dependency that was originally causing the issue into Swift. So if you're still seeing it on modern SDK versions, it's likely to be caused by something different.

Would you mind opening up a new issue explaining what you're seeing?

LydGol90 commented 1 year ago

Hi there, I wanted to share here in case this helps anyone else or helps debug the issue further.

I had never experienced this issue before with my project which has been using this lib for over 2 years. Then I got a new macbook with M2 Max chip and installed latest xcode 14.3.0 and got this for the first time. Others on here have said it happens randomly for them but I have found a specific scenario where I can replicate every time.

With a fresh clean project, I run the pod install and everything works fine, I can run over and over, I can make changes to podfile, install other libraries and run pod install again etc and everything continues to work fine. The issues begin if I run the xcode clean command (command + shift + K). When I run this and try to build it will fail every time with the could not build Objective-C module 'PurchasesHybridCommon' error. Then the only way to recover is to delete pods and pod install again. (FYI for me it is enough to just delete the Purchases, PurchasesCoreSwift and PurchasesHybridCommon folders and run pod install, I do not have to delete and re-install all my Pods).

I'm not sure exactly what the xcode clean is doing under the hood but it is the only thing that causes this issue to happen for me. I can delete ios/build folder, I can delete everything under the xcode DerivedData folder and do a clean build with with no errors. Clearly the clean command does some other things too and one of them is messing with these Pods somehow.

Unfortunately I don't have time to investigate further due to other deadlines so I have simply been avoiding using the xcode clean command. Hope this helps others

fellipetav commented 1 year ago

The team responsible for Flutter projects here encountered this problem today. We still haven't figured out what is a definitive solution. But we noticed that it's happening only when running on iOS Simulators. Doesn't happen when running (debugging or not) in physical ones.

The problem also started after we cleaned the build folder.

Even after deleting Pods and Podfile.lock then running pod install, the problem persists. The only difference is that we can build and run the project, but the error comes up always when we face any kind of exception. But as I said before, it happens only in iOS Simulator.