flutter 应用程序中的 Admob:“连接到广告服务器时出错:SSL 握手中止”

发布于 2025-01-11 00:47:47 字数 6730 浏览 0 评论 0原文

尝试加载奖励插页式广告时,我在 Admob flutter 中遇到 SSL 握手错误(在真实硬件上测试单元广告 ID):

连接到广告服务器时出错:SSL 握手中止:ssl=0x72ea901888:系统调用期间出现 I/O 错误,连接重置

我确实明白这意味着什么,但我相信它在后端足够可靠,我想知道我是否做了什么错误的。

main.dart:

...
await MobileAds.instance.initialize();
...

page.dart:

RewardedInterstitialAd? _rewardedInterstitialAd;
int _numRewardedInterstitialLoadAttempts = 0;
int maxFailedLoadAttempts = 3;
VoidCallback? _adsCallback;
...
const ADMOB_TEST_REWARDED_INTERSTITIAL_AD_UNIT_ID = "ca-app-pub-3940256099942544/5354046379";
...
String getAdmobRewardedInterstitialUnitId() {
  return kDebugMode
      ? ADMOB_TEST_REWARDED_INTERSTITIAL_AD_UNIT_ID
      : ADMOB_REWARDED_INTERSTITIAL_AD_UNIT_ID;
}
...
AdRequest createAdRequest() => AdRequest(
  keywords: <String>[
    'keyword1',
    ...
  ],
  contentUrl: 'http://myappdomain.app',
  nonPersonalizedAds: true,
);
...
void createRewardedInterstitialAd(VoidCallback adsCallback) {
  _adsCallback = adsCallback;

  FirebaseCrashlytics.instance.log('RewardedInterstitialAd.load()');
  RewardedInterstitialAd.load(
      adUnitId: getAdmobRewardedInterstitialUnitId(),
      request: createAdRequest(),
      rewardedInterstitialAdLoadCallback: RewardedInterstitialAdLoadCallback(
        onAdLoaded: (RewardedInterstitialAd ad) {
          print('$ad loaded.');
          FirebaseCrashlytics.instance.log('RewardedInterstitialAd: onLoaded()');

          _rewardedInterstitialAd = ad;
          _numRewardedInterstitialLoadAttempts = 0;
        },
        onAdFailedToLoad: (LoadAdError error) {
          print('RewardedInterstitialAd failed to load: $error');
          FirebaseCrashlytics.instance.log('RewardedInterstitialAd: onAdFailedToLoad');
          FirebaseCrashlytics.instance.recordError(error, StackTrace.empty);

          _rewardedInterstitialAd = null;
          _numRewardedInterstitialLoadAttempts += 1;
          if (_numRewardedInterstitialLoadAttempts < maxFailedLoadAttempts) {
            createRewardedInterstitialAd(adsCallback);
          }
        },
      ));
}

AndroidManifest.xml:

...
       <!-- test -->
       <meta-data
           android:name="com.google.android.gms.ads.APPLICATION_ID"
           android:value="ca-app-pub-3940256099942544~3347511713"/>
    </application> 

这是我得到的:

2022-03-02 11:35:32.974 I/flutter:RewardedInterstitialAd 加载失败:LoadAdError(代码:0,域:com.google.android.gms.ads,消息:连接到广告服务器时出错:SSL握手中止:ssl=0x72ea901888:系统调用期间出现 I/O 错误,连接被对等方重置,响应信息: ResponseInfo(responseId:null,mediationAdapterClassName:,adapterResponses:[]))

设备上的日期/时间正常。 可能是什么原因?

附言。 google_mobile_ads:^1.1.0

PPS。我可以看到奖励插页式广告在 1.1.0 中处于测试阶段,这可能是一个错误。

购买力平价。我已在我的 Google 帐户中启用了广告跟踪,并在日志中获取了以下内容:

2022-03-03 11:10:21.597 V/NativeCrypto: SSL handshake aborted: ssl=0x72d8ecf348: I/O error during system call, Connection reset by peer
2022-03-03 11:10:21.600 E/GoogleConversionReporter: Error sending ping
    javax.net.ssl.SSLHandshakeException: SSL handshake aborted: ssl=0x72d8ecf348: I/O error during system call, Connection reset by peer
        at com.google.android.gms.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
        at com.google.android.gms.org.conscrypt.NativeSsl.doHandshake(:com.google.android.gms@[email protected] (100400-428111784):6)
        at com.google.android.gms.org.conscrypt.ConscryptFileDescriptorSocket.startHandshake(:com.google.android.gms@[email protected] (100400-428111784):16)
        at com.android.okhttp.internal.io.RealConnection.connectTls(RealConnection.java:196)
        at com.android.okhttp.internal.io.RealConnection.connectSocket(RealConnection.java:153)
        at com.android.okhttp.internal.io.RealConnection.connect(RealConnection.java:116)
        at com.android.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:186)
        at com.android.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:128)
        at com.android.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:97)
        at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:289)
        at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:232)
        at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:465)
        at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:411)
        at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:542)
        at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:106)
        at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:30)
        at drb.run(PG:14)

请注意,我有从 AndroidManifest.xml 引用的网络配置文件:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true">
        <trust-anchors>
            <certificates src="system" />
        </trust-anchors>
    </base-config>
</network-security-config>

这是请求:

2022-03-03 11:18:28.804 I/Ads: GMA Debug BEGIN
2022-03-03 11:18:28.804 I/Ads: GMA Debug CONTENT {"timestamp":1646288308803,"event":"onNetworkRequest","components":["network_request_0864d36d-6153-46ad-94aa-d4c40db7d2fe"],"params":{"firstline":{"uri":"https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/production/sdk-core-v40-impl.html","verb":"GET"},"headers":[{"name":"User-Agent","value":"Mozilla/5.0 (Linux; Android 10; Mi 9T Build/QKQ1.190825.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/98.0.4758.101 Mobile Safari/537.36 (Mobile; afma-sdk-a-v214106999.212910000.1)"},{"name":"Accept","value":"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"},{"name":"Upgrade-Insecure-Requests","value":"1"}]}}
2022-03-03 11:18:28.804 I/Ads: GMA Debug FINISH

我已检查“https://googleads.g.doubleclick” .net/mads/static/mad/sdk/native/sdk-core-v40-loader.html”,由于 SSL 问题,我也无法从桌面连接到它。

I'm getting SSL handshake error in Admob flutter when trying to load Rewarded interstitial ads (test unit ad id on a real hardware):

Error while connecting to ad server: SSL handshake aborted: ssl=0x72ea901888: I/O error during system call, Connection reset

I do understand what it means, but i believe it's reliable enough on back-end side and i wonder if i did anything wrong.

main.dart:

...
await MobileAds.instance.initialize();
...

page.dart:

RewardedInterstitialAd? _rewardedInterstitialAd;
int _numRewardedInterstitialLoadAttempts = 0;
int maxFailedLoadAttempts = 3;
VoidCallback? _adsCallback;
...
const ADMOB_TEST_REWARDED_INTERSTITIAL_AD_UNIT_ID = "ca-app-pub-3940256099942544/5354046379";
...
String getAdmobRewardedInterstitialUnitId() {
  return kDebugMode
      ? ADMOB_TEST_REWARDED_INTERSTITIAL_AD_UNIT_ID
      : ADMOB_REWARDED_INTERSTITIAL_AD_UNIT_ID;
}
...
AdRequest createAdRequest() => AdRequest(
  keywords: <String>[
    'keyword1',
    ...
  ],
  contentUrl: 'http://myappdomain.app',
  nonPersonalizedAds: true,
);
...
void createRewardedInterstitialAd(VoidCallback adsCallback) {
  _adsCallback = adsCallback;

  FirebaseCrashlytics.instance.log('RewardedInterstitialAd.load()');
  RewardedInterstitialAd.load(
      adUnitId: getAdmobRewardedInterstitialUnitId(),
      request: createAdRequest(),
      rewardedInterstitialAdLoadCallback: RewardedInterstitialAdLoadCallback(
        onAdLoaded: (RewardedInterstitialAd ad) {
          print('$ad loaded.');
          FirebaseCrashlytics.instance.log('RewardedInterstitialAd: onLoaded()');

          _rewardedInterstitialAd = ad;
          _numRewardedInterstitialLoadAttempts = 0;
        },
        onAdFailedToLoad: (LoadAdError error) {
          print('RewardedInterstitialAd failed to load: $error');
          FirebaseCrashlytics.instance.log('RewardedInterstitialAd: onAdFailedToLoad');
          FirebaseCrashlytics.instance.recordError(error, StackTrace.empty);

          _rewardedInterstitialAd = null;
          _numRewardedInterstitialLoadAttempts += 1;
          if (_numRewardedInterstitialLoadAttempts < maxFailedLoadAttempts) {
            createRewardedInterstitialAd(adsCallback);
          }
        },
      ));
}

AndroidManifest.xml:

...
       <!-- test -->
       <meta-data
           android:name="com.google.android.gms.ads.APPLICATION_ID"
           android:value="ca-app-pub-3940256099942544~3347511713"/>
    </application> 

Here is what i get:

2022-03-02 11:35:32.974 I/flutter: RewardedInterstitialAd failed to load: LoadAdError(code: 0, domain: com.google.android.gms.ads, message: Error while connecting to ad server: SSL handshake aborted: ssl=0x72ea901888: I/O error during system call, Connection reset by peer, responseInfo: ResponseInfo(responseId: null, mediationAdapterClassName: , adapterResponses: []))

The date/time on the device is ok.
What could be the reason?

PS. google_mobile_ads: ^1.1.0

PPS. I can see that Rewarded Interstitial is in beta in 1.1.0, probably that's a bug.

PPPS. I've enabled ads tracing in my Google account and got this in the log:

2022-03-03 11:10:21.597 V/NativeCrypto: SSL handshake aborted: ssl=0x72d8ecf348: I/O error during system call, Connection reset by peer
2022-03-03 11:10:21.600 E/GoogleConversionReporter: Error sending ping
    javax.net.ssl.SSLHandshakeException: SSL handshake aborted: ssl=0x72d8ecf348: I/O error during system call, Connection reset by peer
        at com.google.android.gms.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
        at com.google.android.gms.org.conscrypt.NativeSsl.doHandshake(:com.google.android.gms@[email protected] (100400-428111784):6)
        at com.google.android.gms.org.conscrypt.ConscryptFileDescriptorSocket.startHandshake(:com.google.android.gms@[email protected] (100400-428111784):16)
        at com.android.okhttp.internal.io.RealConnection.connectTls(RealConnection.java:196)
        at com.android.okhttp.internal.io.RealConnection.connectSocket(RealConnection.java:153)
        at com.android.okhttp.internal.io.RealConnection.connect(RealConnection.java:116)
        at com.android.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:186)
        at com.android.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:128)
        at com.android.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:97)
        at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:289)
        at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:232)
        at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:465)
        at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:411)
        at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:542)
        at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:106)
        at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:30)
        at drb.run(PG:14)

Note i'm having network config file referenced from AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true">
        <trust-anchors>
            <certificates src="system" />
        </trust-anchors>
    </base-config>
</network-security-config>

Here was the request:

2022-03-03 11:18:28.804 I/Ads: GMA Debug BEGIN
2022-03-03 11:18:28.804 I/Ads: GMA Debug CONTENT {"timestamp":1646288308803,"event":"onNetworkRequest","components":["network_request_0864d36d-6153-46ad-94aa-d4c40db7d2fe"],"params":{"firstline":{"uri":"https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/production/sdk-core-v40-impl.html","verb":"GET"},"headers":[{"name":"User-Agent","value":"Mozilla/5.0 (Linux; Android 10; Mi 9T Build/QKQ1.190825.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/98.0.4758.101 Mobile Safari/537.36 (Mobile; afma-sdk-a-v214106999.212910000.1)"},{"name":"Accept","value":"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"},{"name":"Upgrade-Insecure-Requests","value":"1"}]}}
2022-03-03 11:18:28.804 I/Ads: GMA Debug FINISH

I've checked "https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.html" and i can't also connect to it from my desktop due to SSL issue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

虐人心 2025-01-18 00:47:47

即使在示例应用中,该功能也不起作用出现同样的错误,创建了票据

It does not work even in example app with the same error, a ticket created.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文