[11.3] AdMob support for Android + EU Consent

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
bio1712
Citizen
Posts: 72
Joined: Wed Aug 19, 2015 4:13 pm
Location: Italy

[11.3] AdMob support for Android + EU Consent

Post by bio1712 »

AdMob support for Android!

iOS Library

(Old content)
Hi all.
As you may have noticed, the way to deploy Android apps has changed: the newest version of the official Android port doesn't use ant anymore, but uses the Gradle wrapper.
Therefore a new AdMob library is needed.

I want to thank Master Both, the author of this beautiful library for having let me use some of his code.

There is another reason I made this library: the functions are the same of the iOS library I have made before.


(New content)
The library has been updated to LÖVE 11.3!
With this library you can display AdMob ads (banners, interstitial and rewarded video) and collect consent from the European users as required by the GPDR law (more info here)

I've added a new module:

love.ads!

With this module is possible to request and display ads from LÖVE!
An AdMob account is needed in order to use this module.

I have added 11 functions and 5 callbacks:

love.ads Functions
  • love.ads.createBanner(string adUnitID,string position)
    string adUnitID : Your banner ad unit id.
    string position : The position of the banner. Can be "top" or "bottom".
    Initializes the banner ad without displaying it. This function may be fired only once.
    The banner inizialized is a smart banner.
  • love.ads.showBanner()
    Displays the banner ad. This function may be fired after createBanner
  • love.ads.hideBanner()
    Hides the banner ad. This function may be fired after createBanner
  • love.ads.requestInterstitial(string adUnitID)
    string adUnitID : Your interstitial ad unit id.
    Requests an interstitial ad. This function should be called every time a new ad is needed.
  • love.ads.isInterstitialLoaded()
    Check if the interstitial ad previously requested is ready to be shown.

    Returns:
    bool isAdReady: true if the ad is ready to be shown.
  • love.ads.showInterstitial()
    Displays the interstitial ad. May be called only if the ad is loaded.
  • love.ads.requestRewardedAd(string adUnitID)
    string adUnitID : Your rewarded ad unit id.
    Requests a rewarded video ad. This function should be called every time a new ad is needed.
  • love.ads.isRewardedAdLoaded()
    Check if the rewarded video ad previously requested is ready to be shown.

    Returns:
    bool isAdReady: true if the ad is ready to be shown.
  • love.ads.showRewardedAd()
    Displays the rewarded video ad. May be called only if the ad is loaded.
  • love.ads.getDeviceLanguage()
    Returns:
    string deviceLanguage: the code of the language set on the device. (Example: EN,FR,IT)
    It can be useful for internationalization.
  • love.ads.changeEUConsent()
    Shows the Consent View to let the user change his consent.
love.ads Callbacks
  • love.interstitialFailedToLoad()
    Fired when an interstitial ad fails to load.
  • love.interstitialClosed()
    Fired when the user closes an interstitial ad.
  • love.rewardedAdFailedToLoad()
    Fired when a rewarded video ad fails to load.
  • love.rewardUserWithReward(string rewardType,number rewardQuantity)
    string rewardType : The type of the reward you set in your AdMob dashboard.
    number rewardQuantity : The quantity of rewards you set in you AdMob dashboard.

    Fired when a rewarded video ad successfully finishes playing.
  • love.rewardedAdDidStop()
    Fired when a rewarded video ad is closed by the user.
    This callback is fired even if the video has already finished.
Here is the repository of the library:
https://bitbucket.org/bio1712/love2d-admob-android
(LÖVE version: 11.3)

How to use:
In order to use this library you need to follow the instructions here.
In addition, you have to open SDK manager and download Google Play Services under the extras menu.

Included in the source, there is an example game.love.

To use the library you need to open ./love/src/main/java/org/love2d/android/AdActivity.java and
1) Insert your app ID at line 63
2) Insert your publisher ID at line 66 (needed for the Consent SDK)
3) Insert your privacy policy URL at line 67 (needed for the Consent SDK)
4) Add your test devices for each kind of ad.
5) You can disable the Consent SDK by turning the boolean "collectConsent" to false at line 65.

Then, open ./app/src/main/AndroidManifest.xml and set your app ID at line 81.

Note: all the Ad-Unit IDs in the game.love are from this url.

Screenshots:

Image

Image

Image

Image

Second note: This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.

Sample APK: https://bitbucket.org/bio1712/love2d-ad ... -debug.apk
Last edited by bio1712 on Fri Feb 07, 2020 2:52 pm, edited 10 times in total.
greboide
Prole
Posts: 5
Joined: Mon Jul 31, 2017 6:40 am

Re: [0.10.2] AdMob support for Android!

Post by greboide »

why dont you make a pull request to send this back to love main project, just curious, other than that nice work!
User avatar
zorg
Party member
Posts: 3435
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: [0.10.2] AdMob support for Android!

Post by zorg »

greboide wrote: Wed Aug 09, 2017 3:40 am why dont you make a pull request to send this back to love main project, just curious, other than that nice work!
Because it would most likely not be incorporated, ever.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
bio1712
Citizen
Posts: 72
Joined: Wed Aug 19, 2015 4:13 pm
Location: Italy

Re: [0.10.2] AdMob support for Android!

Post by bio1712 »

yetneverdone wrote: Wed Aug 09, 2017 6:59 am how is this different from this: https://bitbucket.org/npinochet/love-android-sdl2 ??
The way of deploying it’s different, furthermore it doesn’t have rewarded videos and functions are called in a different way.
greboide wrote: Wed Aug 09, 2017 3:40 am why dont you make a pull request to send this back to love main project, just curious, other than that nice work!
Thank you!
User avatar
yetneverdone
Party member
Posts: 446
Joined: Sat Sep 24, 2016 11:20 am
Contact:

Re: [0.10.2] AdMob support for Android!

Post by yetneverdone »

The way of deploying it’s different, furthermore it doesn’t have rewarded videos and functions are called in a different way.
Deploying? The link you provide for the instruction is the main wiki of master both's repo,which by the way, is very deprecated.
bio1712
Citizen
Posts: 72
Joined: Wed Aug 19, 2015 4:13 pm
Location: Italy

Re: [0.10.2] AdMob support for Android!

Post by bio1712 »

yetneverdone wrote: Wed Aug 09, 2017 2:03 pm
The way of deploying it’s different, furthermore it doesn’t have rewarded videos and functions are called in a different way.
Deploying? The link you provide for the instruction is the main wiki of master both's repo,which by the way, is very deprecated.
The link I provide for the instruction is the readme.md file of Martin Felis’ repo.
If you compare the “Quick start” sections of my library and Master Both’s one you will notice the differences.
User avatar
Marty
Citizen
Posts: 89
Joined: Mon Dec 04, 2017 1:47 am
Location: Germany

Re: [0.10.2] AdMob support for Android!

Post by Marty »

Hey bio1712. Thank you for these forked repos. I'm excited to try this out.

@everyone But I got a problem with the deployment using this, maybe anybody can help? :?

The common official documentations are very fussy and ant was missing the build.xml (gradle seems to be the way to go), I ended up downloading JetBrain's Android Studio to make things simple. I managed to compile the project with it, eventually. All dependencies are loaded, correctly as it seems.

All I did was adding my own love file to app\src\main\assets, adding my own ca-app-pub ID in the AdActivity and changing target from android-25 to android-19 in the project.properties (the game needs to run on KitKat).

I also added a gradle.properties with:

Code: Select all

org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=1024m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.parallel=true
to increase the build process. :monocle:


When I run the app on my SGS3 I get an SDL error, tho:
Couldn't load gnustl_shared from loader dalvik.system.PathClassLoader[dexPath=/data/app/org.love2d.android-1.apk,libraryPath=/data/app-lib/org.love2d.android-1]: findLibrary returned null
:cry:

Anybody knows how I can fix this problem?
Visual Studio Code TemplateRichLÖVE Mobile (AdMob+UnityAds+PlayGamesServices+GameCenter)Add me on Discord

───▄▀▀▀▄▄▄▄▄▄▄▀▀▀▄───
───█▒▒░░░░░░░░░▒▒█───
────█░░░░░░░░░█────
▄▄──█░░░▀█▀░░░█──▄▄
█░░█▀▄░░░░░░░▄▀█░░█
bio1712
Citizen
Posts: 72
Joined: Wed Aug 19, 2015 4:13 pm
Location: Italy

Re: [0.10.2] AdMob support for Android!

Post by bio1712 »

modiX wrote: Thu Dec 07, 2017 11:40 pm Hey bio1712. Thank you for these forked repos. I'm excited to try this out.

@everyone But I got a problem with the deployment using this, maybe anybody can help? :?

The common official documentations are very fussy and ant was missing the build.xml (gradle seems to be the way to go), I ended up downloading JetBrain's Android Studio to make things simple. I managed to compile the project with it, eventually. All dependencies are loaded, correctly as it seems.

All I did was adding my own love file to app\src\main\assets, adding my own ca-app-pub ID in the AdActivity and changing target from android-25 to android-19 in the project.properties (the game needs to run on KitKat).

I also added a gradle.properties with:

Code: Select all

org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=1024m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.parallel=true
to increase the build process. :monocle:


When I run the app on my SGS3 I get an SDL error, tho:
Couldn't load gnustl_shared from loader dalvik.system.PathClassLoader[dexPath=/data/app/org.love2d.android-1.apk,libraryPath=/data/app-lib/org.love2d.android-1]: findLibrary returned null
:cry:

Anybody knows how I can fix this problem?
Have you tried using gradlew build? Why have you added a new gradle.properties file? And what version of Android Build Tools do you have?
User avatar
Marty
Citizen
Posts: 89
Joined: Mon Dec 04, 2017 1:47 am
Location: Germany

Re: [0.10.2] AdMob support for Android!

Post by Marty »

bio1712 wrote: Tue Dec 12, 2017 5:58 am Have you tried using gradlew build?
No, I haven't. So I gave it a shot, executed "gradlew.bat build", worked out. Then I created a keystore and signed my APK, I could install it. However, the problem persists.
bio1712 wrote: Tue Dec 12, 2017 5:58 am Why have you added a new gradle.properties file?
The build process took almost 20 minutes, so after 2 failed attempts I decided to search for a solution. With that file with the content you see in my last post, the build process only takes 2 minutes. Now, for my confusion, I've renamed the file and it still takes only 1-2 minutes, so not sure why it took so long before. I keep the file renamed as _gradle.properties to avoid any problems caused by it, for now.
bio1712 wrote: Tue Dec 12, 2017 5:58 am And what version of Android Build Tools do you have?
My build.gradle file has configured to use the build tools version is 25.0.2, just as it is in your fork. I tried it with the latest 27, too, but it didn't work either.

I'm going to test the whole thing with the original port as well as on some other devices tomorrow to see where the problem is coming from.
Visual Studio Code TemplateRichLÖVE Mobile (AdMob+UnityAds+PlayGamesServices+GameCenter)Add me on Discord

───▄▀▀▀▄▄▄▄▄▄▄▀▀▀▄───
───█▒▒░░░░░░░░░▒▒█───
────█░░░░░░░░░█────
▄▄──█░░░▀█▀░░░█──▄▄
█░░█▀▄░░░░░░░▄▀█░░█
Post Reply

Who is online

Users browsing this forum: No registered users and 19 guests