简体   繁体   English

LibGDX 中的 Appodeal 横幅广告“错误的 Package 名称”

[英]Appodeal Banner Ads in LibGDX "Wrong Package Name"

I'm trying to test Appodeal's demo banner ads inside of LibGDX and I get this banner that displays a “You provided a wrong package name” error.我正在尝试在 LibGDX 中测试 Appodeal 的演示横幅广告,我得到了这个横幅,显示“您提供了错误的 package 名称”错误。

在此处输入图像描述

I've googled that error message but cannot find anything.我已经用谷歌搜索了该错误消息,但找不到任何东西。 I have downloaded the Appodeal test app and their test ads display correctly.我已经下载了 Appodeal 测试应用程序,并且他们的测试广告正确显示。 I am using the same test ID's for Appodeal and Admob that their test app uses.我对 Appodeal 和 Admob 使用他们的测试应用程序使用的相同测试 ID。 I have gone through their setup tutorial and looked at the code for their test app, but I cannot figure out what I'm doing wrong.我已经阅读了他们的设置教程并查看了他们的测试应用程序的代码,但我无法弄清楚我做错了什么。 Any help figuring this out will be greatly appreciated!任何帮助解决这个问题将不胜感激!

I created a small test app, here is my code.我创建了一个小型测试应用程序,这是我的代码。

AndroidLauncher.java 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 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 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>

PROJECT: build.gradle项目: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: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 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>

I think you have created a test demo project for test Ad.我认为您已经为测试广告创建了一个测试演示项目。 but you should keep same package name of project to show ad, because they will check package name getting from context.但是您应该保留相同的 package 项目名称以显示广告,因为他们会从上下文中检查 package 名称。

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);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM