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?
This solved the problem for me:
In the
robovm.xmlfile replace the<frameworkPaths>element with the following part:Note that (also in the
robovm.xmlfile) in theframeworkssection for me the following part had to be added:Using the shell in ios subproject create two directories:
arm_libsandsim_libsGo into
arm_libsdirectory and execute the following commands:Go into
sim_libsdirectory and execute the following commands:This gives the following structure:
Now running in simulator and on iPhone works for me.