[0.10.2] AdMob support for Android!

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

[0.10.2] AdMob support for Android!

Post by bio1712 » Mon Aug 07, 2017 9:06 pm

AdMob support for Android!

Hi all.
As you may have noticed, the way to deploy Android apps has changed: the newest version of the official Android port doesen'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.

Let me show you the 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 9 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 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 this library:
https://bitbucket.org/bio1712/love2d-admob-android
(LÖVE version: 0.10.2)

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.
Screenshot_2017-08-05-11-21-15.png
Screenshot_2017-08-05-11-21-15.png (25.67 KiB) Viewed 3578 times
Note: all the Ad-Unit IDs in the game.love are from this url.

Second Note: Before releasing the app is recommended to open the file ./love/src/main/java/org/love2d/android/AdActivity.java and add your Admob APP-ID at line 42.

greboide
Prole
Posts: 5
Joined: Mon Jul 31, 2017 6:40 am

Re: [0.10.2] AdMob support for Android!

Post by greboide » 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!

User avatar
zorg
Party member
Posts: 2288
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: [0.10.2] AdMob support for Android!

Post by zorg » Wed Aug 09, 2017 4:36 am

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
Prole
Posts: 44
Joined: Wed Aug 19, 2015 4:13 pm
Location: Italy

Re: [0.10.2] AdMob support for Android!

Post by bio1712 » Wed Aug 09, 2017 8:24 am

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: 292
Joined: Sat Sep 24, 2016 11:20 am
Contact:

Re: [0.10.2] AdMob support for Android!

Post by yetneverdone » 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.

bio1712
Prole
Posts: 44
Joined: Wed Aug 19, 2015 4:13 pm
Location: Italy

Re: [0.10.2] AdMob support for Android!

Post by bio1712 » Wed Aug 09, 2017 4:04 pm

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
modiX
Citizen
Posts: 73
Joined: Mon Dec 04, 2017 1:47 am

Re: [0.10.2] AdMob support for Android!

Post by modiX » 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?
───▄▀▀▀▄▄▄▄▄▄▄▀▀▀▄───
───█▒▒░░░░░░░░░▒▒█───
────█░░░░░░░░░█────
▄▄──█░░░▀█▀░░░█──▄▄
█░░█▀▄░░░░░░░▄▀█░░█

Visual Studio Code Template

bio1712
Prole
Posts: 44
Joined: Wed Aug 19, 2015 4:13 pm
Location: Italy

Re: [0.10.2] AdMob support for Android!

Post by bio1712 » Tue Dec 12, 2017 5:58 am

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
modiX
Citizen
Posts: 73
Joined: Mon Dec 04, 2017 1:47 am

Re: [0.10.2] AdMob support for Android!

Post by modiX » Wed Dec 13, 2017 12:35 am

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 Template

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests