How to Insert AdMob Ads to an App Inventor 2 (AI2) App

Ever wondered how to integrate Google AdMob ads to your App Inventor 2 app? Until recently, it was impossible to do so free of charge since AI2 does not permit the inclusion of AdMob and the other available possibilities are all paid options through third-party tools.

This has changed – finally – with a website called Thunkable.

Follow these steps to include AdMob ads to your AI2 app:

1) visit the beta version of Thunkable (AdMob is only integrated to their beta version for now) at beta.thunkable.com;

2) Login with your Google account (gmail / the same used for your AI2 account);

3) Import your AI2 app by clicking on Apps -> Upload legacy app project (.aia) from my computer. It is important to use the legacy uploading option to retain AI2’s original package name. If you don’t, the package name will be thunkable’s and when you’ll try to update your published app on Google Play, it will show an error message.

N.B.: If using the legacy uploading method and if
AI2’s original package name includes uppercase letters
(i.e.: appinventor.ai_NYAppMaster.GuitarTabs),
Thunkable’s legacy method will probably transform it to lowercase
letters only (i.e.: appinventor.ai_nyappmaster.guitartabs) and this will
also be a problem when you try to update your app on
Google Play afterward.

So, here’s what to do in such a case:
download Notepad++ (available here: https://notepad-plus-plus.org/).
This free software will allow you to batch edit your apk file once it is
unzipped (if necessary, read another article of mine on how to
unzip and rezip an apk file: https://robertradford.com/how-to-overcome-mit-app-inventors-5-meg-limit-for-your-apk-files/).

Open Notepad++, press on ctrl-F and select the “Find in Files” tab.
Fill in the “Find what” (your original AI2’s package name, for example)
and “Replace with” (your lowercase-only package name) fields;
then, select the directory where your unzipped apk file is located and
click on “Replace all Files”. That’s it.
Even if thousands of entries are replaced, it takes only a few seconds.

4) Still in Thunkable’s main menu, click on your uploaded app project; once in, you shall see under the “Experimental” tab on the left side of the screen “AdMob Banner” and “AdMob Interstitial”. Drag and drop your preferred type of ad directly in your app designer section (middle of the screen).

5) Click on the AdMob component you just added and, on the right side of your screen, under “Properties”, you’ll be able to include your Ad Unit ID (you must be registered with AdMob; it’s free) and check the “Visible” option.  There’s also a “Test Mode” that can be checked (don’t click on your own app’s ads if the test mode is unchecked!).

6) In the blocks’ section, include a “call AdMob_Banner1.Load Ad” trigger under the “when Screen1.Initialize do” component. Moreover, you’ll need to create this component (three blocks): “when AdMob_Banner1.Ad Loaded do” -> “set AdMob_Banner1.Visible  to” -> “true”.

Done!

Kudos to Thunkable’s team by the way!

Advertisements

How to overcome MIT App inventor’s 5 meg limit for your apk files?

Good day all,

Here’s a solution to the 5 meg limit imposed by MIT’s App Inventor Classic and App Inventor 2…

1) Save your AI app as a .apk file.

2) Download ApkTool from http://ibotpeaches.github.io/Apktool and install it to your computer.

3) Copy your .apk file to the Apktool folder located in your computer’s c: drive (should normally be located at c:/apktool).

4) Open your computer’s command prompt terminal; be sure to go back to the c:/ by typing cd.. in the terminal (you may have to do so more than once). Once at c:/, type cd apktool (if you installed Apktool in this particular folder, that is).

5) Still in the terminal, type apktool d NameOfYourFile.apk (i.e.: apktool d Test.apk). This will “unzip” your .apk file and a folder (NameOfYourFile) shall be created; in it, you’ll find your .apk’s manifest and other related folders and files. If you see a folder called meta-inf, delete it. Open the asset folder; you will be able to update your files there (delete or add any required files for your app)… The good news is: no need to worry about the 5 meg limit anymore!

6) Once this is done, go back to the terminal and type apktool b NameOfYourFile NameOfYourFile.apk (i.e.: apktool b Test Test.apk).

7) By doing so, you now “zipped” back your app to a standard .apk file, which also includes the files you added to the asset folder. Copy this new .apk file back to your desktop…

8) You will now have to use a program called JarSigner in order to sign your .apk file. It is notably included to Java version 1.6.0.45 and that is the version that I use (Jarsigner may not be included to later versions of Java though). Hence, you can download Java 1.6.0.45 from http://filehippo.com/download_jre_32/14872/. Once this Java version is downloaded and installed to your computer, you will have to open a command prompt terminal and locate the Jarsigner program. In my computer, it is under Java’s bin folder… c:/Program Files/Java/jdk1.6.0_45/bin/…

9) Once in the bin folder (and always in your command terminal), type: jarsigner -verbose -sigalg MD5withRSA -digestalg SHA1 -keystore android.keystore C:LocationOfYourDesktopNameOfYourFile.apk androidkey  (i.e.: jarsigner -verbose -sigalg MD5withRSA -digestalg SHA1 -keystore android.keystore C:UsersRobDesktopTest.apk androidkey)

10) Jarsigner will ask for your keystore passphrase… by default, the AI keystore passphrase (or password) is “android”. Your .apk is now signed. Bravo.

11) Before uploading it to Google Play, you still need to zipalign it! The Zipalign tool is part of Android SDK (1.6 onwards) and can be found under the tools folder of the SDK. To use it, you will have to run the following command in your terminal: zipalign -v 4 source.apk destination.apk. In example: zipalign -v 4 Test.apk Test2.apk … Once the zipping is done, delete Test.apk and rename Test2.apk to Test.apk (in order to preserve the original name of the file).

12) Test your .apk in your mobile phone and if everything’s fine you’ll be ready for uploading it to Google Play !

If you would like to obtain help regarding this procedure, feel free to contact me. For US$20.00, I shall update your .apk file accordingly and make it ready for your Google Play upload. Please include your zipped .apk file to your email (you can use 7-zip to do so, a free tool) and mention your keystore passphrase if modified from the default “android” value. I shall respond with a Paypal link for your payment as well as a server link where you’ll be able to upload the files you would like to add to your asset folder. Once your payment is through, you will receive a final email including the updated .apk file.

Best regards.