横幅广告不显示Flutter



我想让横幅广告出现在我的主屏幕,但它不会显示。我使用的是firebase_admob 0.11.0+1包。我创建了firebase和google admob帐户,将它们链接在一起,并获得了appId和banner ID,并添加了代码,但它不起作用。

我还在manifest文件中添加了appID,如包

中所示
const String testDevice = 'YOUR_DEVICE_ID';
const testAppId = "ca-app-pub-6340236221743124~6413606161";
const testAdUnitId = "ca-app-pub-6340236221743124~6413606161";
void main() {
WidgetsFlutterBinding.ensureInitialized();
runApp(MyApp());
}
class MyApp extends StatelessWidget {

@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.light(),
title: "Start of the app",
debugShowCheckedModeBanner: false,
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
static const MobileAdTargetingInfo targetingInfo = MobileAdTargetingInfo(
testDevices: testDevice != null ? <String>[testDevice] : null,
keywords: <String>['foo', 'bar'],
contentUrl: 'http://example.com',
childDirected: true,
nonPersonalizedAds: true,
);
BannerAd _bannerAd;
BannerAd createBannerAd() {
return BannerAd(
adUnitId: BannerAd.testAdUnitId,
size: AdSize.banner,
targetingInfo: targetingInfo,
listener: (MobileAdEvent event) {
print("BannerAd event $event");
},
);
}
@override
void initState() {
super.initState();
FirebaseAdMob.instance.initialize(appId: FirebaseAdMob.testAppId);
_bannerAd = createBannerAd()..load();
}
@override
void dispose() {
_bannerAd?.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('AdMob Plugin example app'),
),
body: SingleChildScrollView(
child: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
RaisedButton(
child: const Text('SHOW BANNER WITH OFFSET'),
onPressed: () {
_bannerAd ??= createBannerAd();
_bannerAd
..load()
..show(horizontalCenterOffset: -50, anchorOffset: 100);
}),]),),),),);}}

编辑:错误日志

FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:processDebugResources'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> Android resource linking failed
C:Userslaksh.gradlecachestransforms-2files-2.15324cf3d856f90a58788658b9d99824dplay-services-ads-lite-19.6.0AndroidManifest.xml:27:5-38:15: AAPT: error: unexpected element <queries> found in <manifest>.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 41s
The built failed likely due to AndroidX incompatibilities in a plugin. The tool is about to try using Jetfier to solve the incompatibility.
Building plugin firebase_admob...
Running Gradle task 'assembleAarRelease'...
Exception: The plugin firebase_admob could not be built due to the issue above.

应用程序/src/构建。gradle低于

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new FileNotFoundException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 29
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.new_test"
minSdkVersion 16
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
apply plugin: 'com.google.gms.google-services'

android/build.gradle

buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.google.gms:google-services:4.3.4'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}

嗯,在我看来,你的代码没有问题。构建错误显示您的构建有问题。gradle and AndroidX.

你能回复我你的构建吗?Gradle或添加到您的原始帖子?

B.T.W.-请看看这个github问题-https://github.com/FirebaseExtended/flutterfire/issues/2511

被罩。

最新更新