How to get admob sdk ios (.xcframework) to work with robovm (Libgdx)? Error: Undefined symbols for architecture arm64:

411 Views Asked by At

I am trying to implement google admob sdk on my LibGDX project for iOS, when I try to launch the game I get this error:

[ERROR] 14:44:17.979 Undefined symbols for architecture arm64:
[ERROR] 14:44:17.980   "_OBJC_CLASS_$_GADInterstitial", referenced from:
[ERROR] 14:44:17.981       objc-class-ref in libGGLAdMob.a(GGLContext+AdMob.o)
[ERROR] 14:44:18.114      (maybe you meant: _OBJC_CLASS_$_GADInterstitialAd)
[ERROR] 14:44:18.157 ld: symbol(s) not found for architecture arm64
[ERROR] 14:44:18.180 clang: error: linker command failed with exit code 1 (use -v to see invocation)
[ERROR] Couldn't compile app

I have the following in my gradle file:

buildscript {
    
    ....
    dependencies {
        classpath 'com.android.tools.build:gradle:7.1.3'
        classpath 'com.mobidevelop.robovm:robovm-gradle-plugin:2.3.15'

        //for ads for firebase
        classpath 'com.google.gms:google-services:4.3.10'
    }
}

allprojects {
    apply plugin: "eclipse"

    version = '1'
    ext {
        ...
        gdxVersion = '1.10.0'
        roboVMVersion = '2.3.15'
        ...
    }

    ...
}

project(":ios") {
    apply plugin: "java-library"
    apply plugin: "robovm"

    //publish on app store (iOS)
    configurations {natives}

    dependencies {
        ...

        //robopods
        implementation "com.mobidevelop.robovm:robopods-google-mobile-ads-ios:2.2.3"
    }


    //publish on app store (iOS)
    robovm {
        // Configure robovm
        iosSignIdentity = "Apple Distribution: XXXXXX XXX (XXXXXXXXX)"
        iosProvisioningProfile = "XXXX XXXX"
        iosSkipSigning = false
        arch = "arm64"
        stdoutFifo = ""
        stderrFifo = ""
    }
}

I downloaded the admob ios SDK from here: https://developers.google.com/admob/ios/download

I unzipped file and added the sdk to folders inside ios folder in my project.

I created libs, arm_libs and sim_libs in the ios folder.

I then copy and pasted all the .xcframework files (in my download folder) into the libs folder. Then I copy and paste from my download folder the .framework files within the .xcframework folder into the arms_libs and sim_libs folder.

In the Info.plist.xml I add my admob as follows:

<key>GADApplicationIdentifier</key>
    <string>ca-app-pub-xxxxxxxxxxxxxxx~xxxxxxxxx</string>

    <key>SKAdNetworkIdentifier</key>
    <string>cstr6suwn9.skadnetwork</string>

In the robovm.xml file I add the following:

<frameworkPaths>
    <path>libs</path>
    <path variant="device">arm_libs</path>
    <path variant="simulator">sim_libs</path>
  </frameworkPaths>

<frameworks>
....
<!--    googleMobileAdsASKiOS 9.5.0-->
    <framework>GoogleAppMeasurement</framework>
    <framework>GoogleMobileAds</framework>
    <framework>GoogleUtilities</framework>
    <framework>nanopb</framework>
    <framework>PromisesObjC</framework>
    <framework>UserMessagingPlatform</framework>
    <framework>GoogleAppMeasurementIdentitySupport</framework>

  </frameworks>

Then I launch in my physical device (iPhone 8) and I get the following error:

[ERROR] 14:44:17.979 Undefined symbols for architecture arm64:
[ERROR] 14:44:17.980   "_OBJC_CLASS_$_GADInterstitial", referenced from:
[ERROR] 14:44:17.981       objc-class-ref in libGGLAdMob.a(GGLContext+AdMob.o)
[ERROR] 14:44:18.114      (maybe you meant: _OBJC_CLASS_$_GADInterstitialAd)
[ERROR] 14:44:18.157 ld: symbol(s) not found for architecture arm64
[ERROR] 14:44:18.180 clang: error: linker command failed with exit code 1 (use -v to see invocation)
[ERROR] Couldn't compile app
....

I have tried many different solutions I have found online, but nothing seems to work. Any help would be greatly appreciated. Thank you!

2

There are 2 best solutions below

0
dkimitsa On

UPDATE: root case is com.mobidevelop.robovm:robopods-google-mobile-ads-ios it depends on com.mobidevelop.robovm:robopods-google-apis-ios and this artefact contains native library libGGLCore.a that exposes these missing dependency. There is no source for this library and its from 2016 when RoboVM was closed by MS. You should not use these bindings as these are not updated. Consider using alt-pods as more recent and being updated (by me)

similar issue was asked on MobiVM gitter channel. there are few moments:

  • Firebase.zip (9.3.0) that contains Google-Mobile-Ads-SDK 9.7.0 has no references either to libGGLAdMob.a or _OBJC_CLASS_$_GADInterstitial. You can check this by searching through binaries or using nm tool on GAD framework;
  • com.mobidevelop.robovm:robopods-google-mobile-ads-ios is quite outdated.

As a root case there is a chance that wrong framework is used (e.g. old one).
As a quick way to test here is a sample project that uses alt-pods bindings(in general more recent) https://github.com/dkimitsa/alt-pods-tests/tree/master/firebase-google-ads

0
SidHunt On

Found a solution on reddit. Mobile Ads IOS sdk 8+ has breaking changes and robopods is not compatible with this. Use sdk 7.42.0 from here https://github.com/CocoaPods/Specs/blob/master/Specs/5/9/a/Google-Mobile-Ads-SDK/7.42.2/Google-Mobile-Ads-SDK.podspec.json#L40

Credits to the solution posted on reddit here https://www.reddit.com/r/libgdx/comments/oo32h1/build_error_on_ios_updating_to_the_latest_version/