Building A V2 Android Plugin! Basics with Godot 4.2

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys this is Mitch with fineo CGI and today  we're going to talk about how to do Android   plugins inside of the new version 2 plug-in system  inside of gdo so we're going to go through the   process of creating the plugin then we're going  to talk about how to set up your entire build   system to work with the new plugin we're going to  talk about how to get the plug-in system working   we're going to add in the Android build template  then we're going to talk about how to call those   functions and get back information from those  functions and we're going to talk about how to   attach signals to your Android plugin so that's  what I have in store for you guys today let's go   ahead and get started okay so the first thing that  we need to do is we need to actually go over some   prerequisites so if you don't have the ability to  export to Android on Gau be sure to run through   that tutorial I have it linked in the description  below so that way you guys can go through that set   up your stuff to get ready the other big thing  that we're going to need to do is we're going   to need to have Android Studio installed Android  Studio is the default tool that a lot of people   use when they actually do their development now  I actually have that Linked In the description   below as well and if you go through that Android  tutorial I do install it in that tutorial now   once we have that let's go ahead and actually  get going so first things first we need to   actually build our Android plug-in so let's open  up Android studio and create a new project now if   you have ever used Android Studio before and if  you open it up it'll look like this this is a   previous project you had open right you can click  file new project and then go ahead and open up a   new project that will get you this menu here if  you've never opened up Android Studio if I close   this project I believe it is right here close  you'll see that it should show something like   this so you can actually come in here and click  on new project so click on that no activity double   click on that and then let's go ahead and name it  Android plug-in tutorial now you can come in here   and change your package name to whatever you want  in my case I'm going to go org gdo engine plugin   Android Android plug-in tutorial now that's might  be required it might not it's something that in   my testing it seemed to work when I do it this  way but you might be able to get away with using   your own name space as well now I'm going to click  finish and that's going to go ahead and build this   plugin so we're going to let this run and I will  be right back now you will see here that we have   a app a Gradle scripts and a Java section here  these are the major areas that you really care   about and your manifest is kind of important so to  explain the uh ecosystem of a plug-in and actually   really just Android in general is you have a  manifest file and this manifest file describes   what you're building and then you have your Java  section which is basically all of the code that's   associated with that plugin so if you're going in  and you want to build like a hello world plugin   which is what we're doing this is where all of  that codee's going to live and then over here on   the bottom section is all of your Gradle settings  now these actually do matter quite a bit now you   have the project Gradle and then you have the  build Gradle project Gradle we're not going to   mess with as much but the build Gradle we really  will play with because there's a lot of changes   in here that we're going to need to make so  let's start with the build Gradle and let's   go from there so if we take a look at our build  Gradle first things first you'll see it says ID   Android application let's change that to a library  because that's going to tell it to be a library   simple enough and now if we come down here let's  check our Min SDK let's make it 24 because that's   what gdau requires and then let's come down here  change this from 1.8 or in this case it's Java   8 I don't know why they do 18 but it's fine we'll  change it to version 17 because that's the version   that could uses so we'll go ahead and pull those  guys in and then for dependencies we're going to   add in the gdau dependency the thing is is for  us to be able to use gdau assets as a feature   inside of our plugin we need to actually have it  here so we'll say implementation quote org do do   engine. gdo colon Gau colon 4.2.1 . stable and  I spelled stable wrong stable and that's going   to give us the gdau engine source code well at  least the plugin for Gau engine so we can actually   build our plugin and from here we can go up to  our Android manifest and we can basically make   some small adjustments here so what I'm going to  do is I'm going to get rid of this segment here   and I'm going to go bracket application enter meta  data enter Android name is equal to or.do engine.   plugin do uh dot V2 Dot and then the name of our  actual class so what I'm going to do is name it   hello world and then I'm going to hit enter and  then I'm going to say Android value or.do engine   plugin. Android do Android plugin tutorial  do hello world like that now you're probably   wondering okay this is like magic here right so  what is this doing so what I'm doing is this is a   class that I'm going to be creating this is the  location of that class so you can see here or   Gau engine plugin Android Android plugin  tutorial or gdo engine plugin Android   Android plugin tutorial now I should probably  uh camel case this just because it makes more   sense though I guess really they didn't so  maybe we shouldn't but I just don't I don't   know if I like it but you can see here that  this is equal equivalent to this and this is   telling gdau where it exists inside the gdau  ecosystem if that makes sense and what will   do from here is we'll basically come in here  we'll double check this make sure that it's   happy which it is we'll go to our module double  check to make sure that's correct so we have our   Android namespace config I'm just looking to see  if there's anything that mentions an application   ID which it does it is right here so we're going  to want to pull this out we don't need that so   we'll contr s we'll sync our Gradle we'll let that  sync and then we'll come in here we'll rightclick   new new Java class and we'll say hello world  because that's the class that we're going to be   building now you'll see that this matches this  this right here this guy this package matches   exactly with this package here if that makes  sense so that's how we do this and then from   here we basically need to extend this class into  some kind of um gdau plug-in so we'll hit colon extends gdau plugin like that and you'll  see that we have an underline so let's   rightclick show context actions and there  is none so that's not great but let's see   if we can get this to work anyway so we'll  come up here and we'll say import org. gdo engine. gdo do gdo and then we'll  also import org. gdo do plugin do actually we should probably do g. plugin. gdo  plugin see if that works it still doesn't like it   class or interface is expected oh I'm dumb I don't  need the colon there we go let's try that let's   get rid of the colon let's do show context actions  and you'll see that it has an Implement method so   we'll click Implement method and we'll hit okay  and it will Implement our plug-in name method now   what I'll do is I'm going to return quote our  class name hello world like that and now this   is where things kind of change quite drastically  actually if we want to make a function and in this   case we're going to make a Hello World function  what we have to do is we have to make the function   so public void hello right the name of the  function then all we have to do is write our code   right so what I want to do is I want to make it so  it does a modal popup like a little toast message   so I'll say get gdau do get activity do run on UI  thread new runnable like that public override run   toast dot make text get Gau do get activity comma  quote hello world exclamation point Exclamation   point you can add as many exclamation points as  you want that's not going to affect anything do   toast comma toast do length long that's how long  it's going to show and then we'll say do show and   that's going to show that guy right there and  that's all we really need to do well not quite   we need to tell gdau that this exists now back  in the day what we would do is we would have a   function that called out all of the classes by  name but now with the new version of gdau we   could just hit at used by gdau and that's it and  then it's going to get registered just fine so   it saves us a lot of trouble and it makes things  a lot easier now you'll also notice that we have   an underline here so let's rightclick show context  create Constructor matching super so we'll click   that and it'll build out that Constructor right  here which is another thing that we kind of need   to have for this to work properly so now at this  point if we click the build button let's see what   happens hopefully it works well it looks like it's  successfully built so let's go out to where this   is located so we're going to right click and go  open in Explorer and that's going to open up an   Explorer window right here let's go out to our app  build outputs a AR and there is our a file awesome   right so now we have to get the Gau side to work  right and that's going to be a whole process in   itself so let's head over to gdo let's hit new and  say Android the plugin V2 tutorial like that going   to create that folder and hit create and edit now  I'll snap G to our screen right here and you'll   see we are in Gau hooray right so in order for  us to be able to do plugins first things first   we need to right click our RS and I'm going to  create a new folder I'm going to call it add-ons   like that I'm going to rightclick open in file  manager and that's going to open up this in a file   manager I'm going to rightclick new folder and  I'm going to call this hello world like that I'm   going to double click on this guy and I'm going to  come into my a file I'm going to copy this a file   and drop it in like that and now we are pretty  much good to go to set this up so thankfully   gdau has relatively made this a bit easier for  us and then we'll go back into Kau we'll go to   project project settings we'll go over to plugins  and click create a new plugin and for the name we   will call it hello world for subfolder we need to  choose where it's going to be I believe we chose   if I remember correctly hello world so we'll do  that we'll say hello world for description we'll   say test plugin for Gau integration for author  we'll say Mitch version 1.0 language will'll do GD   script though technically you could probably get  away with whatever you want to call it now in for   the script name what we need to do is we need to  come up with a script name so in our case I'm just   going to say hello world. GD and we'll need to  choose a subfolder so I guess I did this backwards   so let's CH let's go ahead and fix that so let's  go in here let's get rid of our hello world folder and do that so we'll hit create and that's  going to create the subfolder so it looks like it   already creates that subfolder and then we'll go  into our a and we'll drag our debug a into here   like that simple enough and you'll see that we  have an enter tree and an exit tree now the nice   thing about these class here is that it's actually  relatively easy to build out this thing so gdau   went from a configuration system for your plug-in  to basically they basically combined the plug-in   system so that instead of it being separate  for Android and everyone else they made it so   that everybody uses the plug-in system so that's  kind of the route that we're going here and now we   basically need need to create and initialize that  plugin so let's come down here and create a class   to do that now I basically stole this from the  gdau documentation so they actually have this bit   here that you guys can use but what I'll show you  guys is how to build it so class Android export   plugin extends editor export plugin like that and  this is basically where you build that plugin and   we will will come over here and basically create a  plug-in name so VAR plugin name is equal to quote   and we're going to name our plugin so hello world  I know it seems like we're repeating a lot of   information and we kind of have to unfortunately  gdau doesn't exactly make this simple so we just   kind of have to make it work so first things first  what the gdau community recommends is that you   check to see if your uh stuff is supported by  that um platform so we'll say funk underscore   supports platform platform and we'll basically  say if platform is editor export platform Android   then return true and this is basically gd's way  of allowing us to um determine if we are on the   proper platform so if you're not on the proper  platform it's not going to load that plugin if   that makes sense so that's what that's for then  we'll say funk _ Gore Android libraries platform   debug and basically what this is for is it will  return where that a binary is so you can check   if debug like so and then you can basically return  a packed string array of bracket bracket and then   wherever our stuff is located so in our case it's  located in hello world slash and we got to come   up with our our a file so I believe we named it  app debug. we should probably change that but for   right now we'll we'll go with that so app debug a  and then we'll say else and we'll just copy this   and paste it because I'm just going to use the  debug one but if you have a release version of   that a file that's what this is for you could  put that guy in there and it'll actually work   and now we need to tell Android if there's any  special dependencies that go with this so we'll   say funk uncore get uncore Android dependencies  and then we can basically just do the exact same   thing here copy this and paste it and then  basically send back an empty pack string   array because we don't have any dependencies now  this is useful if you have any dependencies that   you need to have brought along with you you could  put them in here here and it will bring them along   and then the last one that we need is to get back  our name so we'll say funk get name like that and   we're going to return our plug-in name like that  and that's basically all that you need to create   your editor plugin and now all we have to do is  come up here and basically initialize it so VAR   export plugin is type Android export plugin now  remember this does not have to be Android export   plugin I did this because that's just what they  have as default but you could call it whatever   you want and it will work and then we'll come down  here and initialize our plugin so export plugin is   equal to Android export plugin. new like that and  then we can hit add export plugin export plugin   and then on exit we're going to want to clean  that up right so we'll say remove export plug-in   like that and then export plugin is equal to null  now you might be wondering okay Mitch what the   world is all of the stuff right well all of this  allows us to bring that plugin into memory and   use that plugin inside of the editor it allows us  to be able to actually read the plug-in data and   use it as expected if that makes sense and it also  allows us to register with the gdau runner so that   it knows that we have this plug-in more or less  now at this point what we have to do is we have   to go to Project install Android build template  and click install now if this doesn't exist for   you you need to install the actual export template  so if you go to export and you click add Android   if you see anything down here that says hey like  you can't export because of such and such make   sure that you run through that I do go through  a lot of that in my Android export tutorial so   check that out but then we need to make sure we  click use gradal build because that's going to   actually allow us to have a Gradle build now  at this point we're basically done we can use   our stuff so let's click close let's go to user  interface let's rightclick add a child node let's   add in a button like so let's right click our  control attach a script and let's call it scene   manager because I always have a scene manager I'm  going to hit contr s save this as control and then   I'm going to click on this button node button down  and I'm going to connect it to my control node now   I am also going to adjust this button to make it  nice and large and I will say Hello World on that   button so if I click on it like that now if I go  back to here how do we actually interact with that   plugin that's a whole another conversation that  we have to have because interacting with a plugin   is completely different than doing anything else  right and thankfully it is relatively easy let's   go up to the top and say VAR plugin and then let's  come down to our ready and say if engine do has   Singleton quote and our name of our class hello  world like that and then we can come in here and   say if we have that plugin VAR plugin is equal  to engine. getet Singleton well I need capital e quote hello world like that  else we're going to print an error cannot find plugin and then under  our button down press let's go ahead and   fire off that hello world so plugin. hello  world and I don't remember if we capitalized   hello world or if we just did hello I think we  just did hello let's take a look at our plugin   we did hello that was it with a capital H so we'll  do hello and now from here we can actually plug in   our Android device so let me go ahead and grab  that and I will be right back and once you have   it plugged in you should be able to see in the  upper right hand corner right here this little   icon called remote debug now if you don't have  this icon that's totally fine but it is something   that can be really useful so go ahead and see if  you guys have that and um just make sure that you   know that your remote debug is set up and if  it's not set up go through my tutorial I walk   you guys through this part so we'll click remote  debug click Google pixel 7 in my case and it says   no main scene has been defined uh let's go ahead  and just select current that's going to select my   current scene and we're going to let this export  hopefully it exports properly it probably won't   it never does the first time for me so we'll we'll  see how that goes but it should hopefully work oh   wow it actually worked the first time so that's  really surprising actually so let's come in here   and you will see that we have our Android plugin  now if we click hello world well nothing happens   so what in the world happened well let's go CMD  let's take a look so let's do ADB log cat- sgo   user script error not existent function hello on  base nil cannot find plugin so it could not find   our hello world plugin so somewhere in this entire  linking process we made a mistake so that's good   so let's take a step back let's look at what  we did so our hello world is set up correctly   I believe here we called hello world out right  here so hello world so that's good we have our   package right here so that should be good Android  manifest has hello world here so that's good this   is the correct path with Hello World calling out  our class so that's good we look at our build   Gradle that looks fine we look at this guy we have  our name space right here so that is good this   is a library so that's good all of this probably  would have had a build error if we actually made   a mistake so thankfully I don't think this is the  problem so let's take a look in here we have our   plug-in config which is correct but I'm curious  if we go up to our project project settings and   we take a look at our plugins it is enabled so  that's unfortunately not the issue which kind   of stinks because I was hoping it was that if  we take a look at our hello world you can see   that it is pointing to the correct GD script I  believe but it's possible that it might not be   we take a look at this we have hello world right  here and then we're pointing to an app debug. if   we take a look at our hello world we have our app  debug a AR so that should be correct so something   went wrong here's our plug-in name hello world  that's correct as well so unfortunately we're   going to be caught in a bad spot I think we do  have our project set up this is correct here okay so I think I figured it out so basically  what's going on is that we need to inform the   Gau Gradle system that our plug-in exists now  from what I have figured out is basically we   need to add in some build config field so if  we come in here and type build config field   parentheses quote string comma G doore plug inore  name comma quote slash quote other slash SL quote   and then we'll put in our class so hello world  SL quot quote like that and then we basically   need to do the same thing but down here in the  build types so we'll come in here and we'll say build config file or field I should say and  then we'll paste it twice we'll change this   to plugin package name and we'll  go in here and go org Dogo engine. plugin Dot and then we'll use our actual Android  plugin tutorial so we'll go Android plugin   tutorial. hello world and that's basically going  to tell gdau where the package is and then we'll   come in here and have hello world and then we'll  say plugin name like that and then we need to do   the exact same thing but for debug so we'll copy  this and we'll type debug bracket bracket paste   now you can't use this without having the build  feature on so we'll come in here and we'll say   build features and do build config is equal to  True like that and that'll basically allow for   this to work out now once we have this there's  another small issue I ran into in the Rees folder   there's a bunch of additional folders in here if  you just expand that and get rid of everything in   there so just delete that entire you know folder  structure out and just leave the reses folder here   and it should be fine and now from here we'll hit  build we'll let this build and it's mad so we did   it wrong so let's take a look could not find  method debug for arguments I believe I think   it's because we have parentheses around these I  don't think you're supposed to have parentheses   so let's get rid of those parentheses like this  do the same thing down here get rid of these parentheses and then let's see what happens  if we hit build and there we go we have a   successful build so now let's go into our a  let's go into our hello world let's control   a copy paste replace and we're good to go so now  if we head back to gdau here and we take a look   at our code here you'll notice that we have a  VAR here let's get rid of that because we don't   want to do that um basically that VAR makes it  so that we can't uh have a global reference to   that plugin so once it gets down here it it's  basically null right so now we can hit debug   and and we'll click hello world and you'll see  that it pops up with Hello World awesome so our   plugin is actually working it's now running out  it's firing this off right here and it's getting   it to work so now the question is great so we have  everything working so how do we return stuff well   that's easy if we type string like this and  then we come down here we can actually just return hello world with a bunch of exclamation  points so now if we build this you'll see that   if we go into our a our hello world copy  this guy paste it replace destination go   in here and then just say print bracket  hello world like that if we rerun this you'll see that since we have that ADB log  cat up we can take a look at this so if we hit   hello world it's going to come back and print  out that hello world because we returned that   hello world back to good so that's basically  how you send stuff out and receive things so   now the question is okay so we have all of that  which is exciting how do we do signals because   signals is a gigantic part of gdau well that's  actually really simple if we head back to our   Android studio right here we can come down here  and create a signal so when you want to create a   signal all you have to do is create a function  for it so we'll say public set signal info get plugin signals like that and  then all we have to do is say set signal info signals is equal to a new array  set like that and then we're going to return that   signal like that now it's going to be mad at us  so let's hover over here and see what's going   on it says that something clashes with something  else so I'm going to rightclick show context make   plugin signals return Java set plugin signal  we'll click on that and that's going to fix   our issue and then all we have to do is just  add that signal so we'll say signals. add and   we can add in a new signal info and then we can  name it so we'll say hello signal like that and   then we can do if we want to return something  we can go comma and then we can put in what   we want to return so in my case I'll just do a  string like that string. class and there we go   and then I can come in here and emit that  signal so we can say emit signal quote hello   signal like that comma and we'll pass in what  we want to send back so this is a return from   a signal like that now we can build this and we  should be good to go it should build successfully   hopefully we'll click on our app debug a  we'll paste it over replace and then we'll go   back to gdau like this we will come in here  and we'll basically connect up our signal   now thankfully this should be relatively easy  let's just come up to our plugin up here when   we get our plugin we'll say plugin plugin Dot  and then we could pick our signal name and I   believe our signal name was hello signal so we'll  do that paste dot connect and then we can pass in   the function we want to run now in my case the  function I want want to run is just going to be Funk signal return and I'm going  to pass in my string that I get   back so I'll just do Str Str like  that and I'll just print that Str Str and then I'll connect that signal  return like that now I don't think I   need to do that I can just do that if I remember  correctly that should work now if I hit play in   this should work hopefully so we'll bring up this  guy here we'll click hello world and you'll see   that we have hello world and then this is a return  from a signal so we successfully subscribed to our   signal and fired off our signal return when  that signal got emitted and now that you have   the basics that's pretty much everything that you  need to know about how to do a plug-in with the   new version 2 Android plug-in system inside of  gdau so if you like this video go and hit that   like button hey you know if you dislike this  video go and hit that dislike button cuz I'm   here to make content for you guys this video was  a viewer suggested tutorial which is what all of   my tutorials are so if you have any suggestions  please leave them in the comments below or jump   on my GitHub link is in the description to my  suggestion slot and just go ahead and suggest   something that's how I keep track of all  of my suggestions as it is so it's really   helpful for me to keep things organized there  and hey if you have any questions or comments   ments please leave in the comments below  or jump on my Discord the link is in the   description and anybody there will be more than  happy to help you out I freak with that Discord   all the time so I can always help you guys out  if I see your message but that is all I have for   you guys today so thank you so much again for  watching and I'll see you all next time thanks
Info
Channel: FinePointCGI
Views: 894
Rating: undefined out of 5
Keywords: godot, godot engine, godot 4.2, godot 4, godot game engine, advanced godot | importing photos with the android camera, how to export to android in godot, custom plugins in godot, godot engine 4.2, godot 4 android ads, intall godot game in android, godot 4 android admob, exporting from godot android, godot android, godot 4.0, run godot game in android devise, godot to android, godot tutorial, install godot application in android phone, godot admob android
Id: Vy9Nrbrr8H8
Channel Id: undefined
Length: 33min 33sec (2013 seconds)
Published: Mon Apr 15 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.