I am implementing admob in my iOS module using this guide.
I have a view controller where my interstitial ads are initialized like this
@CustomClass
public class ViewController extends UIViewController implements ActionResolver {
private GADInterstitial interstitial;
private static final String AD_UNIT_ID = "ca-app-pub-XXXXXXXXXXXXXXXX-XXXXXXXXXX";
public ViewController() {
viewDidLoad();
}
@Override
public void viewDidLoad() {
super.viewDidLoad();
interstitial = createAndLoadInterstitial();
}
private GADInterstitial createAndLoadInterstitial() {
//Ad Unit ID of your interstital, from adMob account.
GADInterstitial interstitial = new GADInterstitial(AD_UNIT_ID);
System.out.println("Add unit ID is " + AD_UNIT_ID);
interstitial.setDelegate(new GADInterstitialDelegateAdapter() {
@Override
public void didDismissScreen(GADInterstitial ad) {
ViewController.this.interstitial = createAndLoadInterstitial();
}
});
interstitial.loadRequest(createRequest());
return interstitial;
}
private GADRequest createRequest() {
GADRequest request = new GADRequest();
// To test on your devices, add their UDIDs here:
request.setTestDevices(Arrays.asList(GADRequest.getSimulatorID()));
return request;
}
@IBAction
public void showInterstitialAd() {
if (interstitial.isReady()) {
interstitial.present(UIApplication.getSharedApplication().getKeyWindow().getRootViewController());
System.out.println("Interstitial is loaded.");
} else {
interstitial.loadRequest(createRequest());
System.out.println("Interstitial not ready!");
}
}
}
My implementation is similar to this guide also.
When I run my app on the simulator I get the following exception.
org.robovm.objc.ObjCClassNotFoundException: GADInterstitial
at org.robovm.objc.ObjCClass.getByType(ObjCClass.java:251)
at org.robovm.objc.ObjCClass.getFromObject(ObjCClass.java:212)
at org.robovm.objc.ObjCObject.getObjCClass(ObjCObject.java:161)
at org.robovm.apple.foundation.NSObject.alloc(NSObject.java:214)
at org.robovm.objc.ObjCObject.<init>(ObjCObject.java:79)
at org.robovm.apple.foundation.NSObject.<init>(NSObject.java:157)
at org.robovm.pods.google.mobileads.GADInterstitial.<init>(GADInterstitial.java:52)
at com.nauv.fut.simulator.ViewController.createAndLoadInterstitial(ViewController.java:39)
at com.nauv.fut.simulator.ViewController.viewDidLoad(ViewController.java:34)
at com.nauv.fut.simulator.ViewController.<init>(ViewController.java:27)
at com.nauv.fut.simulator.IOSLauncher.createApplication(IOSLauncher.java:30)
at com.badlogic.gdx.backends.iosrobovm.IOSApplication$Delegate.didFinishLaunching(IOSApplication.java:65)
at com.badlogic.gdx.backends.iosrobovm.IOSApplication$Delegate.$cb$application$didFinishLaunchingWithOptions$(IOSApplication.java)
at org.robovm.apple.uikit.UIApplication.main(Native Method)
at org.robovm.apple.uikit.UIApplication.main(UIApplication.java:413)
at com.nauv.fut.simulator.IOSLauncher.main(IOSLauncher.java:35)
I have imported the admob framework on my ios build.gradle. I have also tried moving it to ios module in main build.gradle though this doesnt change anything. How can I fix this error? My class is being imported correctly and I am using project.ext.robopodsVersion = "1.14.0" on my app build.gradle.
Fortunately some people forked the project and I have found a working solution :)
The fork : https://github.com/MobiDevelop/robovm-robopods
I did the following.
Gradle:
Build script dependency
dependencies {
...
classpath 'com.mobidevelop.robovm:robovm-gradle-plugin:2.2.0-SNAPSHOT'
}
IOS Project dependencies:
...
compile "com.mobidevelop.robovm:robopods-google-mobile-ads-parent:2.2.0-SNAPSHOT"
compile "com.mobidevelop.robovm:robopods-google-mobile-ads-ios:2.2.0-SNAPSHOT"
compile "com.mobidevelop.robovm:robovm-rt:2.2.0-SNAPSHOT"
compile "com.mobidevelop.robovm:robovm-cocoatouch:2.2.0-SNAPSHOT"
Download SDK from here
Copy the GoogleMobileAds.framework folder in ios/libs
Modify the robovm.xml file (I went completely overkill on the frameworks list but I was tired of compilation error, if you find the ones that are not necessary, feel free to let me know):
<config>
...
<frameworkPaths>
<path>libs</path>
</frameworkPaths>
<frameworks>
<framework>UIKit</framework>
<framework>OpenGLES</framework>
<framework>QuartzCore</framework>
<framework>CoreGraphics</framework>
<framework>OpenAL</framework>
<framework>AudioToolbox</framework>
<framework>AVFoundation</framework>
<framework>AdSupport</framework>
<framework>AudioToolbox</framework>
<framework>CoreMedia</framework>
<framework>CoreMotion</framework>
<framework>CoreVideo</framework>
<framework>CoreTelephony</framework>
<framework>CoreBluetooth</framework>
<framework>SafariServices</framework>
<framework>EventKit</framework>
<framework>EventKitUI</framework>
<framework>MediaPlayer</framework>
<framework>MessageUI</framework>
<framework>StoreKit</framework>
<framework>SystemConfiguration</framework>
<framework>GoogleMobileAds</framework>
<framework>VideoToolbox</framework>
<framework>GLKit</framework>
</frameworks>
</config>
And this works (for me)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With