0

I'm having some issues about Google's AdMob integration on my gluon project. I'm following the answer at this link:

Gluon mobile cross-platform adsView

At the step 3 i have this problems about imports:

  • The import android cannot be resolved
  • The import com.google cannot be resolved
  • The import javafxports cannot be resolved

I've already checked other answers about this kind of problems on other topics but noone of them solved my problem.

Can anybody help me to solve the problem?

Thanks in advance

EDIT

This is the code required by Jose's comment. Here is my build.gradle:

buildscript {
    repositories {
        jcenter()
}
dependencies {
    classpath 'org.javafxports:jfxmobile-plugin:1.3.5'
   }
}

apply plugin: 'org.javafxports.jfxmobile'

repositories {
jcenter()
maven {
    url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
}
}

mainClassName = 'com.gluonapplication.GluonApplication'

dependencies {
   compile "com.gluonhq:charm:4.3.3"

    androidCompile 'com.google.android.gms:play-services-ads:9.4.0'
    //androidCompile 'com.google.android.gms:play-services-ads:10.2.1'
}

jfxmobile {
    downConfig {
        version = '3.2.4'
        plugins 'display', 'lifecycle', 'statusbar', 'storage'
    }
android {
    manifest = 'src/android/AndroidManifest.xml'
}
ios {
    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)
}

and this is the class where i found errors:

import android.view.Gravity;
import android.widget.LinearLayout;
import com.gluonhq.charm.down.Services;
import com.gluonhq.charm.down.plugins.LifecycleEvent;
import com.gluonhq.charm.down.plugins.LifecycleService;
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;
import javafxports.android.FXActivity;
import com.gluonhq.charm.down.plugins.AdViewService;

public class AndroidAdViewService implements AdViewService {

    private AdView adView;

    @Override
    public void setAdUnit(String unitId, String testDeviceId, boolean 
test) {
    FXActivity.getInstance().runOnUiThread(() -> {
        LinearLayout layout = new 
LinearLayout(FXActivity.getInstance());
        layout.setVerticalGravity(Gravity.BOTTOM);
        layout.setOrientation(LinearLayout.VERTICAL);

        adView = new AdView(FXActivity.getInstance());
        adView.setAdSize(AdSize.SMART_BANNER);
        adView.setAdUnitId(unitId);

        AdRequest adRequest;
        if (test) {
            adRequest = new AdRequest.Builder()
                .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)        // 
All emulators
                .addTestDevice(testDeviceId)        // from logcat!
                .build();
        } else {
            adRequest = new AdRequest.Builder().build();
        }

        adView.loadAd(adRequest);
        adView.setAdListener(new AdListener() {
            @Override
            public void onAdLoaded() {
                super.onAdLoaded();
            }
        });

        layout.addView(adView);

        FXActivity.getViewGroup().addView(layout);
    });

    Services.get(LifecycleService.class).ifPresent(service -> {
        service.addListener(LifecycleEvent.RESUME, () -> 
FXActivity.getInstance().runOnUiThread(() -> adView.resume()));
        service.addListener(LifecycleEvent.PAUSE, () -> 
FXActivity.getInstance().runOnUiThread(() -> adView.pause()));
    });
    }

}

The code is exactly the same of the link, it's just a project only for ADMob integration.

This is the project structure:

enter image description here

FFdeveloper
  • 241
  • 3
  • 14
  • Post some of the code you have tried, the build.gradle file, and a screenshot of the file structure of your project, otherwise it is impossible to say. – José Pereda Jun 14 '17 at 12:04
  • I edited the question. Please let me know if you need something else. As i said, is just the code of the link in the question, no other code. – FFdeveloper Jun 15 '17 at 07:50
  • The question is where do you add the Android class `AndroidAdViewService`, what package. That's why I asked for a screenshot of the file structure. – José Pereda Jun 15 '17 at 07:51
  • I added it. Sorry – FFdeveloper Jun 15 '17 at 07:55
  • Using Eclipse, the dependencies for the Android package are not resolved automatically. Try adding android.jar and jfxdvk.jar to the Eclipse build path manually. And the play-services-ads.jar as well. – José Pereda Jun 15 '17 at 08:08
  • I added those jars. Now i've got this situation: No errors on classes (from the project structure view) but i've got red exclamation point on the project. When i try to run it i've got no error but neither i can't see anything happen. When i open android class i still have this error: The import com.google.android.gms.ads cannot be resolved But on project structure view i can't see any error. Can you help me to solve this problem? I think i have some problem with play-services-ads.jar, because i added this jar to the build path: google-play-services-ads.jar – FFdeveloper Jun 16 '17 at 08:13
  • UPDATE: from the console i can run the project but i can't see the banner at the bottom. I used an IDUnit test from google ADMob: https://developers.google.com/admob/android/test-ads and i setted the boolean in the ads.setAdUnit method to false (it seems to work in this way, am i wrong?). – FFdeveloper Jun 16 '17 at 08:34
  • You mean you can run the project on an Android device? Use `adb logcat` to find out if the app is enabling the service or any other messages from ADMob. – José Pereda Jun 16 '17 at 08:52
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/146842/discussion-between-ffdeveloper-and-jose-pereda). – FFdeveloper Jun 16 '17 at 08:55

0 Answers0