无法在我的应用中添加广告

时间:2015-02-07 16:17:31

标签: android libgdx ads

我一直在尝试在libgdx中向我的应用添加广告时遇到很大问题。我到处寻找解决方案,但没有运气。我不知道它是我的模拟器还是我的应用程序。我仍然有点新编码所以我可能犯了一些愚蠢的错误!提前谢谢!

编辑:将我的模拟器更改为genymotion,我现在收到一个不同的错误, Logcat是:

02-08 01:55:50.994: D/dalvikvm(1332): GC_CONCURRENT freed 369K, 5% free 8800K/9200K, paused 2ms+0ms, total 8ms
02-08 01:55:51.002: I/dalvikvm(1332): Could not find method android.webkit.WebView.evaluateJavascript, referenced from method com.google.android.gms.internal.gu.evaluateJavascript
02-08 01:55:51.002: W/dalvikvm(1332): VFY: unable to resolve virtual method 1096: Landroid/webkit/WebView;.evaluateJavascript (Ljava/lang/String;Landroid/webkit/ValueCallback;)V
02-08 01:55:51.002: D/dalvikvm(1332): VFY: replacing opcode 0x6f at 0x0016
02-08 01:55:51.174: I/dalvikvm(1332): Failed resolving Lcom/simplegames/TweenAccessors/SpriteAccessor; interface 252 'Laurelienribon/tweenengine/TweenAccessor;'
02-08 01:55:51.174: W/dalvikvm(1332): Link of class 'Lcom/simplegames/TweenAccessors/SpriteAccessor;' failed
02-08 01:55:51.174: E/dalvikvm(1332): Could not find class 'com.simplegames.TweenAccessors.SpriteAccessor', referenced from method com.simplegames.screens.SplashScreen.setupTween
02-08 01:55:51.174: W/dalvikvm(1332): VFY: unable to resolve new-instance 4737 (Lcom/simplegames/TweenAccessors/SpriteAccessor;) in Lcom/simplegames/screens/SplashScreen;
02-08 01:55:51.174: D/dalvikvm(1332): VFY: replacing opcode 0x22 at 0x0003
02-08 01:55:51.174: I/dalvikvm(1332): Could not find method aurelienribon.tweenengine.TweenManager.update, referenced from method com.simplegames.screens.SplashScreen.render
02-08 01:55:51.174: W/dalvikvm(1332): VFY: unable to resolve virtual method 1215: Laurelienribon/tweenengine/TweenManager;.update (F)V
02-08 01:55:51.174: D/dalvikvm(1332): VFY: replacing opcode 0x6e at 0x0004
02-08 01:55:51.174: I/dalvikvm(1332): Failed resolving Lcom/simplegames/TweenAccessors/SpriteAccessor; interface 252 'Laurelienribon/tweenengine/TweenAccessor;'
02-08 01:55:51.174: W/dalvikvm(1332): Link of class 'Lcom/simplegames/TweenAccessors/SpriteAccessor;' failed
02-08 01:55:51.174: D/dalvikvm(1332): DexOpt: unable to opt direct call 0x8ef0 at 0x05 in Lcom/simplegames/screens/SplashScreen;.setupTween
02-08 01:55:51.174: D/dalvikvm(1332): DexOpt: unable to opt direct call 0x04be at 0x0d in Lcom/simplegames/screens/SplashScreen;.setupTween
02-08 01:55:51.174: I/dalvikvm(1332): Failed resolving Lcom/simplegames/screens/SplashScreen$1; interface 253 'Laurelienribon/tweenengine/TweenCallback;'
02-08 01:55:51.174: W/dalvikvm(1332): Link of class 'Lcom/simplegames/screens/SplashScreen$1;' failed
02-08 01:55:51.174: D/dalvikvm(1332): DexOpt: unable to opt direct call 0x8fa6 at 0x14 in Lcom/simplegames/screens/SplashScreen;.setupTween
02-08 01:55:51.174: I/dalvikvm(1332): DexOpt: unable to optimize static field ref 0x0061 at 0x26 in Lcom/simplegames/screens/SplashScreen;.setupTween
02-08 01:55:51.178: D/dalvikvm(1332): GC_CONCURRENT freed 327K, 4% free 8861K/9216K, paused 2ms+0ms, total 5ms
02-08 01:55:51.182: W/dalvikvm(1332): threadid=10: thread exiting with uncaught exception (group=0xa6190908)
02-08 01:55:51.182: E/AndroidRuntime(1332): FATAL EXCEPTION: GLThread 107
02-08 01:55:51.182: E/AndroidRuntime(1332): java.lang.NoClassDefFoundError: com.simplegames.TweenAccessors.SpriteAccessor
02-08 01:55:51.182: E/AndroidRuntime(1332):     at com.simplegames.screens.SplashScreen.setupTween(SplashScreen.java:47)
02-08 01:55:51.182: E/AndroidRuntime(1332):     at com.simplegames.screens.SplashScreen.show(SplashScreen.java:42)
02-08 01:55:51.182: E/AndroidRuntime(1332):     at com.badlogic.gdx.Game.setScreen(Game.java:61)
02-08 01:55:51.182: E/AndroidRuntime(1332):     at com.simplegames.dinobird.DBGame.create(DBGame.java:12)
02-08 01:55:51.182: E/AndroidRuntime(1332):     at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:241)
02-08 01:55:51.182: E/AndroidRuntime(1332):     at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1505)
02-08 01:55:51.182: E/AndroidRuntime(1332):     at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
02-08 01:55:51.250: I/AndroidInput(1332): sensor listener tear down
02-08 01:55:51.250: I/AndroidGraphics(1332): Managed meshes/app: { }
02-08 01:55:51.250: I/AndroidGraphics(1332): Managed textures/app: { }
02-08 01:55:51.250: I/AndroidGraphics(1332): Managed cubemap/app: { }
02-08 01:55:51.250: I/AndroidGraphics(1332): Managed shaders/app: { }
02-08 01:55:51.250: I/AndroidGraphics(1332): Managed buffers/app: { }

我的宣言:

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.simplegames.dinobird.android"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="21" />
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/GdxTheme" >
        <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>
        <activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
        <activity
            android:name="com.simplegames.dinobird.android.AndroidLauncher"
            android:label="@string/app_name" 
            android:screenOrientation="portrait"
            android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

最后我的AndroidLauncher:

    package com.simplegames.dinobird.android;

import android.app.Dialog;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;

import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
import com.simplegames.dinobird.DBGame;

public class AndroidLauncher extends AndroidApplication {

    private static final String GOOGLE_PLAY_URL = "https://play.google.com/store/apps/developer?id=SimpleGames1.0";
      protected AdView adView;
      protected View gameView;

    @Override
    protected void onCreate (Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
        cfg.useAccelerometer = false;
        cfg.useCompass = false;

        // Do the stuff that initialize() would do for you
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

        RelativeLayout layout = new RelativeLayout(this);
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
        layout.setLayoutParams(params);

        AdView admobView = createAdView();
        layout.addView(admobView);
        View gameView = createGameView(cfg);
        layout.addView(gameView);

        setContentView(layout);
        startAdvertising(admobView);
      }

      private AdView createAdView() {
        adView = new AdView(this);
        adView.setAdSize(AdSize.SMART_BANNER);
        adView.setAdUnitId("@sting/banner_ad_unit_id");
        adView.setId(12345); // this is an arbitrary id, allows for relative positioning in createGameView()
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        params.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
        params.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
        adView.setLayoutParams(params);
        adView.setBackgroundColor(Color.BLACK);
        return adView;
      }

      private View createGameView(AndroidApplicationConfiguration cfg) {
        gameView = initializeForView(new DBGame(), cfg);
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
        params.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
        params.addRule(RelativeLayout.BELOW, adView.getId());
        gameView.setLayoutParams(params);
        return gameView;
      }

      private void startAdvertising(AdView adView) {
        AdRequest adRequest = new AdRequest.Builder().build();
        adView.loadAd(adRequest);
      }

      @Override
      public void onResume() {
        super.onResume();
        if (adView != null) adView.resume();
      }

      @Override
      public void onPause() {
        if (adView != null) adView.pause();
        super.onPause();
      }

      @Override
      public void onDestroy() {
        if (adView != null) adView.destroy();
        super.onDestroy();
      }

      @Override
      public void onBackPressed() {
        final Dialog dialog = new Dialog(this);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

        LinearLayout ll = new LinearLayout(this);
        ll.setOrientation(LinearLayout.VERTICAL);

        Button b1 = new Button(this);
        b1.setText("Quit");
        b1.setOnClickListener(new OnClickListener() {
          public void onClick(View v) {
            finish();
          }
        });
        ll.addView(b1);

        Button b2 = new Button(this);
        b2.setText("TheInvader360");
        b2.setOnClickListener(new OnClickListener() {
          public void onClick(View v) {
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(GOOGLE_PLAY_URL)));
            dialog.dismiss();
          }
        });
        ll.addView(b2);

        dialog.setContentView(ll);
        dialog.show();
      }
    }

2 个答案:

答案 0 :(得分:0)

我认为问题在于:“com.simplegames.TweenAccessors.SpriteAccessor” 尝试更改此文件的位置。

在此处获取更详细的信息:NoClassDefFoundError - Eclipse and Android

答案 1 :(得分:0)

修复,右键单击我的android项目,将鼠标悬停在android工具上,然后单击修复项目属性。