LibGDX "Wrong Package Name" 中的 Appodeal 横幅广告

Appodeal Banner Ads in LibGDX "Wrong Package Name"

我正在尝试在 LibGDX 中测试 Appodeal 的演示横幅广告,我得到的横幅显示“您提供了错误的包名称”错误。

我用谷歌搜索了该错误消息,但找不到任何内容。我已经下载了 Appodeal 测试应用程序,他们的测试广告显示正确。我为 Appodeal 和 Admob 使用了与他们的测试应用程序使用的相同的测试 ID。我已经阅读了他们的设置教程并查看了他们测试应用程序的代码,但我无法弄清楚我做错了什么。任何解决这个问题的帮助将不胜感激!

我创建了一个小型测试应用程序,这是我的代码。

AndroidLauncher.java

package com.mygdx.adtest;

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

import com.appodeal.ads.Appodeal;
import com.appodeal.ads.BannerView;
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;

public class AndroidLauncher extends AndroidApplication {
    @Override
    protected void onCreate (Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
        
        // LAYOUT: combines LibGDX View and Ad View
        RelativeLayout relativeLayout = new RelativeLayout(this);
        
        // Ad View
        Appodeal.initialize(this, "fee50c333ff3825fd6ad6d38cff78154de3025546d47a84f", Appodeal.BANNER);
        Appodeal.setTesting(true);
        Appodeal.show(this, Appodeal.BANNER);
        
        BannerView bannerView = new BannerView(this, null);
        Appodeal.setBannerViewId(bannerView.getId());
        
        // LibGDX View
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);     
        View libgdxView = initializeForView(new AppodealTest(), config);
        
        // add to view
        relativeLayout.addView(bannerView);
        relativeLayout.addView(libgdxView);
        
        // set layout
        setContentView(relativeLayout);
    }
}

AppodealTest.java

package com.mygdx.adtest;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.utils.ScreenUtils;

public class AppodealTest extends ApplicationAdapter {
    @Override public void create () { }
    @Override public void render () { ScreenUtils.clear(0.2f, 0.3f, 0.4f, 1); }
    @Override public void dispose () { }
}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.mygdx.adtest" >
    
    <!-- APPODEAL -->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:isGame="true"
        android:appCategory="game"
        android:label="@string/app_name"
        android:theme="@style/GdxTheme" >
        
        <activity
            android:name="com.mygdx.adtest.AndroidLauncher"
            android:label="@string/app_name" 
            android:screenOrientation="fullUser"
            android:configChanges="keyboard|keyboardHidden|navigation|orientation|screenSize|screenLayout">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    
        <!-- ADMOB -->
        <meta-data
                android:name="com.google.android.gms.ads.APPLICATION_ID"
                android:value="ca-app-pub-3940256099942544~3347511713"/>
    </application>
</manifest>

项目:build.gradle

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
        gradlePluginPortal()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.0.4'
    }
}

allprojects {
    apply plugin: "eclipse"
    version = '1.0'
    ext {
        appName = "AppodealTest"
        gdxVersion = '1.10.0'
        roboVMVersion = '2.3.12'
        box2DLightsVersion = '1.5'
        ashleyVersion = '1.7.3'
        aiVersion = '1.8.2'
        gdxControllersVersion = '2.1.0'
    }
    repositories {
        mavenLocal()
        mavenCentral()
        google()
        gradlePluginPortal()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        maven { url "https://oss.sonatype.org/content/repositories/releases/" }
    }
}

project(":desktop") {
    apply plugin: "java-library"
    dependencies {
        implementation project(":core")
        api "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
        api "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
    }
}

project(":android") {
    apply plugin: "com.android.application"
    configurations { natives }
    dependencies {
        implementation project(":core")
        api "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-arm64-v8a"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86_64"
    }
}

project(":core") {
    apply plugin: "java-library"
    dependencies {
        api "com.badlogicgames.gdx:gdx:$gdxVersion"
    }
}

ANDROID: build.gradle

android {
    buildToolsVersion "30.0.2"
    compileSdkVersion 30
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
            jniLibs.srcDirs = ['libs']
        }
    }
    packagingOptions {
        exclude 'META-INF/robovm/ios/robovm.xml'
    }
    defaultConfig {
        applicationId "com.mygdx.adtest"
        minSdkVersion 16
        targetSdkVersion 30
        multiDexEnabled true
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    
    // APPODEAL
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

// 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 {
    doFirst {
        file("libs/armeabi/").mkdirs()
        file("libs/armeabi-v7a/").mkdirs()
        file("libs/arm64-v8a/").mkdirs()
        file("libs/x86_64/").mkdirs()
        file("libs/x86/").mkdirs()
        configurations.natives.copy().files.each { jar ->
            def outputDir = null
            if (jar.name.endsWith("natives-arm64-v8a.jar")) outputDir = file("libs/arm64-v8a")
            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_64.jar")) outputDir = file("libs/x86_64")
            if(jar.name.endsWith("natives-x86.jar")) outputDir = file("libs/x86")
            if(outputDir != null) {
                copy {
                    from zipTree(jar)
                    into outputDir
                    include "*.so"
                }
            }
        }
    }
}

tasks.whenTaskAdded { packageTask ->
    if (packageTask.name.contains("package")) {
        packageTask.dependsOn 'copyAndroidNatives'
    }
}

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.mygdx.adtest/com.mygdx.adtest.AndroidLauncher'
}

eclipse.project.name = appName + "-android"

// APPODEAL
repositories {
    // Add Appodeal repository
    maven { url "https://artifactory.appodeal.com/appodeal" }
}

dependencies {
    implementation 'androidx.multidex:multidex:2.0.1'
    
    // APPODEAL
    implementation 'com.appodeal.ads:sdk:2.10.3.+'
}

network_security_config.xml

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true">
        <trust-anchors>
            <certificates src="system" />
            <certificates src="user" />
        </trust-anchors>
    </base-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">127.0.0.1</domain>
    </domain-config>
</network-security-config>

我认为您已经为测试广告创建了一个测试演示项目。但您应该保留与项目相同的包名称以显示广告,因为它们会检查从上下文中获取的包名称。

package com.mygdx.adtest;    //You should pay attention to this.

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

import com.appodeal.ads.Appodeal;
import com.appodeal.ads.BannerView;
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;

public class AndroidLauncher extends AndroidApplication {
    @Override
    protected void onCreate (Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
        
        // LAYOUT: combines LibGDX View and Ad View
        RelativeLayout relativeLayout = new RelativeLayout(this);
        
        // Ad View
        Appodeal.initialize(this, "fee50c333ff3825fd6ad6d38cff78154de3025546d47a84f", Appodeal.BANNER);
        Appodeal.setTesting(true);
        Appodeal.show(this, Appodeal.BANNER);
        
        BannerView bannerView = new BannerView(this, null);
        Appodeal.setBannerViewId(bannerView.getId());
        
        // LibGDX View
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);     
        View libgdxView = initializeForView(new AppodealTest(), config);
        
        // add to view
        relativeLayout.addView(bannerView);
        relativeLayout.addView(libgdxView);
        
        // set layout
        setContentView(relativeLayout);
    }
}