애드몹 테스트 광고가 안떠요 ㅠ

23.09.30 16:53 작성 23.09.30 16:54 수정 조회수 447

1

스크린샷 2023-09-29 141728.png스크린샷 2023-09-29 141800.png스크린샷 2023-09-29 141853.png

이런 로그캣이 뜨는데 이유가 뭘까요 ㅠㅠ

 

이건 모듈 그래들 파일입니다.

plugins {
    id("com.android.application")
}

android {
    namespace = "com.example.admobtest"
    compileSdk = 33

    defaultConfig {
        applicationId = "com.example.admobtest"
        minSdk = 20
        targetSdk = 33
        versionCode = 1
        versionName = "1.0"

        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            isMinifyEnabled = false
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
        }
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
}

dependencies {

    implementation ("com.google.android.gms:play-services-ads:21.1.0")
    implementation("androidx.appcompat:appcompat:1.6.1")
    implementation("com.google.android.material:material:1.9.0")
    implementation("androidx.constraintlayout:constraintlayout:2.1.4")
    testImplementation("junit:junit:4.13.2")
    androidTestImplementation("androidx.test.ext:junit:1.1.5")
    androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
}

 

이건 메인 액티비티.자바 파일입니다.

package com.example.admobtest;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.initialization.InitializationStatus;
import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;

public class MainActivity extends AppCompatActivity {
    private AdView mAdView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        MobileAds.initialize(this, new OnInitializationCompleteListener() {
            @Override
            public void onInitializationComplete(InitializationStatus initializationStatus) {
            }
        });

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

 

이건 액티비티 메인.xml 파일입니다.

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <com.google.android.gms.ads.AdView
        xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        ads:adSize="BANNER"
        ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
    </com.google.android.gms.ads.AdView>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

 

이건 마니페스트 파일입니다.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">
    <uses-permission android:name="com.google.android.gms.permission.AD_ID"/>

    <application
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.AdmobTest"
        tools:targetApi="31">
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-3940256099942544~3347511713"/>
    </application>

</manifest>

 

계속봐도 뭐가 문제인지 잘 모르겠습니다. ㅠㅠ

혹시 원인이랑 수정해야하는 부분을 알 수 있을까요?

 

 

 

 

 

답변 1

답변을 작성해보세요.

0

인프런 AI 인턴님의 프로필

인프런 AI 인턴

2023.10.01

안녕하세요, 인프런 AI 인턴이에요. 애드몹 테스트 광고가 안 뜨는 이유로 로그캣에 표시되는 오류가 있는데요.

보시면 알겠지만 dependencies에는 애드몹 SDK가 올바르게 추가되어 있습니다. 하지만 누락된 부분이 있는 것 같아요. onCreate 메소드에서 애드몹 초기화 코드가 빠져있는 것 같네요.

애드몹 광고를 표시하기 위해 애드몹 초기화가 필요한데, 이를 수행하는 코드가 필요합니다. 예를 들어, 다음과 같이 onCreate 메소드에 애드몹 초기화 코드를 추가해보세요.

import com.google.android.gms.ads.MobileAds;

...

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

    // 애드몹 초기화 코드
    MobileAds.initialize(this, "YOUR_ADMOB_APP_ID");

    // 액티비티 레이아웃 등의 코드

}

위의 코드에서 “YOUR_ADMOB_APP_ID” 부분에는 자신이 생성한 애드몹 앱 ID를 입력해야 합니다. 만약 애드몹 앱 ID를 생성하지 않았다면, 애드몹 계정을 만들고 앱을 등록하여 앱 ID를 얻으세요.

애드몹 광고가 정상적으로 표시되도록 코드를 추가해보세요. 그래도 문제가 있다면 해당 오류 로그를 함께 알려주시면 좀 더 자세한 도움을 드릴 수 있을 것 같아요. 감사합니다.