Extension-admob

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.

Hi @pozirk, Iā€™ve been trying to get your AdMob extension working but seem to be hitting problems for both Android and iOS. Any help would be appreciated. Iā€™m on OSX 10.15 (Catalina) and using XCode 12 (tried 11.3 but got issues with the tracking transparency with iOS 14 so moved to 12).

For iOS, the build seems to go most of the way through but then fails with:

Framework not found GoogleMobileAds

Even though the GoogleMobileAds.framework is listed in the project Frameworks folder - Iā€™m not sure how to fix this.

For Android, as I mentioned above, using XCode 11.x didnā€™t build due to the tracking transparency with iOS 14. With XCode 12, the build again goes to the final gradle steps then fails with references to:

Execution failed for task ':app:checkDebugAarMetadata'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
   > The minCompileSdk (31) specified in a
     dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
     is greater than this module's compileSdkVersion (android-30).
     Dependency: androidx.work:work-runtime:2.7.0.

Iā€™m targetting Android-30 and there are several solutions on Google about forcing/adding a dependency or api reference to the work-runtime:2.6.0 - to get around the error, but none that Iā€™ve tried seem to work, or Iā€™m just not putting the fixes in the correct build.gradle location. Iā€™ve also tried using Android-31 which supports the 2.7.0 version and first time it complained that Android 12 needed an ā€˜android:exported=ā€œfalse/trueā€ā€™ parameter - I added this (true and false) and the build succeeded but getting a blank screen.

Things just seem to have moved on versions since your helpful post and itā€™s just got a bit complicated for me.

Thanks

Greg

Iā€™m on MacOS 12 and XCode 13, not sure if it makes any difference.
There are 2 ways to add a framework and one of them not working as expected.

  1. Framework at the left tree panel
  2. General project properties - this one, as I recall, didnā€™t work, didnā€™t actually add a framework

You are not supposed to add GoogleMobileAds.framework manually, it should be added by extension, but try to remove it and re-add, make sure itā€™s from extension, see Path at the top right corner.





For Android, I think I had this issue myself, fix similar to this one helped:


Iā€™m not sure why I didnā€™t metion it in readme, I guess, I was hoping the problem would go away eventually, cause itā€™s just SDK version mismatch.
You need to add it to Lime bulid.gradle though:
compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
	buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
	
	lintOptions { //pozirk - this might help with other problems
		checkReleaseBuilds false
	}
	
	defaultConfig {
		applicationId "::META_PACKAGE_NAME::"
		minSdkVersion Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION)
		targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
		versionCode Integer.parseInt(project.VERSION_CODE)
		versionName project.VERSION_NAME
		::if (languages != null)::resConfigs ::foreach languages::"::__current__::", ::end::""::end::
		
		configurations.all { //pozirk - should fix your problem
            resolutionStrategy { force 'androidx.work:work-runtime:2.6.0' }
		}
	}

It might actually worked for you with SDK31, listen for extension events to see if you initialize it correctly and check adb logs, admob doesnā€™t show any ads except test in debug version, so blank screen is normal.

Thanks for the reply. Iā€™m making progress - I think. Android is building using your build.gradle changes and SDK 30 but Iā€™m getting a blank screen still. Iā€™m only using banner ads and the test ad appears but my app content doesnā€™t. If I remove the extension-admob my app displays fine. So still working on that on.

Iā€™m still having iOs build issues so may need to try xcode 13.

Will keep trying. Thanks again.

Greg

Hi @pozirk. Unfortunately I havenā€™t been able to get any further with these issues for both Android and iOS, and Iā€™m runnning out of ideas. Iā€™m using the current released versions of OpenFL(9.1.0) and Lime(7.9.0). Other versions are: Haxe=4.2.4, hxcpp=4.2.1, hxp=1.2.2, your extension-admob=2.0.1 (using the ./buildPackage.sh and .installPackage.sh and that created the zip).

Android: SDK: 30 m& NDK: 21e

  • Doing a ā€˜lime rebuild android -cleanā€™ does nothing as Iā€™m on the released version of OpenFL/Lime.
  • If I use the latest git versions of both Iā€™m unable to build lime as I get load of errors which I think is due to NDK21 as opposed to the suggested version NDK 15c
  • Iā€™ve added the following to the template AndroidManifest.xml node:
    tools:remove=ā€œandroid:appComponentFactoryā€ android:appComponentFactory=ā€œwhateverStringā€ android:allowNativeHeapPointerTagging=ā€œfalseā€
  • These were from Googling about SDK 30 blank screen issues and appComponentFactory errors I saw in logcat.
  • Iā€™ve also your recommendations in the lime gradle.properies of:
    android.useAndroidX=true
    android.enableJetifier=true

But I still get a blank screen with the exception of the test advert being shown (which is shows your part works). The application is still running and I can log screen touches and things work normally but with a blank display. There is a lot of stuff in the logcat but I canā€™t determine if there is anything specific that is reporting anything about the blank screen. If I remove your extension but keep the SDk 30 the same happens so the extension appears to be fine.

iOS: macOS 12.3.1, XCode 13.3, iOS SDK 15.4.
No matter what I seem to try, the build gets all the way through and fails with the final linking of the GoogleMobileAds framework. Iā€™ve added the path into the search paths, removed and re-added the framwork, moved the folder to be within the project folder, changed the order of the framework search paths and probably other things as well.

The output of the clang++ command that throws the error shows that the framwork is listed and the search path is present. Running this command on itā€™s own fails in the same way. Iā€™ve even tried tweaking this command manually but still no joy.

Iā€™ve seen references to using a xcworkspace instead of the xcodeproj that OpenFL generates - but that didnā€™t work and I think thatā€™s to do with using CocoaPods to add dependencies to a project. Iā€™ve not used it before. Do you use CocoaPods at all?

Again, any help would be much appreciated.

Greg

Black screen on Android might be this:

I have the same OpenFL and Android environment as you.

Iā€™m not sure why for iOS it canā€™t find GoogleMobileAds framework. Maybe something with the naming.
Try download all the frameworks again and replace them:

I managed to get Android working. Seems my AndroidManifest.xml template wasnā€™t merging correctly as part of the build. Iā€™m now using SDK 31 and the test ad is working.

For iOS, which version of the Mobile Ads SDK are you using in the extension. When I use the latest 9.3.0 I get compilation errors as there are differences in the API. Iā€™ve tried to change the AdmobEx.mm to correct the differences but Iā€™m battling with an error in the way things are now implemented with GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth - Canā€™t quite figure out how to fix it yet.

Did you use work-runtime:2.7.0 with Android SDK31?

For iOS, Iā€™m using Mobile Ads SDK 8.11, theyā€™ve made some changes again in v9, so annoying.

Yes (I think so). I removed the resolutionStrategy and the lintOptions and have built both debug and release versions. The debug showed the test ads but the release version showed nothing but I suspect that is due to the app not being available on the store and the AdMob banner still under ā€˜reviewā€™.

Iā€™ve not retried 8.11 yet but have been looking at 9.3 still for iOS. I have managed to get a clean build that ran but didnā€™t show the test ad. To get it to build, I removed the

self._banner = [[GADBannerView alloc] initWithAdSize:GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(viewWidth)];

with

self._banner = [[GADBannerView alloc] initWithAdSize:GADAdSizeBanner];

Still canā€™t figure out why it complains about GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth.

I also had to tweak the buildPackages and installPackages. Firstly, with the buildPackages, when building for iOS, I had a runtime failure immediately as it complained that no AdMob ID had been provided in the Info.plist. This was due to the zip file not containing the templates folder. Secondly, with the installPackages Iā€™ve changed it to use haxelib install extension-admob.zip as haxelib local gave a warning about being deprecated.

Well, I will update extension to th latest iOS SDK eventually, but Iā€™m not sure on timing.

Shouldnā€™t be problems with Admob ID, have you provided it in your project.xml?
File extension-admob-Info.plist from templates folder should be inserted in your Info.plist automatically.

No problem. I appreciate your efforts on this so far and the help youā€™ve given. It doesnā€™t help how rapidly these changes come and force updates to different things and then break others. Itā€™s hard keeping everything up-to-date.

The AdMob ID issue was probably due to me using the buildPackages.sh and installPackages.sh method which didnā€™t include the templates folder in the zip - so the haxelib version didnā€™t contain that folder. Not a problem as I got that fixed.

Iā€™m probably going admob free for a little while until Iā€™ve got it all working so I can at least get some kind of release out (and verified that I can get through the process end-to-end).

Iā€™ll probably come back to it in a week or so.

I think I will be able to update extension with the latest changes somewhere in May as I need to update my own games at AppStore.

1 Like

Thanks for all your best works. It seems the extension will work well for both Android and iOS.
And just my opinion, someone could improve the iAp extension. For my last try, it did not work at all with newest Android library. Donation can be made from other devs.:grin:

Iā€™ve tested extension on Android with the latest Google Play Services 49 (ie Mobile Ad SDK 20.6.0) and Android SDK 31.
Both debug and release versions show ads fine for me, Iā€™ve tried interstitial only.
Android now requires to have new permission <uses-permission android:name="com.google.android.gms.permission.AD_ID"/>, I will update github version soon.

I see some warnings about depreciated methods in the extension, but not sure how to check what these methods are.
Does anyone know?

I will check iOS version of the extension next.

1 Like