在 Android N 以上版本中為 Google Mobile Ads SDK 設定 Charles 代理程式
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
在 Android N 以上版本中,只有執行下列步驟時,Charles Proxy 才會顯示廣告呼叫:
- 更新行動裝置上的 Google Play 服務。
- 在行動裝置上啟用網路追蹤。
- 在裝置上安裝 Charles SSL 憑證,並設定 Proxy。
- 為行動應用程式啟用 SSL Proxy。
更新行動裝置上的 Google Play 服務
如果是模擬器,側邊選單中沒有顯示 Google Play 專區,可能需要更新 Android Studio,並在虛擬裝置設定中下載最新系統映像檔。請務必在目標中使用含有 Google Play 的系統映像檔。

使用側邊選單檢查 Google Play 服務,並更新至最新版本。Google Play 服務的最低運作版本為 14.5.74
。

如果是實體行動裝置 (手機或平板電腦),你可以搜尋 Google Play,或點選這個連結直接開啟 Google Play。
在行動裝置上啟用網路追蹤
如要啟用網路追蹤,請先啟用裝置的開發人員選項。啟動 Google 設定應用程式,然後依序選取「Google」>「廣告」>「啟用廣告的偵錯記錄」。AdMob 和 Google Ad Manager 發布商都可參閱更詳細的指南。

在裝置上安裝 Charles SSL 憑證,並設定 Proxy
如要將 Charles 設為行動應用程式的 Proxy,請先在電腦上安裝 Charles。按照 Charles 的說明,在 Android 模擬器或行動裝置上安裝 SSL 憑證。

透過 Proxy 使用模擬器較為簡單,因為模擬器已連上與執行 Charles 的電腦相同的 Wi-Fi 網路。搭配 Proxy 使用模擬器時,請將 Proxy 設為 localhost (http://127.0.0.1
) 和 Charles Proxy 執行的通訊埠 (位於 Charles 選單選項「Proxy」>「Proxy 設定」)。
如果使用實體行動裝置 (手機或平板電腦),請使用進階網路設定,將行動裝置連上與執行 Charles 的電腦相同的 Wi-Fi 網路。設定實體裝置的 Proxy 設定時,請使用 Charles 選單選項「Help」>「Local IP address」取得電腦的 IP 位址,然後在裝置上輸入 Proxy 位址 (您必須連上相同 Wi-Fi 網路,這項操作才能生效)。使用 Charles Proxy 執行的通訊埠。
為行動應用程式啟用 SSL Proxy
如要讓 Charles 攔截行動應用程式的 SSL 流量,您必須聲明應用程式可以信任使用者提供的 SSL 憑證。
首先,您需要在以下位置新增網路安全性設定的 XML 資源檔案:
<network-security-config>
<debug-overrides>
<trust-anchors>
<!-- Trust user added CAs while debuggable only -->
<certificates src="user" />
</trust-anchors>
</debug-overrides>
</network-security-config>

接著,更新 AndroidManifest.xml
檔案,使用網路安全性設定。
<?xml version="1.0" encoding="utf-8"?>
<manifest ... >
<application ...
android:networkSecurityConfig="@xml/network_security_config"
... >
...
</application>
</manifest>

完成後,您可以啟動行動應用程式,並在 Charles 記錄中尋找廣告請求。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-31 (世界標準時間)。
[null,null,["上次更新時間:2025-08-31 (世界標準時間)。"],[[["\u003cp\u003eOn Android N or higher, specific steps are required to view ad calls in Charles proxy, including updating Google Play services, enabling network tracing, installing the Charles SSL certificate, and configuring SSL proxy settings for your app.\u003c/p\u003e\n"],["\u003cp\u003eFor successful network tracing, ensure your Google Play services version is at least 14.5.74 and enable debug logging for ads within the Google Settings app.\u003c/p\u003e\n"],["\u003cp\u003eInstalling the Charles SSL certificate requires downloading Charles on your computer and following the instructions provided to install the certificate on your emulator or mobile device.\u003c/p\u003e\n"],["\u003cp\u003eWhen using Charles proxy, ensure your mobile device and computer are on the same Wi-Fi network and correctly configure proxy settings using either localhost for emulators or your computer's local IP address for physical devices.\u003c/p\u003e\n"],["\u003cp\u003eTo enable Charles to intercept SSL traffic from your mobile app, you need to declare trust for user-provided SSL certificates by adding a network security configuration XML file and updating your app's AndroidManifest.xml file.\u003c/p\u003e\n"]]],[],null,["On Android N or higher, ad calls are visible in Charles proxy only when the\nfollowing steps are performed:\n\n1. Update the Google Play services on the mobile device.\n2. Enable Network Tracing on the mobile device.\n3. Install Charles SSL certificate on your device, and set up proxy.\n4. Enable SSL Proxy for your mobile app.\n\nUpdate the Google Play services on the mobile device\n\nFor an emulator, if you don't see the Google Play section in the side menu,\nyou may need to update the Android Studio and download the latest system\nimages in the **Virtual Device Configuration**. Make sure to use a system\nimage with Google Play in its target.\n\nUse the side menu to check and update Google Play services to the latest\nversion. The minimum working version of the Google Play services is\n`14.5.74`.\n\nFor a physical mobile device (phone or tablet), you can search for Google\nPlay or follow this\n[link](//play.google.com/store/apps/details?id=com.google.android.gms)\nto open Google Play directly.\n\nEnable Network Tracing on the mobile device\n\nTo enable network tracing, you will need to [enable developer\noptions](//developer.android.com/studio/debug/dev-options) for your\ndevice. Launch the Google Settings app and select **Google \\\u003e Ads \\\u003e Enable\ndebug logging for ads** . A more detailed\n[guide](/admob/android/network-tracing) is\navailable for both AdMob and Google Ad Manager publishers.\n\nInstall Charles SSL certificate on your device, and set up proxy\n\nTo use Charles as a proxy for your mobile app, you will need to download and\n[install](//www.charlesproxy.com/documentation/installation/) Charles\non a computer. Follow Charles' instructions to install an SSL certificate on\nthe Android emulator or mobile device.\n\nIt is simpler to [use the emulator with a\nproxy](//developer.android.com/studio/run/emulator-networking#proxy) because the\nemulator is already connected to the same Wi-Fi network with the computer\nrunning Charles. When using the emulator with a proxy, set the proxy to\nlocalhost (`http://127.0.0.1`) and the port that Charles proxy is running on\n(found in Charles menu option **Proxy \\\u003e Proxy Settings**).\n\nIf you're using a physical mobile device (phone or tablet), you'll need to\nconnect the mobile device to the same Wi-Fi network with your computer\nrunning Charles using the [advanced network\nsettings](//support.google.com/pixelphone/answer/2819519). When setting up the\nproxy settings for your physical device, use the Charles menu option **Help \\\u003e\nLocal IP address** to get the IP address of your computer, to enter for the proxy\naddress on your device (you must be on the same Wi-Fi network for this to work).\nUse the port that Charles proxy is running on.\n\nEnable SSL Proxy for your mobile app\n\nFor Charles to intercept your mobile app's SSL traffic, you will need to declare\nthat your app can trust a user-provided SSL certificate.\n\nFirst, you will need to add a new XML resource file for [Network Security\nConfiguration](//developer.android.com/training/articles/security-config) under \n\n \u003cnetwork-security-config\u003e\n \u003cdebug-overrides\u003e\n \u003ctrust-anchors\u003e\n \u003c!-- Trust user added CAs while debuggable only --\u003e\n \u003ccertificates src=\"user\" /\u003e\n \u003c/trust-anchors\u003e\n \u003c/debug-overrides\u003e\n \u003c/network-security-config\u003e\n\nNext, update the `AndroidManifest.xml` file to use the network security\nconfiguration. \n\n \u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n \u003cmanifest ... \u003e\n \u003capplication ...\n android:networkSecurityConfig=\"@xml/network_security_config\"\n ... \u003e\n ...\n \u003c/application\u003e\n \u003c/manifest\u003e\n\nAfter that, you can launch the mobile app and look for ad requests in the\nCharles log."]]