Google's Admob library integration import cannot be resolved in javafx

给你一囗甜甜゛ 提交于 2019-12-25 18:36:08

问题


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:

来源:https://stackoverflow.com/questions/44542177/googles-admob-library-integration-import-cannot-be-resolved-in-javafx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!