Is there any way to integrate ads such as Google's Admob library into gluon mobile on either android or iOS or hopefully both?
This is the gradle file, I have downloaded the Google Play Services library and the google Repository :
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.javafxports:jfxmobile-plugin:1.2.0'
}
}
apply plugin: 'org.javafxports.jfxmobile'
repositories {
jcenter()
maven {
url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
}
}
mainClassName = 'graphing.calculator.Calculator'
dependencies {
compile 'com.gluonhq:charm:4.3.0'
androidCompile 'com.google.android.gms:play-services-ads:9.4.0'
}
jfxmobile {
downConfig {
version = '3.2.0'
plugins 'display', 'lifecycle', 'statusbar', 'storage'
}
android {
manifest = 'src/android/AndroidManifest.xml'
androidSdk = '/Users/aniket/Library/Android/sdk'
}
ios {
arch = "arm64"
infoPList = file('src/ios/Default-Info.plist')
forceLinkClasses = [
'com.gluonhq.**.*',
'javax.annotations.**.*',
'javax.inject.**.*',
'javax.json.**.*',
'org.glassfish.json.**.*'
]
}
}
project.afterEvaluate {
explodeAarDependencies(project.configurations.androidCompile)
}
Yes, there is a way, for both Android and iOS.
This answer already contains a snippet of how it could be done on Android. But I'll update it here using and extending the Charm Down library. I won't include the iOS solution, though, as it requires modifications in the jfxmobile plugin, as I'll explain later.
Create a new project with the Gluon plugin, and modify the following. You'll have to keep the package names I mention, but you can name your project (and package) as you want.
build.gradle
scriptYou need to include the Google Play Services library:
Note the last task: it explodes the
aar
files on the android/google local repositories, to extract the jars (in this case the Google Play Services jar and all its dependencies).Note also that after modifying the build file, you need to reload the project (to sync the project and manage the new dependencies).
Besides the project files, you need to add this package:
com.gluonhq.charm.down.plugins
, and these classes:AdViewService
interfaceAdViewServiceFactory
classIn the Android/Java package, add this package:
com.gluonhq.charm.down.plugins.android
, and this class:AndroidAdViewService
classIt makes use of
com.google.android.gms.ads.AdView
. If your Android dependencies already include Google Play Services, you won't have any problem with the imports. Otherwise, go back to step 1.Note that I'm setting a layout where the banner will go to the bottom of the screen. Change this at your convenience.
AndroidManifest.xml
You need to add this to the manifest:
Note the Google Play Services value corresponds with the 9.4.0 version.
Now you can add the service to your project. For that you'll need an Ad unit Id. You can create an account on Google AdMob to add your app, and get the App ID for the banner unit.
To get the test device id, you'll have to run the app first, and find in the console the id with
adb logcat
.You should see the ads at the bottom, and some logs at the console as well.
For iOS it is possible as well. The problem is that it requires downloading the Google Mobile Ads SDK, and adding the
GoogleMobileAds.framework
to the list of frameworks, so when compiling the native code it finds it.This should be done in the
jfxmobile-plugin
, so it is out of scope in this question for now.