You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于Google API的TTS与GPS地图应用模拟器正常但真机运行异常求助

问题排查解决方案
  • API密钥签名不匹配:这是该场景最高发的问题。你在Google Cloud平台申请的Maps SDK for Android密钥,默认仅配置了debug调试签名的SHA-1校验值,release打包APK使用的是正式签名文件,对应的SHA-1值不在密钥的允许列表中,就会出现地图加载失败的情况。操作步骤:获取正式签名文件的SHA-1值,到Google Cloud控制台的密钥配置页,将正式签名SHA-1和你的应用包名com.codingflow.texttospeechexample添加到允许列表即可。
  • 运行时权限未适配:Android 6.0及以上系统,定位权限属于敏感权限,仅在AndroidManifest.xml中声明无法获取权限,需要在应用运行时主动触发权限申请弹窗,用户授权后才能调用定位接口。模拟器通常默认授予应用全部权限,而真机默认是拒绝状态,未做权限适配就会出现定位失败、地图标记异常的问题。
  • GMS服务缺失问题:谷歌地图API依赖Google Play服务核心框架,部分国产安卓设备默认未预装GMS服务,安装应用后会无法初始化地图组件。可以在应用启动时增加GMS服务可用性检测逻辑,检测不通过时给用户明确提示。
  • 清单配置错误修正:
    1. 删除AndroidManifest.xml中无用的enter code here无效行,避免打包时出现未知异常
    2. 你配置的自定义MAPS_RECEIVE权限所属包名和应用实际包名不匹配,且新版Google Maps SDK已经不需要自定义该权限,可以直接删除自定义权限声明和对应uses-permission两行配置
  • 混淆规则缺失:检查release打包的混淆配置,是否添加了Google Maps、GMS相关组件的混淆白名单,未配置的话混淆过程会删除SDK核心类,导致功能崩溃。可以直接添加官方给出的混淆规则到proguard-rules.pro文件中。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.codingflow.texttospeechexample"
    >

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.TextToSpeech">


        <uses-library android:name="com.google.android.maps" />
        <uses-library
            android:name="org.apache.http.legacy"
            android:required="false" />

        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="my api key" />
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

        </activity>
    </application>
    <queries>
        <intent>
            <action android:name="android.intent.action.TTS_SERVICE" />
        </intent>
    </queries>
</manifest>

内容的提问来源于stack exchange,提问作者grr

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.29 00:27:02