amplify-swift icon indicating copy to clipboard operation
amplify-swift copied to clipboard

"library not loaded @rpath/awscore.framework/awscore" error when installing cognito etc. in amplify through 'SPM'

Open vasicer opened this issue 2 years ago • 3 comments

Describe the bug

When amplify is installed through SPM such as congito, api, datastore, the following error occurs.

"library not loaded @rpath/awscore.framework/awscore"

However, if "amplify" is installed without installing "AWSCognitoAuthPlugin" and "AWSPinpointAnalyticsPlugin", no error occurs. However, in this case, the plug-in cannot be used.

Steps To Reproduce

Steps to reproduce the behavior:

  1. Install ‘https://github.com/aws-amplify/amplify-ios' through Swift Package Manager
  2. Select 'AWSCognitoAuthPlugin', 'AWSPinpointAnalyticsPlugin', 'Amplify'
  3. iOS Simulator
    1. Finish and run(debug) app through Simulator
    2. First Open App Success but app close and restart in Simulator
    3. See error
  4. iOS device
    1. Finish and run app through Device(iphone xr)
    2. see error

Expected behavior

add "@rpath/awscore.framework/awscore"

Amplify Framework Version

1.28.0

Amplify Categories

Analytics, Auth

Dependency manager

Swift PM

Swift version

5.6.1

CLI version

10.0.0

Xcode version

13.4.1

Is this a regression?

No

Regression additional context

No response

Device

iphone-XR & simulator

iOS Version

15.6.1

Specific to simulators

No response

Additional context

No response

vasicer avatar Sep 09 '22 10:09 vasicer

@vasicer Thanks for opening the issue. Our team will investigate and provide an update.

harsh62 avatar Sep 09 '22 19:09 harsh62

@vasicer Thanks for opening the issue. Our team will investigate and provide an update.

Thank for your response. It doesn't work in 'SPM', but it works fine in 'Cocoa pod'.

Hopefully that'll fix it 

vasicer avatar Sep 09 '22 22:09 vasicer

@vasicer I've seen this problems with apps before. When a binary is created and it uses other binaries it defines runpaths using @rpath so it knows where to find them. There are 2 common reasons why a binary can fail to be loaded.

  1. The runpath does not point to where the binaries can be found
  2. The binaries were not bundled with the app and so they won't be there

You can determine which of the 2 it is by manually reviewing the build directory. The crash logs should provide more context so you can see which binary is finally to find another binary it needs. Look for that binary and check the location defined by @rpath to see if it is there.

Mostly like you need to to update how you are linking and embedding your app dependencies. You can follow these steps to correct most common problems.

  1. Review Build Phases to ensure all your dependencies are listed under Target Dependencies
  2. Under Link with Libraries check that the linking is correct
  3. Under the General tab check the section on Frameworks, Libraries and Embedded Content

In your Build Settings you can find Runpath Search Paths defined with the setting below. Typically for an iOS app the app bundle has a folder named Frameworks where binaries can be found.

LD_RUNPATH_SEARCH_PATHS = $(inherited) @executable_path/Frameworks

The docs below cover how frameworks are embedded in an app. When you are using SPM for Amplify it references binary frameworks for the AWS SDK. These should be found in the Frameworks directory after you run the build.

Let us know if you can diagnose the problem and fix it with these steps.

brennanMKE avatar Sep 16 '22 18:09 brennanMKE

Hi, I'm having the same issue - I installed AWS SDK through swift package manager. The app builds fine in a simulator but crashes on a real device with the following errors:

dyld[3421]: Library not loaded: @rpath/AWSCore.framework/AWSCore
  Referenced from: <48ECAF53-E510-3205-AD36-4519B64ACB89> /private/var/containers/Bundle/Application/98D7B0DC-EB1E-471F-95D1-DC24FE9DD892/AppName.app/AppName
  Reason: tried: '/Users/user/Library/Developer/Xcode/DerivedData/appname-fbxgvorporwtejdequbpyqeofqyi/Build/Products/Debug-iphoneos/PackageFrameworks/AWSCore.framework/AWSCore' (no such file), '/private/preboot/Cryptexes/OS/Users/user/Library/Developer/Xcode/DerivedData/appname-fbxgvorporwtejdequbpyqeofqyi/Build/Products/Debug-iphoneos/PackageFrameworks/AWSCore.framework/AWSCore' (no such file)

(same error contnd...)

The crash message is Thread 1: signal SIGABRT

What I tried:

  • Cleaning the build
  • Cleaning out the DerivedData
  • Reinstalling the AWS SDK
  • Setting "Always Embed Swift Standard Libraries" setting to Yes
  • Importing AWSCore in my main app struct
  • My search paths seems set to @executable_path/../Frameworks, I haven't changed anything here

I couldn't find any other resolutions online and this issue seems to be the most similar to what I'm experiencing. I would really appreciate your help here.

metedata avatar Oct 16 '23 16:10 metedata