Page 1 of 1

Android AdMob

Posted: Mon Jan 22, 2018 12:03 am
by LunaRebirth
Hi guys,

I'm trying to set up firebase admob for my Android project.
After following the instructions on the Google site with this code:

Code: Select all

    Game::jniEnv = 0;
    Game::state->activity->vm->AttachCurrentThread(&Game::jniEnv, NULL);
 
    // Create the Firebase app.
    firebase::App* app =
        firebase::App::Create(firebase::AppOptions(),
                              Game::jniEnv,
                              Game::state->activity->clazz);
 
    // Your Android AdMob app ID.
    const char* kAdMobAppID = "xxxxxxxxxx";
 
    // Initialize the AdMob library with your AdMob app ID.
    firebase::admob::Initialize(*app, kAdMobAppID);
 
    ///
    firebase::admob::InterstitialAd* interstitial_ad;
    interstitial_ad = new firebase::admob::InterstitialAd();
 
    const char* kInterstitialAdUnit = "xxxxxxxxxx";
 
    // my_ad_parent is a reference to an iOS UIView or an Android Activity.
    // This is the parent UIView or Activity of the interstitial ad.
    interstitial_ad->Initialize(static_cast<firebase::admob::AdParent>(Game::state->activity->clazz), kInterstitialAdUnit);
I get a crash on

Code: Select all

firebase::App* app = firebase::App::Create(firebase::AppOptions(), Game::jniEnv, Game::state->activity->clazz);
Looking into the problem, it is likely from Google Play Services not being found.
After adding these to my..

AndroidManifest.xml

Code: Select all

<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
My Android Activity

Code: Select all

import com.google.android.gms.ads.InterstitialAd;
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
I get these errors:

Code: Select all

    [javac] C:\Users\Admin\Desktop\Project\app\src\com\Project\app\Project.java:22: error: package com.google.android.gms.ads does not exist
    [javac] import com.google.android.gms.ads.InterstitialAd;
    [javac]                                  ^
    [javac] C:\Users\Admin\Desktop\Project\app\src\com\Project\app\Project.java:23: error: package com.google.android.gms.ads does not exist
    [javac] import com.google.android.gms.ads.AdListener;
    [javac]                                  ^
    [javac] C:\Users\Admin\Desktop\Project\app\src\com\Project\app\Project.java:24: error: package com.google.android.gms.ads does not exist
    [javac] import com.google.android.gms.ads.AdRequest;
    [javac]                                  ^
    [javac] C:\Users\Admin\Desktop\Project\app\src\com\Project\app\Project.java:25: error: package com.google.android.gms.ads does not exist
    [javac] import com.google.android.gms.ads.AdSize;
    [javac]                                  ^
    [javac] C:\Users\Admin\Desktop\Project\app\src\com\Project\app\Project.java:26: error: package com.google.android.gms.ads does not exist
    [javac] import com.google.android.gms.ads.AdView;
    [javac]                                  ^
    [javac] 5 errors
    [javac] 3 warnings
 
As well as error:

Code: Select all

Error:(113, 28) No resource found that matches the given name (at 'value' with value '@integer/google_play_services_version').
Could anyone help me?
Thanks

NOTE:
I have installed the Google Play services from Android Studio.
I am using ant, so Gradle answers (the only answers I could find online) will not work.

Re: Android AdMob

Posted: Mon Jan 22, 2018 11:39 am
by CuteAlien
Libraries have changed a lot since I coded that stuff last time (also should update mine as they likely no longer work...). But back then it wasn't enough to install google play services but at least for billing I needed more libs. Maybe also for admob, I really can't remember. I can give you the list of libs I had to install back then, but likely that list changed by now and I might have needed some of them for other reasons. But might give you an idea:
- Extras - Android Support Library
- Extras - Google Play services
- Extras - Google Repository
- Extras - Google Play APK Expansion Library
- Extras - Google Play Billing Library
- Extras - Google Play Licensing Library
- Extras - Google Web Driver

Re: Android AdMob

Posted: Tue Jan 23, 2018 7:54 am
by LunaRebirth
I downloaded all of those and the problem persists.

It looks like a simple fix using Gradle, but unfortunately Android Studio makes it difficult for me to create a new project with source that already exists. Can't seem to figure out how to compile the Irrlicht Android tutorial with Android Studio.
Oh well..

From https://stackoverflow.com/questions/411 ... mmand-line, I should be able to extract the jar (done) and somehow build it in my project.

The extract file from an answer on the link above contains only a single file:
C:\Users\Admin\AppData\Local\Android\sdk\extras\google\m2repository\com\google\android\gms\play-services-ads\11.0.4\play-services-ads-11.0.4\classes.jar


If I could somehow import this file into my build.xml or something, perhaps it could work.
I'm having a tough time figuring out how to do this, though. Have you had any experience including .jar files into your Android project?

Re: Android AdMob

Posted: Tue Jan 23, 2018 11:20 am
by CuteAlien
OK, I'm also bad with java build systems (struggled with that stuff infinite hours in H-Craft - I actually spend more time on getting admob and billing working than on porting the whole game to Android and the build-system was on of the reasons) . But usually you should not have to care about extracting jar files and similar stuff when using admob. But there can be something you have to do to find the library. I'm not sure right now how I got it to add that line... but in the end the google-play-services_lib should have it's own line in your project.properties. Somehow you can get ant to add it there. So maybe let's start there ... does your project.properites file already contain a line like "android.library.reference.1=libs/google-play-services_lib" below the "#Project Target."?

Re: Android AdMob

Posted: Tue Jan 23, 2018 5:19 pm
by LunaRebirth
No, it doesn't. When I add it, the program says it can't be found.
I looked through HCraft and didn't see it in the libs folder -- do I take the Google play services .aar file and put in the libs/ folder under that name, or am I missing something?
( after extracting play-services.aar, it only contains R.txt and AndroidManifest.xml, nothing else )

Note that the Google Play Services no longer come with a "libproject" folder, which is all I'm seeing online.
Several answers on this topic is "I just removed that line from the properties file and it worked fine"

Re: Android AdMob

Posted: Tue Jan 23, 2018 8:37 pm
by CuteAlien
Name has likely changed by now and I didn't have to move around any libraries, but that was in the default folder of the SDK. I just think I needed that one to get it to link back then, but not really certain about it anymore... will write again if I figure out/remember more.

edit: I suspect the better solution might be to get Irrlicht running with gradle and Android Studio. I get the feeling support for other build-systems is not much supported anymore.

Re: Android AdMob

Posted: Sat Jan 27, 2018 8:50 pm
by LunaRebirth
I think I (almost) got Irrlicht working with Android Studio. Once I get it working, I'll create a tutorial.

I'm able to compile, so long as I don't use createDeviceEx(), which is really strange.

I'm using the Irrlicht Android example program. What would be a reason that all Irrlicht functions work, but not createDeviceEx()?
The libIrrlicht.a library is correctly linking (set to ${ANDROID_ABI}/libIrrlicht.a for all devices), and #include <irrlicht.h> is also correctly being included.

EDIT:
Nevermind. For some reason, Irrlicht didn't build for x86, which my device was running.
I got the example to run on with gradle on Android Studio.
I'll make a tutorial tonight for it.

Re: Android AdMob

Posted: Mon Jan 29, 2018 10:23 pm
by LunaRebirth

Re: Android AdMob

Posted: Mon Jan 29, 2018 11:45 pm
by CuteAlien
OK, so you build Irrlicht with ndk-build and the use the build library in gradle in your project. Nice solution and thanks for the tutorial!
I hope you get firemob admob now working as well.

Re: Android AdMob

Posted: Tue Feb 06, 2018 4:56 pm
by LunaRebirth
CuteAlien wrote:OK, so you build Irrlicht with ndk-build and the use the build library in gradle in your project. Nice solution and thanks for the tutorial!
I hope you get firemob admob now working as well.
Yes, it ws very simple to set up after switching to Gradle.
I followed the instructions here:
https://firebase.google.com/docs/cpp/setup
and
https://firebase.google.com/docs/admob/cpp/quick-start

Thanks for your help :)