Trying to integrate Google AdMob in libgdx game on iOS results in "framework not found GoogleUtilities"

717 Views Asked by At

I want to include google ads into my libgdx game. In android this is working straightforward. However in iOS there are some complications:

I updated the Info.plist.xml file with my ad-identifier. Then I added the following entries to the robovm.xml file:

into the <frameworks> element:

<!--AdMob-->
<framework>GoogleAppMeasurement</framework>
<framework>GoogleMobileAds</framework>
<framework>GoogleUtilities</framework>
<framework>nanopb</framework>

before the <frameworks> element:

<frameworkPaths>
    <path>libs</path>
</frameworkPaths>

In the main gradle.build file I added an entry allProjects.ext.robopodsVersion = "2.2.3" and added into the iOS project section implementation "com.mobidevelop.robovm:robopods-google-mobile-ads-ios:$robopodsVersion" so this section looks like this:

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


    dependencies {
        implementation project(":core")
        implementation "com.mobidevelop.robovm:robopods-google-mobile-ads-ios:$robopodsVersion"
        api "com.mobidevelop.robovm:robovm-rt:$roboVMVersion"
        api "com.mobidevelop.robovm:robovm-cocoatouch:$roboVMVersion"
        api "com.badlogicgames.gdx:gdx-backend-robovm:$gdxVersion"
        api "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-ios"
        api "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-ios"

    }
}

Then I downloaded the googlemobileadssdkios.zip file and put its contents under libs folder in the iOS project. The contents under ios/libs look like this:

|- nanopb.xcframework
    |- Info.plist
    |- ios-armv7_arm64
        |- ...
    |- ios-i386_x86_64-simulator
        |- ...
    |- ios-x86_64-maccatalyst
        |- ...
|- PromisesObjC.xcframework
    |- Info.plist
    |- ios-armv7_arm64
        |- ...
    |- ios-i386_x86_64-simulator
        |- ...
    |- ios-x86_64-maccatalyst
        |- ...
|- Licenses
    |- ...
|- GoogleUtilities.xcframework
    |- Info.plist
    |- ios-armv7_arm64
        |- ...
    |- ios-i386_x86_64-simulator
        |- ...
    |- ios-x86_64-maccatalyst
        |- ...
|- GoogleMobileAds.framework
    |- GoogleMobileAds
        |- ...
    |- Headers
        |- ...
    |- Modules
        |- ...
|- GoogleAppMeasurement.framework
    |- GoogleAppMeasurement
        |- ...
    |- Modules
        |- ...

So summarised: under each .xcframework directory there are, besides this Info.plist file, the directories os-armv7_arm64, ios-i386_x86_64-simulator and ios-x86_64-maccatalyst.

When I try to run the app on the simulator from Android Studio (using the robovm android studio plugin idea-2.3.10-SNAPSHOT.zip) I get the following error:

[ERROR] 09:12:34.831 ld: framework not found GoogleUtilities
[ERROR] 09:12:34.832 clang: error: linker command failed with exit code 1 (use -v to see invocation)
[ERROR] Couldn't compile app

I had the suspicion that this has something to do with the xcframework that are used by GoogeUtilities and was assured by the open issue https://github.com/MobiVM/robovm/issues/468 which basically tells that there is currently no support for xcframworks, but linking to issue https://github.com/MobiVM/robovm/pull/483 which is describing with little words that now a variant can be specified in the element of the <frameworkPaths> element.

The question for me is now: how to proceed with the libs and how to define path variants so that it can run both in a iOS device and in the simulator?

1

There are 1 best solutions below

0
michaeak On

This solved the problem for me:

In the robovm.xml file replace the <frameworkPaths> element with the following part:

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

Note that (also in the robovm.xml file) in the frameworks section for me the following part had to be added:

<framework>PromisesObjC</framework>

Using the shell in ios subproject create two directories: arm_libs and sim_libs

Go into arm_libs directory and execute the following commands:

cp -r ../libs/GoogleUtilities.xcframework/ios-armv7_arm64/GoogleUtilities.framework .
cp -r ../libs/GoogleAppMeasurement.framework .    
cp -r ../libs/GoogleMobileAds.framework .     
cp -r ../libs/PromisesObjC.xcframework/ios-armv7_arm64/PromisesObjC.framework .
cp -r ../libs/nanopb.xcframework/ios-armv7_arm64/nanopb.framework .            
cp -r ../libs/Licenses . 

Go into sim_libs directory and execute the following commands:

cp -r ../libs/GoogleUtilities.xcframework/ios-i386_x86_64-simulator/GoogleUtilities.framework .
cp -r ../libs/GoogleAppMeasurement.framework .                                                 
cp -r ../libs/GoogleMobileAds.framework .     
cp -r ../libs/Licenses .
cp -r ../libs/PromisesObjC.xcframework/ios-i386_x86_64-simulator/PromisesObjC.framework .
cp -r ../libs/nanopb.xcframework/ios-i386_x86_64-simulator/nanopb.framework .

This gives the following structure:

|- arm_libs
    |- GoogleAppMeasurement.framework
        |- ...
    |- GoogleMobileAds.framework
        |- ...
    |- GoogleUtilities.framework
        |- ...
    |- Licenses
        |- ...
    |- PromisesObjC.framework
        |- ...
    |- nanopb.framework
        |- ...
|- sim_libs
    |- GoogleAppMeasurement.framework
        |- ...
    |- GoogleMobileAds.framework
        |- ...
    |- GoogleUtilities.framework
        |- ...
    |- Licenses
        |- ...
    |- PromisesObjC.framework
        |- ...
    |- nanopb.framework
        |- ...

Now running in simulator and on iPhone works for me.