[Android] Admob and Google Play Game Services Support

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
master both
Party member
Posts: 255
Joined: Tue Nov 08, 2011 12:39 am
Location: Chile

[Android] Admob and Google Play Game Services Support

Post by master both » Sat Apr 23, 2016 4:29 pm

IMPORTANT: THIS LIBRARY IS OBSOLETE
I recommend that you use this one instead: https://love2d.org/forums/viewtopic.php ... 6&p=214482


Hi! since my old post on LÖVE-Android got locked, I have change my Bitbucket account, so the current links are broken, that's why I have decided to repost it here:

You can get the repository here:
https://bitbucket.org/npinochet/love-android-sdl2

For getting this to work you will need to add google-play-services_lib to your project, which I can show you how.
(Not any more!! :awesome: )

I added 14 new functions to love.system:
Admob Functions:
  • Banners:
    • •love.system.createBanner("Banner ID", "orentation", "size") where orentation can be "top" or "bottom" and "size" is a string with an AdSize Constant.
      •love.system.hideBanner() removes the banner from the screen.
      •love.system.showBanner() makes the banner reappear.
    Interstitials:
    • •love.system.createInterstitial("Interstitial ID") create the interstitial ad.
      •love.system.isInterstitialLoaded() check whether there is an ad loaded and ready to be shown.
      •love.system.showInterstitial() show the ad.
Google Play Game Functions:
  • •love.system.googlePlayConnect() Initialize the Google Play Game Services and promts the sign in dialog.
    •love.system.googlePlayDisconnect() It does what you think it does.
    •love.system.isGooglePlayConnected() Return whether the user is sign in or not.

    Achievements:
    • •love.system.unlockAchievement("achievements ID") "achievement ID" is the id generated at the Google Play Dev Console.
      •love.system.incrementAchievement("achievements ID", howmuch) This is for procedual achievements.
      •love.system.showAchievements() Shows the Achievements screen.
    Leaderboards:
    • •love.system.submitScore("leaderboard ID", score) "leaderboards ID" is generated at the Google Play Dev Console.
      •love.system.showLeaderboard("leaderboard ID") Shows an especific leaderboard screen.
      •love.system.showAllLeaderboards() Show a screen with all the leaderboars were the user can choose one.
Some Notes:
•If you want to use Achievements and Leaderboards, you will have to go to "love-android/res/values/ids.xml" and change the number there for your own App ID.
•You can get a "Banner ID" or "Interstitial ID" on the Admob website, they look like this:
ca-app-pub-9796530573307706/1938301675.

Now you can have full control of Google Play Services on lua!

Here you can see all the changes to the oficial love-android repository:
https://bitbucket.org/npinochet/love-an ... dl2:master

Thanks to bio1712 for making this possible :)

If anyone finds a bug or would like a feature to be added, just let me know ;)
Last edited by master both on Mon Oct 30, 2017 11:00 pm, edited 12 times in total.

User avatar
alberto_lara
Party member
Posts: 331
Joined: Wed Oct 30, 2013 8:59 pm

Re: [Android] Admob Banner and Interstitial Support

Post by alberto_lara » Sat Apr 23, 2016 4:33 pm

Wow, dude, since years I've been wondering if somebody would make something to help Add support in LÖVE, this seems very interesting :) keep going.

EDIT: Is it possible to show an example of how tu put the banner? (in a very simple game) Does this involve Java stuff? I'm not really good at these add things but I'm really interested.

EDIT 2: Never mind, I just saw you're putting the instructions there, seems pretty simple, thanks again :)
LÖVE Projects: GOOi, Süsse and Katsudö
Thank you for taking the time to read this

User avatar
master both
Party member
Posts: 255
Joined: Tue Nov 08, 2011 12:39 am
Location: Chile

Re: [Android] Admob Banner and Interstitial Support

Post by master both » Sat Apr 23, 2016 4:57 pm

alberto_lara wrote:Wow, dude, since years I've been wondering if somebody would make something to help Add support in LÖVE, this seems very interesting :) keep going.

EDIT: Is it possible to show an example of how tu put the banner? (in a very simple game) Does this involve Java stuff? I'm not really good at these add things but I'm really interested.
Thanks!
For getting it to work you have to build it just as you'll do in with the official repository, but you'll have to add the google-play-services_lib to it (which is the tricky part, if anyone has problems in this step, let me know). As for the game, just do something like this:

Code: Select all

function love.load()
	if love.system.getOS() == "Android" then
		love.system.createBanner("ca-app-pub-9796530573307706/1938301675", "bottom")
		love.system.showBanner()
	end
end
EDIT: oh didn't saw your EDIT2 :P well then...

User avatar
alberto_lara
Party member
Posts: 331
Joined: Wed Oct 30, 2013 8:59 pm

Re: [Android] Admob Banner and Interstitial Support

Post by alberto_lara » Sat Apr 23, 2016 5:07 pm

That code was actually pretty useful, thanks.
LÖVE Projects: GOOi, Süsse and Katsudö
Thank you for taking the time to read this

User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: [Android] Admob Banner and Interstitial Support

Post by Ranguna259 » Mon Apr 25, 2016 1:08 pm

First of all, AWESOME !!
Thank you very much for this, I've been thinking about doing this but I never came around to do it. Great work
Why won't you build the apk and post in in the download section of your repo.

I get an error when I try to update the project with the google play services lib:

Code: Select all

>android update project -p "path\where\lib\is\google-play-services_lib"
Error: The project either has no target set or the target is invalid.
Please provide a --target to the 'android.bat update' command.
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.

User avatar
master both
Party member
Posts: 255
Joined: Tue Nov 08, 2011 12:39 am
Location: Chile

Re: [Android] Admob Banner and Interstitial Support

Post by master both » Mon Apr 25, 2016 2:38 pm

Ranguna259 wrote:First of all, AWESOME !!
Thank you very much for this, I've been thinking about doing this but I never came around to do it. Great work
Why won't you build the apk and post in in the download section of your repo.
I get an error when I try to update the project with the google play services lib:

Code: Select all

>android update project -p "path\where\lib\is\google-play-services_lib"
Error: The project either has no target set or the target is invalid.
Please provide a --target to the 'android.bat update' command.
Thanks! I might just add an apk for testing, why not?
As for that error, I did forgot to include the target flag on my explanation, but I did answer this on my old thread: https://www.love2d.org/forums/viewtopic ... 10#p193125

User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: [Android] Admob Banner and Interstitial Support

Post by Ranguna259 » Tue Apr 26, 2016 7:17 am

I tried to install your apk but it fails to install and simple says "Application not installed".
I uninstalled the previous version of LOVE I had on my phone and it keeps failing..

I also successfully updated the project with google services lib but I'm getting another error:

Code: Select all

>ant debug
C:\Users\Admin\AppData\Local\Android\sdk\tools\ant\build.xml:573: /../google-play-services_lib resolve to a path with no project.properties file for project big/path/to/love-android-sdl2
This is the contents of project.properties in google-play-services_lib:

Code: Select all

# ^ comments ^
target=android-23

android.library=true
And this is the contents of your project's project.properties:

Code: Select all

# ^ comments ^
target=android-23
android.library.reference.1=/../google-play-services_lib
I don't know what the prompt mean by "no project.properties file for project big/path/to/love-android-sdl2" because clearly google-play-services_lib has a file named "project.properties", maybe the file needs to point to big/path/to/love-android-sdl2 ? But how ?
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.

User avatar
master both
Party member
Posts: 255
Joined: Tue Nov 08, 2011 12:39 am
Location: Chile

Re: [Android] Admob Banner and Interstitial Support

Post by master both » Tue Apr 26, 2016 1:22 pm

So many problems!
Ok I updated the .apk it should work now, I tested it on my phone.
As for that error, I believe that the project isn't finding the google-play-services_lib folder, are you sure it is right next to the project (love-android-sdl2) in the same path?

User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: [Android] Admob Banner and Interstitial Support

Post by Ranguna259 » Tue Apr 26, 2016 5:01 pm

All my problems have been fixed :D
The problem was that google-play-services_lib was inside love-android-sdl2 and not in the same folder and the apk works now.

Things that I'd like to see added to the API:
  • Something like love.system.isIntertitialClosed() or a callback love.interstitialClosed() to check when an intertitial add is closed.
  • A new adds class so I can write something like this:

Code: Select all

function love.load()
  add = love.system.createBanner('id','orientation')
end

function love.update()
  if IwantTo then
    add:show()
  else
    add:hide()
  end
  
  if something then
    add:changeID('id')
  elseif other then
    add:changePosition('position')
    --or add:changeOrientation('orientation')
  end
end
Other than that, the API is perfect, thank you very much and keep up the awesome work.

EDIT:
Nevermind implementing an intertiatial callback or a checker, interstitials stop the game from running while they are open so we don't have to worry about the game while it is open, awesome.
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.

User avatar
Kibita
Prole
Posts: 31
Joined: Tue Dec 29, 2015 7:46 pm

Re: [Android] Admob Banner and Interstitial Support

Post by Kibita » Sun May 01, 2016 3:17 am

Are you planning to add Google leaderboard or achievements system soon? I think this would be great!

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests