我在胶合项目中遇到了有关Google AdMob集成的一些问题。我正在通过以下链接回答:
Gluon mobile cross-platform adsView
在第3步,我有关于进口的问题:
我已经检查过关于其他主题的这类问题的其他答案,但没有人解决我的问题。
有人可以帮我解决问题吗?
提前致谢
修改
这是Jose的评论所要求的代码。这是我的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)
}
这是我发现错误的类:
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()));
});
}
}
代码与链接完全相同,它只是一个仅用于ADMob集成的项目。
这是项目结构: