菜鸟教程小白 发表于 2022-12-13 17:00:16

ios - ROBOVM + robopods + admob ios 绑定(bind)


                                            <p><p>我尝试使用 <a href="https://github.com/robovm/robovm-robopods/tree/master/google-mobile-ads" rel="noreferrer noopener nofollow">this</a> 绑定(bind)我的项目但是我没有实现,所以我收到了类似的错误
<strong>noClassDefFoundFor NSObject</strong></p>

<p>我也尝试添加旧版本
即<a href="https://github.com/BlueRiverInteractive/robovm-ios-bindings" rel="noreferrer noopener nofollow">this</a>但在这里我无法将 admob 模块链接到我的 ios 模块错误,在这种情况下我得到的是:
<strong>未找到“默认”的配置</strong></p>

<p>我正在使用最新版本的 LibGDX。</p>

<p>日志片段:</p>

<pre><code>ava.lang.NoClassDefFoundError: org/robovm/apple/foundation/NSObject$Handle
at org.robovm.pods.google.mobileads.GADRequest.&lt;init&gt;(GADRequest.java)
at com.blurpixel.arcpop.ViewController.createAndLoadBanner(ViewController.java)
at com.blurpixel.arcpop.ViewController.intializeAds(ViewController.java)
at com.blurpixel.arcpop.ViewController.showAds(ViewController.java)
at com.blurpixel.arcpop.Menu.show(Menu.java)
at com.badlogic.gdx.Game.setScreen(Game.java)
at com.blurpixel.arcpop.GameClass.create(GameClass.java)
at com.badlogic.gdx.backends.iosrobovm.IOSGraphics.draw(IOSGraphics.java)
at com.badlogic.gdx.backends.iosrobovm.IOSGraphics$1.draw(IOSGraphics.java)
at com.badlogic.gdx.backends.iosrobovm.IOSGraphics$1.$cb$drawRect$(IOSGraphics.java)
at org.robovm.apple.uikit.UIApplication.main(Native Method)
at org.robovm.apple.uikit.UIApplication.main(UIApplication.java)
at com.blurpixel.arcpop.IOSLauncher.main(IOSLauncher.java)
</code></pre>

<p>我在我的代码中所做的是:</p>

<pre><code> adView = new GADBannerView(GADAdSize.SmartBannerPortrait());
    adView.setAdUnitID(&#34;xxxxxxxxxxxxxxx&#34;);
    adView.setRootViewController(UIApplication.getSharedApplication().getKeyWindow().getRootViewController());
    UIApplication.getSharedApplication().getKeyWindow().getRootViewController().getView().addSubview(adView);

    GADRequest request = new GADRequest();//this line is creating this error if i am commenting this line + the adview.loadAd line i am getting my game running without ads.
   request.setTestDevices(Arrays.asList(GADRequest.getSimulatorID()));
    adView.setDelegate(new GADBannerViewDelegateAdapter() {
      @Override
      public void didReceiveAd(GADBannerView view) {
            super.didReceiveAd(view);
      }
      @Override
      public void didFailToReceiveAd(GADBannerView view, GADRequestError error) {
            super.didFailToReceiveAd(view, error);
            System.out.println(&#34;Failed to recieve &#34;);
      }
    });
    adView.loadRequest(request);
</code></pre>

<p>Gradle 文件:</p>

<p>ios 分级:</p>

<pre><code>    sourceSets.main.java.srcDirs = [&#34;src/&#34;]
sourceCompatibility = &#39;1.7&#39;
*.options*.encoding = &#39;UTF-8&#39;
ext {
    mainClassName = &#34;com.blurpixel.arcpop.IOSLauncher&#34;
}
launchIPhoneSimulator.dependsOn build
launchIPadSimulator.dependsOn build
launchIOSDevice.dependsOn build
createIPA.dependsOn build
eclipse.project {
    name = appName + &#34;-ios&#34;
    natures &#39;org.robovm.eclipse.RoboVMNature&#39;
}
dependencies {

    compile &#34;org.robovm:robopods-google-mobile-ads-ios:1.13.1-SNAPSHOT&#34;
    compile &#34;org.robovm:robopods-google-apis-ios:1.13.1-SNAPSHOT&#34;
}
</code></pre>

<p>build.gradle:</p>

<pre><code>    buildscript {
    repositories {
      mavenCentral()
      maven { url &#34;https://oss.sonatype.org/content/repositories/snapshots/&#34; }
      jcenter()
    }


    dependencies {
      classpath &#39;de.richsource.gradle.plugins:gwt-gradle-plugin:0.6&#39;
      classpath &#39;com.android.tools.build:gradle:2.1.2&#39;
      classpath &#39;com.mobidevelop.robovm:robovm-gradle-plugin:2.2.0-SNAPSHOT&#39;
    }
}
allprojects {
    apply plugin: &#34;eclipse&#34;
    apply plugin: &#34;idea&#34;

    version = &#39;1.2&#39;
    ext {
      appName = &#34;ArcPOP&#34;
      gdxVersion = &#39;1.9.2&#39;
      roboVMVersion = &#39;1.14.0&#39;
      robopodsVersion = &#39;1.13.1&#39;
      box2DLightsVersion = &#39;1.4&#39;
      ashleyVersion = &#39;1.7.0&#39;
      aiVersion = &#39;1.8.0&#39;
      admobVersion = &#39;9.0.1&#39;
    }

    repositories {
      mavenCentral()
      maven { url &#34;https://oss.sonatype.org/content/repositories/snapshots/&#34; }
      maven { url &#34;https://oss.sonatype.org/content/repositories/releases/&#34; }
    }
}
project(&#34;:desktop&#34;) {
    apply plugin: &#34;java&#34;


    dependencies {
      compile project(&#34;:core&#34;)
      compile &#34;com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion&#34;
      compile &#34;com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop&#34;
      compile &#34;com.badlogicgames.gdx:gdx-tools:$gdxVersion&#34;
      compile &#34;com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop&#34;
      compile &#34;com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop&#34;
    }
}
project(&#34;:android&#34;) {
    apply plugin: &#34;android&#34;

    configurations { natives }

    dependencies {
      compile project(&#34;:core&#34;)

      compile &#34;com.badlogicgames.gdx:gdx-backend-android:$gdxVersion&#34;
      natives &#34;com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi&#34;
      natives &#34;com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a&#34;
      natives &#34;com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-arm64-v8a&#34;
      natives &#34;com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86&#34;
      natives &#34;com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86_64&#34;
      compile &#34;com.badlogicgames.gdx:gdx-freetype:$gdxVersion&#34;
      natives &#34;com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi&#34;
      natives &#34;com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi-v7a&#34;
      natives &#34;com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-arm64-v8a&#34;
      natives &#34;com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86&#34;
      natives &#34;com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86_64&#34;
      compile &#34;com.badlogicgames.gdx:gdx-box2d:$gdxVersion&#34;
      natives &#34;com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi&#34;
      natives &#34;com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi-v7a&#34;
      natives &#34;com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-arm64-v8a&#34;
      natives &#34;com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86&#34;
      natives &#34;com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86_64&#34;

      compile &#39;com.google.android.gms:play-services-ads:9.0.1&#39;
      compile &#39;com.facebook.android:facebook-android-sdk:4.1.0&#39;

    }
}
project(&#34;:ios&#34;) {
    apply plugin: &#34;java&#34;
    apply plugin: &#34;robovm&#34;


    dependencies {
      compile project(&#34;:core&#34;)
      compile &#34;org.robovm:robovm-rt:$roboVMVersion&#34;
      compile &#34;org.robovm:robovm-cocoatouch:$roboVMVersion&#34;
      compile &#34;org.robovm:robopods-google-mobile-ads-ios:$robopodsVersion-SNAPSHOT&#34;
      compile &#34;org.robovm:robopods-google-apis-ios:$robopodsVersion-SNAPSHOT&#34;
      compile &#34;com.badlogicgames.gdx:gdx-backend-robovm:$gdxVersion&#34;
      compile &#34;com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-ios&#34;
      compile &#34;com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-ios&#34;
      compile &#34;com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-ios&#34;
    }
}
project(&#34;:html&#34;) {
    apply plugin: &#34;gwt&#34;
    apply plugin: &#34;war&#34;
    dependencies {
      compile project(&#34;:core&#34;)
      compile &#34;com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion&#34;
      compile &#34;com.badlogicgames.gdx:gdx:$gdxVersion:sources&#34;
      compile &#34;com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion:sources&#34;
      compile &#34;com.badlogicgames.gdx:gdx-box2d:$gdxVersion:sources&#34;
      compile &#34;com.badlogicgames.gdx:gdx-box2d-gwt:$gdxVersion:sources&#34;
    }
}
project(&#34;:core&#34;) {
    apply plugin: &#34;java&#34;


    dependencies {
      compile &#34;com.badlogicgames.gdx:gdx:$gdxVersion&#34;
      compile &#34;com.badlogicgames.gdx:gdx-freetype:$gdxVersion&#34;
      compile &#34;com.badlogicgames.gdx:gdx-box2d:$gdxVersion&#34;
    }
}
tasks.eclipse.doLast {
    delete &#34;.project&#34;
}
dependencies {
}
</code></pre>

<p>请提前帮助和感谢。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>问题出在您的 gradle 文件中。首先,您将 mobidevelop 插件与官方 robovm 一起使用。这可能会带来问题。</p>

<p>那么您将在 2 个地方添加依赖项。这不应该做任何坏事,但它不是必需的,如果您更改其中一个可能会导致问题。</p>

<p>应用以下更改,重建 gradle(不要忘记 --refresh-dependencies)并重建您的项目。如果仍然失败,请再次清除缓存。</p>

<p>改变:</p>

<pre><code>classpath &#39;com.mobidevelop.robovm:robovm-gradle-plugin:2.2.0-SNAPSHOT&#39;      
</code></pre>

<p>到</p>

<pre><code>classpath &#39;org.robovm:robovm-gradle-plugin:1.14.0&#39;
</code></pre>

<p>和</p>

<pre><code>robopodsVersion = &#39;1.13.1&#39;
</code></pre>

<p>到</p>

<pre><code>robopodsVersion = &#39;1.14.0&#39;
</code></pre>

<p>可能还需要改变:</p>

<pre><code>gdxVersion = &#39;1.9.2&#39;
</code></pre>

<p>到</p>

<pre><code>gdxVersion = &#39;1.9.0&#39;
</code></pre>

<p>您可能还需要从 robopod 版本中删除“-SNAPSHOT”。不是 100% 确定它们存在(如果你想要这些)</p>

<p>删除:</p>

<pre><code>dependencies {

    compile &#34;org.robovm:robopods-google-mobile-ads-ios:1.13.1-SNAPSHOT&#34;
    compile &#34;org.robovm:robopods-google-apis-ios:1.13.1-SNAPSHOT&#34;
}
</code></pre>

<p>来自 ios build.gradle(这些区域已经在你的 main build.gradle 中定义)</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - ROBOVM &#43; robopods &#43; admob ios 绑定(bind),我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/37917578/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/37917578/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - ROBOVM &#43; robopods &#43; admob ios 绑定(bind)