Posts tagged with admob

i started working on existing react native projet, that have Google ads which is already working on the playStore.

However,is not working on dev environment, is this is normal ? Does the Google ads works only after uploading the app on the store ?

I downloaded Xcode12 beta 5 to apply Google Ads SDK v7.64 and AppTrackingTransparency framework to my app. But when I build my project with Xcode12 beta 5, I meet "library not found for -lGoogleUtilities" even though I didn't change my project file anything. When I use Xcode11 to build my project, it's okay.

Is it a bug of Xcode12? Or How can I fix the problem?

I use pod to setting and opened *.xcworkspace file to open project.

I added a single Native ad to my application, but on different devices, ads, especially videos, come with a delay, on the emulator the video is not shown at all. I know that you can somehow preload ads, but I don’t know how to do it, please explain to me.

Here is my code:

class Fragment(private var index: Int, private var adsId: String) : Fragment() {     var currentNativeAd: UnifiedNativeAd? = null     lateinit var adLoader: AdLoader     override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {         val view = inflater.inflate(R.layout.fragment, container, false)         return view     }     override fun onActivityCreated(savedInstanceState: Bundle?) {         super.onActivityCreated(savedInstanceState)         val unifiedNativeAdView = layoutInflater.inflate(R.layout.native_ad_layout, null) as UnifiedNativeAdView         val nativeAdLayout = view!!.findViewById<FrameLayout>(R.id.id_native_ad)         val adLoader = AdLoader.Builder(activity, adsId).forUnifiedNativeAd { unifiedNativeAd -> (unifiedNativeAd)             mapUnifiedNativeAdToLayout(unifiedNativeAd, unifiedNativeAdView)             nativeAdLayout.removeAllViews()         }.withAdListener(object : AdListener() {             // Code to be executed when an ad request fails.             override fun onAdLoaded() {                 super.onAdLoaded()                 if (!adLoader.isLoading) {                   nativeAdLayout.addView(unifiedNativeAdView)                 }             }             override fun onAdFailedToLoad(errorCode: Int) {                Toast.makeText(applicationContext, "Ad failed to load! error code: $errorCode", Toast.LENGTH_SHORT).show()             }             override fun onAdClosed() {                 nativeAdLayout.removeAllViews()             }         }).build()         adLoader.loadAd(AdRequest.Builder().build())         }     fun mapUnifiedNativeAdToLayout(adFromGoogle: UnifiedNativeAd, myAdView: UnifiedNativeAdView) {         currentNativeAd?.destroy()         currentNativeAd = adFromGoogle         val mediaView: MediaView = myAdView.findViewById(R.id.ad_media)         myAdView.mediaView = mediaView         myAdView.bodyView = myAdView.findViewById(R.id.ad_body)         if (adFromGoogle.body == null) {             myAdView.bodyView.visibility = View.GONE         } else {             (myAdView.bodyView as TextView).text = adFromGoogle.body         }         myAdView.setNativeAd(adFromGoogle)         val vc = adFromGoogle.videoController         if (vc.hasVideoContent()) {             vc.videoLifecycleCallbacks = object : VideoController.VideoLifecycleCallbacks() {                 override fun onVideoEnd() {                     super.onVideoEnd()                 }             }         }      }     override fun onDestroy() {         currentNativeAd?.destroy()         super.onDestroy()     } } 

native_ad_layout.xml

<?xml version="1.0" encoding="utf-8"?> <com.google.android.gms.ads.formats.UnifiedNativeAdView xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:layout_gravity="bottom">     <LinearLayout         android:layout_width="match_parent"         android:layout_height="match_parent"         android:layout_gravity="center"         android:orientation="vertical">         <RelativeLayout             android:layout_width="match_parent"             android:layout_height="match_parent">             <LinearLayout                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:weightSum="2"                 android:orientation="vertical">                 <com.google.android.gms.ads.formats.MediaView                     android:id="@+id/ad_media"                     android:layout_width="match_parent"                     android:layout_height="0dp"                     android:padding="@dimen/_8sdp"                     android:layout_gravity="center"                     android:layout_weight="2"                     android:background="#fff" />                 <TextView                     android:id="@+id/ad_body"                     android:layout_width="match_parent"                     android:layout_height="wrap_content"                     android:fontFamily="@font/sf_pro_display_regular"                     android:gravity="center"                     android:text="body of ad"                     android:textSize="14sp" />             </LinearLayout>         </RelativeLayout>          </LinearLayout> </com.google.android.gms.ads.formats.UnifiedNativeAdView> 

In a fragment.xml, just a FrameView for the ad.

Recently, I made an android app. After that, I have opened my account in AdMob and entered my app. I have got an App ID and Unit ID. For the first time, I tested my App with testing ID codes from developers.google.com. It worked well. But I have put IDs which are from AdMob in my codes. As a result, It is not displaying. Here is my Manifest.xml file

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     package="com.example.myapp2">     <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="Lotin-Kirill Converter"         android:roundIcon="@mipmap/ic_launcher_round"         android:supportsRtl="true"         android:theme="@style/AppTheme">         <meta-data             android:name="com.google.android.gms.ads.APPLICATION_ID"             android:value="ca-app-pub-xxxxxxxxxxxxxxxx~xxxxxxxxxx"/>         <activity             android:name="com.example.myapp2.Splash"             android:screenOrientation="portrait"             tools:ignore="LockedOrientationActivity">             <intent-filter>                 <action android:name="android.intent.action.MAIN" />                 <category android:name="android.intent.category.LAUNCHER" />             </intent-filter>         </activity>         <activity             android:name="com.example.myapp2.MainActivity">         </activity>         <meta-data             android:name="preloaded_fonts"             android:resource="@array/preloaded_fonts" />     </application> </manifest> 

It is build.gradle(:app)

apply plugin: 'com.android.application' android {     compileSdkVersion 29     buildToolsVersion "29.0.3"     defaultConfig {         applicationId "com.example.myapp2"         minSdkVersion 16         targetSdkVersion 29         versionCode 1         versionName "1.0"         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"     }     buildTypes {         release {             minifyEnabled false             proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'         }     } } dependencies {     implementation fileTree(dir: 'libs', include: ['*.jar'])     implementation 'androidx.appcompat:appcompat:1.1.0'     implementation 'androidx.constraintlayout:constraintlayout:1.1.3'     implementation 'com.google.android.gms:play-services-ads:19.2.0'     testImplementation 'junit:junit:4.12'     androidTestImplementation 'androidx.test.ext:junit:1.1.1'     androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' } 

Here is MainActivity.java

package com.example.myapp2; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; import android.content.DialogInterface; import android.os.Bundle; import android.os.Handler; import android.os.StrictMode; import android.view.View; import android.webkit.WebView; import android.widget.Toast; 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.MobileAds; import com.google.android.gms.ads.initialization.InitializationStatus; import com.google.android.gms.ads.initialization.OnInitializationCompleteListener; public class MainActivity extends AppCompatActivity {     WebView view;     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 = (AdView)findViewById(R.id.adView);         AdRequest adRequest = new AdRequest.Builder().build();         mAdview.loadAd(adRequest);         StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();         StrictMode.setVmPolicy(builder.build());         view = (WebView) this.findViewById(R.id.webView);         view.getSettings().setJavaScriptEnabled(true);         view.getSettings().setDatabaseEnabled(true);         view.getSettings().setDatabasePath("/data/data/" + view.getContext().getPackageName() + "/databases/");         view.getSettings().setDomStorageEnabled(true);         view.getSettings().setLoadsImagesAutomatically(true);         view.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);         view.loadUrl("file:///android_asset/test.html");     }     boolean doubleBackToExitPressedOnce = false;     @Override     public void onBackPressed() {         if (doubleBackToExitPressedOnce) {             new AlertDialog.Builder(this)                     .setTitle("Lotin-Kirill Converter.")                     .setMessage("Dasturdan chiqmoqchimisiz?")                     .setPositiveButton("Ha",                             new DialogInterface.OnClickListener() {                                 @Override                                 public void onClick(DialogInterface dialog,                                                     int which) {                                     finish();                                 }                             }).setNegativeButton("Yo'q", null).show();             return;         }         this.doubleBackToExitPressedOnce = true;         Toast.makeText(this, "Iltimos, Dasturdan chiqish uchun yana bir marta bosing!", Toast.LENGTH_SHORT).show();         new Handler().postDelayed(new Runnable() {             @Override             public void run() {                 doubleBackToExitPressedOnce=false;             }         }, 2000);     } } 

It is activity_main.xml

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout 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="fill_parent"     android:layout_height="fill_parent"     tools:context=".MainActivity">     <WebView         android:id="@+id/webView"         android:layout_width="fill_parent"         android:layout_height="fill_parent"         app:layout_constraintBottom_toBottomOf="parent"         app:layout_constraintEnd_toEndOf="parent"         app:layout_constraintStart_toStartOf="parent">     </WebView>     <com.google.android.gms.ads.AdView         android:id="@+id/adView"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignParentBottom="true"         android:layout_centerHorizontal="true"         app:adSize="BANNER"         app:adUnitId="ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx" /> </RelativeLayout> 

If you find my mistake, Please help me! Thank you for your attention!