marcojak / MauiMTAdmob

MIT License
104 stars 17 forks source link

Running .NET MAUI 8 app on real iOS device getting error - Undefined symbols for architecture arm64 #60

Open khambley opened 5 months ago

khambley commented 5 months ago

/usr/local/share/dotnet/packs/Microsoft.iOS.Sdk/17.0.8478/targets/Xamarin.Shared.Sdk.targets(3,3): Error: clang++ exited with code 1: Undefined symbols for architecture arm64: "_OBJCCLASS$_UMPConsentForm", referenced from: objc-class-ref in registrar.o "_OBJCCLASS$_UMPConsentInformation", referenced from: objc-class-ref in registrar.o "_OBJCCLASS$_UMPDebugSettings", referenced from: objc-class-ref in registrar.o "_OBJCCLASS$_UMPRequestParameters", referenced from: objc-class-ref in registrar.o ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

This build error only occurs when I try to test on my physical iOS devices running iOS 17.2. The plugin works fine on the iOS simulators. I'm building and running it on a Mac in VS for Mac, 17.6.8. Android works fine on simulators and physical devices. I'm running Xcode 15.0.1. I see there is an update for Xcode to 15.2. I'll try updating it and see if that solves it.

erossini commented 5 months ago

I get the same error and I also opened a post on Stackoverflow about it.

I'm not sure is related to the component.

marcojak commented 5 months ago

I've tried on an iPad and it was working fine but let me try again with this version and I'll update you asap.

khambley commented 5 months ago

Yeah, I updated my Xcode to 15.2 and still getting the error above. Not sure what I'm missing here.

marcojak commented 5 months ago

Just tested again and now I get the same issue. I'm investigating it...

marcojak commented 5 months ago

Not sure if this matters, however, I've updated Visual Studio on my PC, I've updated VS on the mac (this might be less relevant) and run the sample on my iPad...then it worked without getting the Arm64 error.

Could you try to update VS and test it again?

erossini commented 5 months ago

I have updated my VS but I still get the error. As a side not, I got another issue because I couldn't deploy the app to the simulator. For that, I added to the project file those lines

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-ios|AnyCPU'">
    <ForceSimulatorX64ArchitectureInIDE>true</ForceSimulatorX64ArchitectureInIDE>
</PropertyGroup>

and, yes, I clean bin and obj folders.

Here is the log when I try to deploy on my real iPhone. ios_build_log.txt

I noticed that at the end there are some warning about Google Ads

2>C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\17.2.8004\targets\Xamarin.Shared.Sdk.targets(746,3): warning MT7091: The framework C:/Users/enric/.nuget/packages/xamarin.firebase.ios.core/8.10.0.3/lib/net6.0-ios15.4/Firebase.Core.resources/GoogleUtilitiesComponents.xcframework/ios-arm64/GoogleUtilitiesComponents.framework is a framework of static libraries, and will not be copied to the app. 2>C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\17.2.8004\targets\Xamarin.Shared.Sdk.targets(746,3): warning MT7091: The framework C:/Users/enric/AppData/Local/XamarinBuildDownloadCache/FAdM-8.13.0/Frameworks/GoogleMobileAdsFramework-Current/GoogleMobileAds.xcframework/ios-arm64_armv7/GoogleMobileAds.framework is a framework of static libraries, and will not be copied to the app. 2>C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\17.2.8004\targets\Xamarin.Shared.Sdk.targets(746,3): warning MT7091: The framework C:/Users/enric/AppData/Local/XamarinBuildDownloadCache/GAppM-8.9.1/GoogleAppMeasurement-8.9.1/Frameworks/GoogleAppMeasurement.xcframework/ios-arm64_armv7/GoogleAppMeasurement.framework is a framework of static libraries, and will not be copied to the app. 2>"$(xcrun -find bitcode_strip)" C:/Users/enric/AppData/Local/XamarinBuildDownloadCache/GAppM-8.9.1/GoogleAppMeasurement-8.9.1/Frameworks/GoogleAppMeasurement.xcframework/ios-arm64_armv7/GoogleAppMeasurement.framework/GoogleAppMeasurement -r -o C:/Users/enric/AppData/Local/XamarinBuildDownloadCache/GAppM-8.9.1/GoogleAppMeasurement-8.9.1/Frameworks/GoogleAppMeasurement.xcframework/ios-arm64_armv7/GoogleAppMeasurement.framework/GoogleAppMeasurement 2>"$(xcrun -find bitcode_strip)" C:/Users/enric/AppData/Local/XamarinBuildDownloadCache/FAdM-8.13.0/Frameworks/GoogleMobileAdsFramework-Current/GoogleMobileAds.xcframework/ios-arm64_armv7/GoogleMobileAds.framework/GoogleMobileAds -r -o C:/Users/enric/AppData/Local/XamarinBuildDownloadCache/FAdM-8.13.0/Frameworks/GoogleMobileAdsFramework-Current/GoogleMobileAds.xcframework/ios-arm64_armv7/GoogleMobileAds.framework/GoogleMobileAds

khambley commented 5 months ago

Not sure if this matters, however, I've updated Visual Studio on my PC, I've updated VS on the mac (this might be less relevant) and run the sample on my iPad...then it worked without getting the Arm64 error.

Could you try to update VS and test it again?

My VS is up to date as well. What Apple chip does your Mac have? I'm running on an M1. I wonder if it needs to compile on an M2? Just a shot in the dark.

erossini commented 5 months ago

My iMac is an M1. I have bought it last year only for testing the apps 😉

khambley commented 5 months ago

My iMac is an M1. I have bought it last year only for testing the apps 😉

Mine is too. That question was directed @marcojak I wonder if they have an M2.

khambley commented 5 months ago

I just tried building it on my Macbook Pro which has an M2 chip and same error. I've tried testing it on an iPhone 13 Pro Max and an iPhone SE (3rd gen) both are iOS 17.2.

khambley commented 5 months ago

@marcojak I've got a PC, I'm going to give it a try on there, maybe that's the issue.

marcojak commented 5 months ago

So, currently I have a MacBook Pro with an i7.

I don't think the Mac architecture is related to the issue as I was able to experience it and then again after I rebuilt this sample app, it worked. While I was doing my test, in the configuration manager I set up ARM64 instead of any. Not sure if that could be the reason why it worked. What I can do, if you are happy to try, is to send you a new version of the library to see if that works for you.

erossini commented 5 months ago

Sure

khambley commented 5 months ago

Yeah, we don't have a configuration manager option on Visual Studio for Mac. I believe it defaults to x64 architecture, I'll see if I can add arm64 in the proj file.

khambley commented 5 months ago

I'm at a loss. I tried building it on a PC that was paired to my Mac. And same error when deploying to a physical iOS device, iPhone 13 Pro Max. I did try setting the CPU to arm64 directly and I'm getting the same error. I'm sorry to say, I'll have to remove MauiMTAdmob and ads for now from iOS build until this is fixed. Bummer!

marcojak commented 5 months ago

Plugin.MauiMTAdmob.1.1.1.zip

Here is the updated version. Could you please try it?

There are no changes but hopefully this should support ARM64.

To make it work:

  1. Remove the plugin from your app
  2. Extract and add this package to your local nugets (if you don't have it already configured, you can do it from VS).
  3. Remove the plugin from the cache (This is required, otherwise, the app will use the package from your cache).
  4. Add the package to the app again

Please, let me know if it works.

marcojak commented 5 months ago

I'm at a loss. I tried building it on a PC that was paired to my Mac. And same error when deploying to a physical iOS device, iPhone 13 Pro Max. I did try setting the CPU to arm64 directly and I'm getting the same error. I'm sorry to say, I'll have to remove MauiMTAdmob and ads for now from iOS build until this is fixed. Bummer!

Could you try the new version I added in the comment just up here?

erossini commented 5 months ago

No, unfortunately some error 😒

marcojak commented 5 months ago

Which version of xcode do you have?

erossini commented 5 months ago

15.2

Screenshot 2024-01-31 at 17 39 44
marcojak commented 5 months ago

I'm using 15.1.

Let me update it to 15.2 and try again. It might take a while as my machine is pretty old, but I'll update you as soon as I can try it.

marcojak commented 5 months ago

While I continue my tests, could you add this package to your iOS app?

This contains the missing references....maybe referencing it directly might solve the issue...

erossini commented 5 months ago

While I continue my tests, could you add this package to your iOS app?

This contains the missing references....maybe referencing it directly might solve the issue...

Sorry, what package? If you refer to the zip file, yes, I added to my project and I get the same issue

marcojak commented 5 months ago

this one: => "MT.Xamarin.Google.iOS.UserMessagingPlatform" Version="1.1.0.2"

sorry it didn't appear in the previous comment

khambley commented 5 months ago

So, I downloaded and installed MT.Xamarin.Google.iOS.UserMessagingPlatform" Version="1.1.0.2, cleaned, rebuilt and tried to run on iOS physical device, still getting error. I tried this workaround, in the cproj file: per this link https://stackoverflow.com/questions/76618970/appdynamics-agent-for-maui-symbol-not-found-for-architecture-x86-64

<Project Sdk="Microsoft.NET.Sdk">
  ...
  <PropertyGroup Condition="$(TargetFramework.Contains('-ios'))">
    <MTouchExtraArgs>--registrar:static</MTouchExtraArgs>
  </PropertyGroup>

</Project>

And at first it looked promising, I was able to build the iOS app and it started to launch but then it got to the launch screen and crashed. UGH!! I'll keep trying things, about to pull my hair out!

marcojak commented 5 months ago

I've moved from Visual studio connected to a mac to VS for mac on my mac with i7. Now I again see the same error (so at least it's not an issue of i7 vs M1 or M2... It's painful as my mac takes ages to build so it's quite slow, but I'll try to find a solution asap.

marcojak commented 5 months ago

Ok, I think I've found a "temporary" solution.

In your ios project import this package: "Xamarin.Google.iOS.UserMessagingPlatform" Version="1.1.0.1"

I'm investigating it further to see why we see this error.

khambley commented 5 months ago

Ok, I think I've found a "temporary" solution.

In your ios project import this package: "Xamarin.Google.iOS.UserMessagingPlatform" Version="1.1.0.1"

I'm investigating it further to see why we see this error.

So I did that and it completely hosed my app. It won't load at all. I re-cloned it from my repo and pulled it down prior to adding your plugin. I created a new MAUI project on my PC and added in your plugin and the setup for iOS including the license. I got it to deploy once to my iOS physical device but the ads did not show up. I then tried again and I got all kinds of errors, like

2022-08-22 23:14:34.618 Xamarin.PreBuilt.iOS[94921:6409975] Could not resolve assembly Microsoft.VisualStudio.DesignTools.TapContract, Version=17.0.0.0, Culture=neutral, PublicKeyToken=null. Details: Could not load file or assembly '/var/mobile/Containers/Data/Application/6B3B6CF6-2A5A-452F-956D-74D8A66941EA/Documents/Lofty.Logbook.content/Microsoft.VisualStudio.DesignTools.TapContract.dll' or one of its dependencies.

It runs on the PC connected to my Mac on the iOS simulators for 17.2. But not physical iOS devices. It's too buggy and unreliable at this point. I'm going to have to find another solution, maybe this tutorial looks promising... ? Admob

erossini commented 5 months ago

Ok, I think I've found a "temporary" solution.

In your ios project import this package: "Xamarin.Google.iOS.UserMessagingPlatform" Version="1.1.0.1"

I'm investigating it further to see why we see this error.

I added this package and now I can deploy on my physical iPhone the application. Thank you The problem is that the advertisements are not displaying at all, in particular banners and interstitial rewards. Maybe, it is because I haven't published the application on the Apple Store and there is no connection to the Apple Store in the Google AdMob settings.

marcojak commented 5 months ago

I'm glad it works... I've noticed something else that doesn't work as it should on iOS physical device and this could be the reason why you don't see ads...I hope to send you a new version to test by the end of the morning so you can test it.

In general, If you are using test IDs, then you should be able to see ads even if not on the store yet.

erossini commented 5 months ago

There is another thing I noticed but in both platforms. I should open another ticket. Briefly, with the interstitial rewards I call

CrossMauiMTAdmob.Current.ShowRewarded();

and then the app is waiting for one of the events to continue. The problem here is that the rewarded is not showing at all and not event is fired.

marcojak commented 5 months ago

There is another thing I noticed but in both platforms. I should open another ticket. Briefly, with the interstitial rewards I call

CrossMauiMTAdmob.Current.ShowRewarded();

and then the app is waiting for one of the events to continue. The problem here is that the rewarded is not showing at all and not event is fired.

Please, open another ticket and I'll have a look and fix it if needed...just to be sure, before calling show rewarded, have you loaded the ad? did you get an event that the ad was loaded successfully (or failed to load)?

marcojak commented 5 months ago

Could you please try this one? If everything is ok, I'll update on nuget.

Plugin.MauiMTAdmob.1.1.2.zip

erossini commented 5 months ago

Sure

erossini commented 5 months ago

Do I need to remove the package Xamarin.Google.iOS.UserMessagingPlatform?

marcojak commented 5 months ago

No, for now keep it. Still trying to fix the issue...

On Thu, 1 Feb 2024, 12:09 Enrico Rossini, @.***> wrote:

Do I need to remove the package Xamarin.Google.iOS.UserMessagingPlatform?

— Reply to this email directly, view it on GitHub https://github.com/marcojak/MauiMTAdmob/issues/60#issuecomment-1921074893, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAUIPIXU6O5ZG4AEDM5RWULYRNZU7AVCNFSM6AAAAABCRR7RJWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMRRGA3TIOBZGM . You are receiving this because you were mentioned.Message ID: @.***>

erossini commented 5 months ago

I quickly tried this version and it seems working.

marcojak commented 5 months ago

That's great. I'll see if I can do something to avoid that import in the iOS project and then I'll release it to everyone

marcojak commented 5 months ago

I've just uploaded the new version 1.1.2 to nuget. This version is slightly different from the one available here and with this one it should be possible to not include the Xamarin.Google.iOS.UserMessagingPlatform in the iOS project.

Remember to remove it from the cache, otherwise VS will use that one instead of downloading it from nuget. If everything works, I can then close this issue!

erossini commented 5 months ago

Yes, it is working. Thank you so much!

khambley commented 5 months ago

I updated your plugin to 1.1.2. The license and app Id is correctly set in the Info.plist and the AppDelegate. I'm getting an error and the app crashes on iOS physical device: An error occurred: 'Object reference not set to an instance of an object.'. Callstack: ' at Plugin.MauiMTAdmob.Platforms.iOS.UMPImplementation..ctor(MauiMTAdmob mauiMTAdmob, Boolean tagForUnderAgeOfConsent, String testDeviceId, DebugGeography geography) at Plugin.MauiMTAdmob.MauiMTAdmob.Init(String license, Boolean tagForUnderAgeOfConsent, String testDeviceId, DebugGeography geography) at Maui3Demo.AppDelegate.FinishedLaunching(UIApplication application, NSDictionary launchOptions) in C:\Projects\Maui3Demo\Maui3Demo\Platforms\iOS\AppDelegate.cs:line 18 at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 58 at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 94 at Maui3Demo.Program.Main(String[] args) in C:\Projects\Maui3Demo\Maui3Demo\Platforms\iOS\Program.cs:line 13 at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args) at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)' The app has been terminated. 2024-02-01 08:35:48.128 Xamarin.PreBuilt.iOS[1380:324948] MTAdmob correctly licensed

erossini commented 5 months ago

It is working for me. For iOS I set

    public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
    {
        CrossMauiMTAdmob.Current.Init(Constants.MauiMTAdmobLicence);
        return base.FinishedLaunching(application, launchOptions);
    }

if it could be helpful

khambley commented 5 months ago

It is working for me. For iOS I set

    public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
    {
        CrossMauiMTAdmob.Current.Init(Constants.MauiMTAdmobLicence);
        return base.FinishedLaunching(application, launchOptions);
    }

if it could be helpful

Tried that, same error

marcojak commented 5 months ago

Interesting... Can I ask you to remove the plugin from the nuget cache, clean the project and rebuild it? This should be another issue than arm64, but I'm not sure yet which one...

khambley commented 5 months ago

It doesn't work on the iOS simulators anymore either. Something isn't getting set in the Plugin and I can't figure out what. Object reference not set to an instance of an object. (System.NullReferenceException at Plugin.MauiMTAdmob.Platforms.iOS.UMPImplementation..ctor(MauiMTAdmob mauiMTAdmob, Boolean tagForUnderAgeOfConsent, String testDeviceId, DebugGeography geography) at Plugin.MauiMTAdmob.MauiMTAdmob.Init(String license, Boolean tagForUnderAgeOfConsent, String testDeviceId, DebugGeography geography) at Maui3Demo.AppDelegate.FinishedLaunching(UIApplication application, NSDictionary launchOptions) in C:\Projects\Maui3Demo\Maui3Demo\Platforms\iOS\AppDelegate.cs:line 19 at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 58 at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 94 at Maui3Demo.Program.Main(String[] args) in C:\Projects\Maui3Demo\Maui3Demo\Platforms\iOS\Program.cs:line 13

marcojak commented 5 months ago

Have you removed from your iOS project Xamarin.Google.iOS.UserMessagingPlatform?

Out of curiosity, can I ask you to remove the app from the simulator and device, rebuild your project and test it again?

Does the sample work for you?

I'll do some further tests and see if I can spot any null references and if needed release a new version

erossini commented 5 months ago

@khambley you are right! In the Simulator I get the same error

image

marcojak commented 5 months ago

Just the simulator? This might give me an idea...sorry about this...

erossini commented 5 months ago

OK, now I tried to deploy to the real device and I have other errors because I'm doing same changing but I can see something that I don't like anymore 😁

image

This happens after replacing the zip package with the package from the NuGet online.

marcojak commented 5 months ago

Ok...for that error, you can just include Xamarin.Google.iOS.UserMessagingPlatform 1.1.0.1 and that should fix it... Not sure again what's happening with the nuget package... For the cards...that shouldn't be related to MTAdmob 😄