为什么我会收到ObjCClassNotFoundException:RoboVM中的GADInterstitial?

时间:2016-05-17 10:39:06

标签: ios admob robovm

我正在使用this guide.

在我的iOS模块中实现admob

我有一个视图控制器,我的插页式广告就像这样初始化

@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!");
    }
}

}

我的实现也类似于this guide

当我在模拟器上运行我的应用程序时,我得到以下异常。

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)

我在ios build.gradle上导入了admob框架。我也尝试将它移动到main build.gradle中的ios模块,尽管这并没有改变任何东西。我该如何解决这个错误?我的类正在正确导入,我在app build.gradle上使用project.ext.robopodsVersion = "1.14.0"

1 个答案:

答案 0 :(得分:1)

幸运的是,有些人分配了这个项目,我找到了一个可行的解决方案:)

分叉:https://github.com/MobiDevelop/robovm-robopods

我做了以下事情。

摇篮:

构建脚本依赖

dependencies {
    ...
    classpath 'com.mobidevelop.robovm:robovm-gradle-plugin:2.2.0-SNAPSHOT'
}

IOS项目依赖关系:

...
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"

here

下载SDK

复制ios / libs中的GoogleMobileAds.framework文件夹

修改robovm.xml文件(我在框架列表上完全过度,但我厌倦了编译错误,如果你发现那些不必要的,请随时告诉我) :

<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>

这适用于(对我而言)