2017-06-19 3 views
0

J'ai un ad-id qui fonctionne dans tous les autres projets. Si j'essaie maintenant de l'afficher dans mon projet libgdx alors il ne s'affiche pas. Le code doit être correct car les annonces de test sont affichées.L'application n'affichait que des annonces test mais pas de véritables annonces, pourquoi?

Voici mon code:

Mon build.gradle Module: Android:

android { 
    buildToolsVersion "21.1.2" 
    compileSdkVersion 21 
    sourceSets { 
     main { 
      manifest.srcFile 'AndroidManifest.xml' 
      java.srcDirs = ['src'] 
      aidl.srcDirs = ['src'] 
      renderscript.srcDirs = ['src'] 
      res.srcDirs = ['res'] 
      assets.srcDirs = ['assets'] 
     } 

     instrumentTest.setRoot('tests') 
    } 
} 

// needed to add JNI shared libraries to APK when compiling on CLI 
tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask -> 
    pkgTask.jniFolders = new HashSet<File>() 
    pkgTask.jniFolders.add(new File(projectDir, 'libs')) 
} 

// called every time gradle gets executed, takes the native dependencies of 
// the natives configuration, and extracts them to the proper libs/ folders 
// so they get packed with the APK. 
task copyAndroidNatives() { 
    file("libs/armeabi/").mkdirs(); 
    file("libs/armeabi-v7a/").mkdirs(); 
    file("libs/x86/").mkdirs(); 

    configurations.natives.files.each { jar -> 
     def outputDir = null 
     if(jar.name.endsWith("natives-armeabi-v7a.jar")) outputDir = file("libs/armeabi-v7a") 
     if(jar.name.endsWith("natives-armeabi.jar")) outputDir = file("libs/armeabi") 
     if(jar.name.endsWith("natives-x86.jar")) outputDir = file("libs/x86") 
     if(outputDir != null) { 
      copy { 
       from zipTree(jar) 
       into outputDir 
       include "*.so" 
      } 
     } 
    } 
} 

task run(type: Exec) { 
    def path 
    def localProperties = project.file("../local.properties") 
    if (localProperties.exists()) { 
     Properties properties = new Properties() 
     localProperties.withInputStream { instr -> 
      properties.load(instr) 
     } 
     def sdkDir = properties.getProperty('sdk.dir') 
     if (sdkDir) { 
      path = sdkDir 
     } else { 
      path = "$System.env.ANDROID_HOME" 
     } 
    } else { 
     path = "$System.env.ANDROID_HOME" 
    } 

    def adb = path + "/platform-tools/adb" 
    commandLine "$adb", 'shell', 'am', 'start', '-n', 'com.barodapride.flappy.android/com.barodapride.flappy.android.AndroidLauncher' 
} 

// sets up the Android Eclipse project, using the old Ant based build. 
eclipse { 
    // need to specify Java source sets explicitely, SpringSource Gradle Eclipse plugin 
    // ignores any nodes added in classpath.file.withXml 
    sourceSets { 
     main { 
      java.srcDirs "src", 'gen' 
     } 
    } 

    jdt { 
     sourceCompatibility = 1.6 
     targetCompatibility = 1.6 
    } 

    classpath { 
     plusConfigurations += [ project.configurations.compile ]   
     containers 'com.android.ide.eclipse.adt.ANDROID_FRAMEWORK', 'com.android.ide.eclipse.adt.LIBRARIES'  
    } 
    dependencies { 

     compile 'com.google.android.gms:play-services-ads:10.2.4' 
    } 
    project { 
     name = appName + "-android" 
     natures 'com.android.ide.eclipse.adt.AndroidNature' 
     buildCommands.clear(); 
     buildCommand "com.android.ide.eclipse.adt.ResourceManagerBuilder" 
     buildCommand "com.android.ide.eclipse.adt.PreCompilerBuilder" 
     buildCommand "org.eclipse.jdt.core.javabuilder" 
     buildCommand "com.android.ide.eclipse.adt.ApkBuilder" 
    } 
} 

// sets up the Android Idea project, using the old Ant based build. 
idea { 
    module { 
     sourceDirs += file("src"); 
     scopes = [ COMPILE: [plus:[project.configurations.compile]]]   

     iml { 
      withXml { 
       def node = it.asNode() 
       def builder = NodeBuilder.newInstance(); 
       builder.current = node; 
       builder.component(name: "FacetManager") { 
        facet(type: "android", name: "Android") { 
         configuration { 
          option(name: "UPDATE_PROPERTY_FILES", value:"true") 
         } 
        } 
       } 
      } 
     } 
    } 
} 

Mon AndroidLauncher:

package com.barodapride.flappy.android; 

import android.os.Bundle; 
import android.view.View; 
import android.widget.RelativeLayout; 

import com.badlogic.gdx.backends.android.AndroidApplication; 
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration; 
import com.barodapride.flappy.AdHandler; 
import com.barodapride.flappy.FlappyGame; 
import com.barodapride.flappy.IActivityRequestHandler; 
import com.google.android.gms.ads.AdRequest; 
import com.google.android.gms.ads.AdSize; 
import com.google.android.gms.ads.AdView; 
import com.google.android.gms.ads.InterstitialAd; 


public class AndroidLauncher extends AndroidApplication implements AdHandler{ 

    private static final String adUnitId ="ca-app-pub-XXXXXXXXX/XXXXXXXXXX"; 
    private static final String TAG = "AndroidLauncher"; 
    protected AdView adView; 


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

     RelativeLayout layout = new RelativeLayout(this); 

     AndroidApplicationConfiguration config = new AndroidApplicationConfiguration(); 
     View gameView=initializeForView(new FlappyGame(this), config); 

     RelativeLayout.LayoutParams gameViewParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); 
     gameViewParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE); 
     gameViewParams.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE); 

     gameView.setLayoutParams(gameViewParams); 
     layout.addView(gameView); 

     adView = new AdView(this); 
     adView.setAdSize(AdSize.BANNER); 
     adView.setAdUnitId(adUnitId); 

     AdRequest.Builder adRequestBuilder = new AdRequest.Builder(); 
     adRequestBuilder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR); 
     adView.loadAd(adRequestBuilder.build()); 

     RelativeLayout.LayoutParams topParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); 
     topParams.addRule(RelativeLayout.ALIGN_PARENT_TOP,RelativeLayout.TRUE); 
     topParams.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE); 
     layout.addView(adView, topParams); 
     adView.setBackgroundColor(android.graphics.Color.TRANSPARENT); 

     setContentView(layout); 
    } 

    @Override 
    public void showAds(boolean show) { 

    } 

    @Override 
    protected void onResume() { 
     super.onResume(); 
     adView.resume(); 
    } 

    @Override 
    protected void onPause() { 
     super.onPause(); 
     adView.pause(); 
    } 

    @Override 
    protected void onDestroy() { 
     super.onDestroy(); 
     adView.destroy(); 
    } 
    } 

Et mon Manifest:

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

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

    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/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" 
      android:theme="@android:style/Theme.Translucent" /> 
     <activity 
      android:name="com.barodapride.flappy.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> 

Pourquoi est la bannière publicitaire pas se pointer?

Répondre

0

Je manque un AddListener qui fait un rappel onAdLoaded qui vous indique, quand un ajout est disponible.

Je ne peux pas identifier clairement dans votre code, où vous faites le lien entre le composant <AdView> et votre code (manque votre mise en page xml).

Voici un fragment d'un de mes jeux libgdx, qui affiche des annonces en direct fin:

Dans mon manifeste, j'utilise cette metadata pour le <Application>

<application> 
<meta-data android:value="true" android:name="ADMOB_ALLOW_LOCATION_FOR_ADS" /> 

Ensuite, vous avez dans votre xml (au moins, je l'espère) un composant <AdView>. Ce composant nécessite un écouteur.

adView.setAdListener(new AdListener() { 

@Override 
public void onAdLoaded() { 
    super.onAdLoaded(); 

    // Inform your screen, that the add is loaded 
    // Screen shall make the AdView visible -> runOnUiThread!!! 
    androidGame.runOnUiThread(50, new Runnable() { 
     @Override 
     public void run() { 
      // This call is from my game engine, just do a callback 
      // to your running screen that it shall make the view visible 
      if (Engine.get().getActiveScreen() != null) 
       Engine.get().getActiveScreen().onBannerAdLoaded(); 
     } 
    }); 
} 
}); 

adView.loadAd(new AdRequest.Builder().build()); 

Espérons que cela aide.

0

Si votre annonce test fonctionne correctement avec votre application et que vous n'obtenez pas d'annonces en direct.

Procédez comme suit:

  1. Attendez quelques fois. Après avoir attendu certaines heures/heures si vous rencontrez toujours un problème, vous devez cocher l'option Vérification du bloc d'annonces et AppId du compte AdMob.

  2. Si vous êtes en mesure de charger des annonces test mais pas de les diffuser, cela peut poser problème pour votre compte AdMob.

  3. Assurez-vous que vous avez correctement configuré un système de paiement et/ou vérifié votre code PIN? Si ce n'est pas fait, les annonces en direct ne seront pas diffusées depuis votre compte.

  4. Maintenant vous devez poster votre problème dans ce group pour assistance.