Extension-admob

Hey guys!

I completely rewrote official extension-admob as it is like 4+ years old and looks abandoned.

New version supports iOS SDK 8.5 and Android SDK 20.0.3.
There are still some bugs, but banners/interstitials work fine for me.

If anyone wants to give it a try and share their experience, you are more than welcome.
Updated version is here:

8 Likes

Hi
great job, just curious if it is or can be made EU compatible ?

It is possible, but I’m not going to do at the moment, as I still need to test basic functionality and fix some bugs.

Hi @pozirk,

You’re a lifesavior, I spent most of the afternoon testing several google ads libraries for openfl and they all seemed at least 4+ years old and broken at this point. Which would make me want to avoid making Android apps using openfl.

If you don’t mind my inexperienced questions, I tried building the app but got errors in the AdMobEx dependency:

C:\Users\AgbePhH\Git\test\GameExport\android\bin\deps\admobex\src\admobex\AdMobEx.java:46: error: class AdmobEx is public, should be declared in a file named AdmobEx.java
public class AdmobEx extends Extension
       ^
C:\Users\AgbePhH\Git\test\GameExport\android\bin\deps\admobex\src\admobex\AdMobEx.java:16: error: cannot find symbol
import com.google.android.gms.ads.AdError;
                                 ^
  symbol:   class AdError
  location: package com.google.android.gms.ads
C:\Users\AgbePhH\Git\test\GameExport\android\bin\deps\admobex\src\admobex\AdMobEx.java:21: error: cannot find symbol
import com.google.android.gms.ads.FullScreenContentCallback;
                                 ^
  symbol:   class FullScreenContentCallback
  location: package com.google.android.gms.ads
 C:\Users\AgbePhH\Git\test\GameExport\android\bin\deps\admobex\src\admobex\AdMobEx.java:22: error: cannot find symbol
import com.google.android.gms.ads.LoadAdError;
                                 ^
  symbol:   class LoadAdError
  location: package com.google.android.gms.ads
C:\Users\AgbePhH\Git\test\GameExport\android\bin\deps\admobex\src\admobex\AdMobEx.java:24: error: cannot find symbol
import com.google.android.gms.ads.RequestConfiguration;
                                 ^
  symbol:   class RequestConfiguration
  location: package com.google.android.gms.ads
C:\Users\AgbePhH\Git\test\GameExport\android\bin\deps\admobex\src\admobex\AdMobEx.java:25: error: package com.google.android.gms.ads.initialization does not exist
import com.google.android.gms.ads.initialization.InitializationStatus;

I have followed your advice to use Android SDK v.30 and Gradle version 6.7.1.

Any ideas how I could fix that, as I would really like to try out your library?

Thanks in advance :slight_smile:

PS: You may need to create a new fork of the library with a new name to push it to haxelib. In particular, do mind the naming “AdMob.hx” instead of “Admob.hx” to remain consistent.

Hey agbephh!

FIrst, you need to rename AdMobEx.java to AdmobEx.java, looks like Github kept old file name.
For “symbols not found”, I guess you don’t have Google Play services installed from SDK Manager.
I’m not at my computer at the moment, will be able to check for sure only in a week.

Yeah, I kind of didn’t like “AdMob”, so renamed everything to “Admob”, but Github left it as before.
So, you should rename to “Admob.hx” too.
Let me know, how it goes. :slight_smile:

2 Likes

Hey @pozirk, thank you for your involvement!

I have tried with these installed:
image

and I still get these same errors, ending with:

C:\Users\AgbePhH\Git\test\GameExport\android\bin\deps\admobex\src\admobex\AdmobEx.java:257: error: cannot find symbol
                                InterstitialAd.load(mainActivity, id, adRequest, new InterstitialAdLoadCallback() {
                                                                                     ^
  symbol: class InterstitialAdLoadCallback
C:\Users\AgbePhH\Git\test\GameExport\android\bin\deps\admobex\src\admobex\AdmobEx.java:257: error: cannot find symbol
                                InterstitialAd.load(mainActivity, id, adRequest, new InterstitialAdLoadCallback() {
                                ^
  symbol: variable InterstitialAd
C:\Users\AgbePhH\Git\test\GameExport\android\bin\deps\admobex\src\admobex\AdmobEx.java:332: error: cannot find symbol
                                RewardedAd.load(mainActivity, id, adRequest, new RewardedAdLoadCallback() {
                                                                                 ^
  symbol: class RewardedAdLoadCallback
C:\Users\AgbePhH\Git\test\GameExport\android\bin\deps\admobex\src\admobex\AdmobEx.java:332: error: cannot find symbol
                                RewardedAd.load(mainActivity, id, adRequest, new RewardedAdLoadCallback() {
                                ^
  symbol: variable RewardedAd
C:\Users\AgbePhH\Git\test\GameExport\android\bin\deps\admobex\src\admobex\AdmobEx.java:380: error: cannot find symbol
                                        _rewarded.show(mainActivity, new OnUserEarnedRewardListener() {
                                                                         ^
  symbol: class OnUserEarnedRewardListener
C:\Users\AgbePhH\Git\test\GameExport\android\bin\deps\admobex\src\admobex\AdmobEx.java:417: error: cannot find symbol
                return AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(mainContext, adWidth);
                             ^
  symbol:   method getCurrentOrientationAnchoredAdaptiveBannerAdSize(Context,int)
  location: class AdSize
Note: C:\Users\AgbePhH\Git\test\GameExport\android\bin\deps\admobex\src\admobex\AdmobEx.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
27 errors

FAILURE: Build failed with an exception.

I read this might need some specific changes in the build.gradle, but I don’t know how it translates in terms of OpenFL configurations.

Apologies as I understand it is not the fault of your implementation of Admob :slight_smile:

I’m not sure why you have these errors, as I never had them myself, but looks like it’s still can’t get to Google Play service APIs.
So let’s try to recreate the same environment, that I have:

  1. Download android-ndk-r21e
  2. Run openfl setup android to set correct path for android sdk and ndk
  3. Check this thread and follow the steps I took to fix problems with Lime: https://github.com/haxelime/lime/issues/1476
  4. Install extension-googleplayservices-basement and add it to your project

Try to rebuild project after each step to see what fixes the problem. I think 4th step is the solution.

1 Like

Hello :slight_smile:

Please tell me if you need me to create a new topic for the issues we’re discussing.

I’ve added the following to the project (the lib was already installed on haxelib) and it doesn’t fix the issue
<haxelib name="extension-googleplayservices-basement" />

I’m very confused about the NDK. I read it was somewhat optional when you have the SDK. I was using an older “r15c” NDK.

I tried switching to NDK-r21e following your advice, but it seems to make clang++ mandatory, which I don’t have.

android-ndk

Being on Windows 10, I tried the following steps:

  • Installed CMake.
  • Installed Ninja for the generator.
  • Installed Mingw for gcc and g++.
  • Tried building LLVM (for CLANG++) but encountered errors.

Do you have any source to understand why a more recent NDK is required?
Do you confirm I need to have clang++ as a compiler for it?

It seems g++ no longer builds Android.


Perhaps we need to closely follow this issue.

I’m on windows 8, there is no need to install all this, android-ndk-r21e is working fine.
Make sure to install the latest version of haxe 4.2.4, openfl, hxcpp, lime

android-ndk-r23b is not going to work with Lime!
Java can be any, I think, but I have jdk1.8.0_301.