gpt4 book ai didi

firebase - 用于 flutter 的 firebase_admob 0.6.1 的 App ID 问题

转载 作者:IT王子 更新时间:2023-10-29 06:33:54 25 4
gpt4 key购买 nike

我在 admob 中创建了一个新的 android 应用程序,我得到了 id,我尝试在 firebase_admob 页面上的示例中使用它。

我已经在默认的 flutter 项目中添加了最新版本,并将代码复制并粘贴到页面上。我只修改了id,我试过单引号,我试过双引号,都没有用,我在控制台中出现了同样的错误。

我做错了什么?我真的不明白,我花了一整天的时间试图弄清楚这一点。请帮助我。

getGoogleAppId 失败并出现异常:java.lang.IllegalStateException:必须在 getGoogleAppId 之前调用初始化。:com.google.android.gms.measurement.AppMeasurement.getGmpAppId(未知来源:0)

我也报错

GoogleService 初始化失败,状态:10,名称为 google_app_id 的字符串资源中缺少 google app id 值。

缺少 google_app_id。 Firebase 分析已禁用。看...

这是代码:

import 'package:flutter/material.dart';
import 'package:firebase_admob/firebase_admob.dart';

// You can also test with your own ad unit IDs by registering your device as a
// test device. Check the logs for your device's ID value.
const String testDevice = 'YOUR_DEVICE_ID';

class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {

static final MobileAdTargetingInfo targetingInfo = new MobileAdTargetingInfo(
testDevices: testDevice != null ? <String>[testDevice] : null,
keywords: <String>['foo', 'bar'],
contentUrl: 'http://foo.com/bar.html',
birthday: new DateTime.now(),
childDirected: true,
gender: MobileAdGender.male,
nonPersonalizedAds: true,
);

BannerAd _bannerAd;
InterstitialAd _interstitialAd;

int _coins = 0;

BannerAd createBannerAd() {
return new BannerAd(
adUnitId: BannerAd.testAdUnitId,
size: AdSize.banner,
targetingInfo: targetingInfo,
listener: (MobileAdEvent event) {
print("BannerAd event $event");
},
);
}

InterstitialAd createInterstitialAd() {
return new InterstitialAd(
adUnitId: InterstitialAd.testAdUnitId,
targetingInfo: targetingInfo,
listener: (MobileAdEvent event) {
print("InterstitialAd event $event");
},
);
}

@override
void initState() {
super.initState();
FirebaseAdMob.instance
.initialize(appId: 'ca-app-pub-0463943530925483~4865006927');
_bannerAd = createBannerAd()..load();
RewardedVideoAd.instance.listener =
(RewardedVideoAdEvent event, {String rewardType, int rewardAmount}) {
print("RewardedVideoAd event $event");
if (event == RewardedVideoAdEvent.rewarded) {
setState(() {
_coins += rewardAmount;
});
}
};
}

@override
void dispose() {
_bannerAd?.dispose();
_interstitialAd?.dispose();
super.dispose();
}


@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new Scaffold(
appBar: new AppBar(
title: const Text('AdMob Plugin example app'),
),
body: new SingleChildScrollView(
child: new Center(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
new RaisedButton(
child: const Text('SHOW BANNER'),
onPressed: () {
_bannerAd ??= createBannerAd();
_bannerAd
..load()
..show();
}),
new RaisedButton(
child: const Text('REMOVE BANNER'),
onPressed: () {
_bannerAd?.dispose();
_bannerAd = null;
}),
new RaisedButton(
child: const Text('LOAD INTERSTITIAL'),
onPressed: () {
_interstitialAd?.dispose();
_interstitialAd = createInterstitialAd()..load();
},
),
new RaisedButton(
child: const Text('SHOW INTERSTITIAL'),
onPressed: () {
_interstitialAd?.show();
},
),
new RaisedButton(
child: const Text('LOAD REWARDED VIDEO'),
onPressed: () {
RewardedVideoAd.instance.load(
adUnitId: RewardedVideoAd.testAdUnitId,
targetingInfo: targetingInfo);
},
),
new RaisedButton(
child: const Text('SHOW REWARDED VIDEO'),
onPressed: () {
RewardedVideoAd.instance.show();
},
),
new Text("You have $_coins coins."),
].map((Widget button) {
return new Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0),
child: button,
);
}).toList(),
),
),
),
),
);
}
}

void main() {
runApp(new MyApp());
}

最佳答案

最新的插件有问题

我能够通过更改打开应用程序:firebase_admob: ^0.5.5

和:

dependencies {
api 'com.google.firebase:firebase-ads:15.0.1'
}

并使用我的 AdMob key 添加到 AndroidManifest.xml:

 </activity>
<meta-data
android:name="com.google.android.gms.ads.APP_ID_HERE"
android:value="ca-app-pub-XXXXXXXXXXXXXXXX"/>
</application>

还有

FirebaseAdMob.instance.initialize(appId: "appid");

GitHub Issue

希望对你有帮助

关于firebase - 用于 flutter 的 firebase_admob 0.6.1 的 App ID 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52302408/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com