社区首页 >问答首页 >用于颤动的firebase_admob 0.6.1的应用程序ID问题

用于颤动的firebase_admob 0.6.1的应用程序ID问题
EN

Stack Overflow用户
提问于 2018-09-12 19:47:51
回答 1查看 2.8K关注 0票数 3

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

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

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

初始化失败,出现异常:必须在初始化之前调用java.lang.IllegalStateException: getGoogleAppId。示例:getGoogleAppId源:0)

我也得到了这个错误

GoogleService无法初始化,状态: 10,缺少名为google_app_id的字符串资源中的谷歌应用程序ID值。

缺少google_app_id。Firebase Analytics已禁用。你看..。

代码如下:

代码语言:javascript
代码运行次数:0
复制
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());
}
EN

回答 1

Stack Overflow用户

发布于 2018-10-31 06:28:38

最新的插件有问题

我可以通过更改:firebase_admob: ^0.5.5来打开应用程序

和:

代码语言:javascript
代码运行次数:0
复制
dependencies {
    api 'com.google.firebase:firebase-ads:15.0.1'
}

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

代码语言:javascript
代码运行次数:0
复制
 </activity>
        <meta-data
            android:name="com.google.android.gms.ads.APP_ID_HERE"
            android:value="ca-app-pub-XXXXXXXXXXXXXXXX"/>
    </application>

也是

代码语言:javascript
代码运行次数:0
复制
FirebaseAdMob.instance.initialize(appId: "appid");

GitHub Issue

希望能有所帮助

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52302408

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档