无法在使用AndEngine开发的游戏中显示Admobs横幅广告

时间:2016-06-01 07:00:29

标签: android admob andengine

我制作了游戏并整合了广告代码广告代码,但是,我在下面发布了以下错误。

E/AndroidRuntime(12583): FATAL EXCEPTION: main
E/AndroidRuntime(12583): Process: ninja.anteprocess.com.hakaishin, PID: 12583
E/AndroidRuntime(12583): java.lang.NoClassDefFoundError: org.andengine.util.debug.Debug$DebugLevel
E/AndroidRuntime(12583):    at org.andengine.util.debug.Debug.<clinit>(Debug.java:25)
E/AndroidRuntime(12583):    at org.andengine.ui.activity.BaseGameActivity.onCreate(BaseGameActivity.java:73)
E/AndroidRuntime(12583):    at android.app.Activity.performCreate(Activity.java:5245)
E/AndroidRuntime(12583):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)

问题应该与multidex有关,因此,在gradle文件中设置“multiDexEnabled true”,但仍然会收到错误。

您认为我的代码有问题吗?我已经发布了以下代码的一些部分供大家查看,但是,我找不到这个问题的问题。如果stackflow的一些专业人员能给我一些帮助,那就太好了!我很乐意听到你的消息!

MainActivity extends MultiSceneActivity

   @Override
    protected Scene onCreateScene() {

        adView = (AdView)findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();
        adView.loadAd(adRequest);

        ResourceUtil.getInstance(this).resetAllTexture();
        SoundFactory.setAssetBasePath("mfx/");
        //For the Music
        MusicFactory.setAssetBasePath("mfx/");
        SplashScene initialScene = new SplashScene(this);
        getSceneArray().add(initialScene);
        return initialScene;
    }
Added the following code in the Manifest File

 <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

<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"
            android:theme="@android:style/Theme.Translucent"/>
MainActivity's layout

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <org.andengine.opengl.view.RenderSurfaceView
        android:id="@+id/renderview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="bottom|center"
        android:orientation="vertical" >

        <com.google.android.gms.ads.AdView
            android:id="@+id/adView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            ads:adSize="BANNER"
            ads:adUnitId="@string/banner_ad_unit_id" >
        </com.google.android.gms.ads.AdView>

    </LinearLayout>

Gradle file 

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    packagingOptions {
        exclude 'project.properties'
        exclude 'bin/AndroidManifest.xml'
    }

    defaultConfig {
        applicationId "com.sample.test"
        minSdkVersion 11
        targetSdkVersion 13
        versionCode 2
        versionName "1.1"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile files('libs/AndEngine.jar')
    compile files('libs/android-support-v4.jar')
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:support-v4:23.4.0'
    compile 'com.google.android.gms:play-services:9.0.1'


}

1 个答案:

答案 0 :(得分:1)

为什么你认为你需要multidex?尝试再次删除multiDexEnabled = true行。另请注意,在Android 4.0(API 14)之前运行multidex时会出现问题,因为我可以看到您的targetVersion是API 13.

有关详细信息,请参阅此处https://developer.android.com/studio/build/multidex.html