我的应用程序在Android模拟器中构建和安装,但在我的Sammy S5上安装/启动时出错。该错误似乎与我的tiapp.xml中的google maps API密钥有关。有问题的部分是:
<android xmlns:android="http://schemas.android.com/apk/res/android">
<manifest>
<uses-sdk android:targetSdkVersion="23"/>
<!-- Allows the API to download data from Google Map servers -->
<uses-permission android:name="android.permission.INTERNET"/>
<!-- Allows the API to cache data -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!-- Use GPS for device location -->
<!-- Use Wi-Fi or mobile connection for device location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<!-- Allows the API to access Google web-based services -->
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<!-- Specify OpenGL ES 2.0 as a requirement -->
<uses-feature android:glEsVersion="0x00020000" android:required="true"/>
<uses-permission android:name="com.appcelerator.sample.mapping.permission.MAPS_RECEIVE"/>
<permission android:name="com.appcelerator.sample.mapping.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>
<application>
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyBNHcyplkOpzO_...remainder redacted"/>
</application>
<application android:theme="@style/Theme.AppCompat.Light"/>
</manifest>
</android>
正如您所看到的,API密钥清晰明了,可以在模拟器中运行,但打包和签名的apk安装并在我的Appcelerator控制台中出现“Ti Application”错误和“Androd Runtime”错误
[ERROR] : TiApplication: (main) [1193,2581] Sending event: exception on thread: main msg:java.lang.RuntimeException: API key not found. Check that <meta-data android:name="com.google.android.geo.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml; Titanium 5.1.2,2015/12/16 19:00,ca822b2
[ERROR] : TiApplication: java.lang.RuntimeException: API key not found. Check that <meta-data android:name="com.google.android.geo.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml
答案 0 :(得分:1)
您的设备/目标似乎需要新的密钥名称。尝试将密钥从com.google.android.maps.v2.API_KEY
更改为com.google.android.geo.v2.API_KEY
。 Google将密钥从maps
更改为geo
以支持多个API。
来自docs:
为了向后兼容,API还支持com.google.android.maps.v2.API_KEY这个名称。此旧版名称仅允许对Android Maps API v2进行身份验证。应用程序只能指定一个API密钥元数据名称。如果同时指定了两者,则API会抛出异常。
答案 1 :(得分:0)
错误是否如此
[ERROR] : TiApplication: (main) [735,735] Sending event: exception on thread: main msg:java.lang.RuntimeException: Unable to start activity ComponentInfo{com.gsl.TracKm/org.appcelerator.titanium.TiActivity}: java.lang.RuntimeException: API key not found. Check that <meta-data android:name="com.google.android.geo.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml; Titanium 5.1.1,2015/11/24 11:07,e46100b
[ERROR] : TiApplication: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.gsl.TracKm/org.appcelerator.titanium.TiActivity}: java.lang.RuntimeException: API key not found. Check that <meta-data android:name="com.google.android.geo.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml
如果是这样,请尝试在ti.app xml文件中的Android manafest中保留一个应用程序标记。喜欢这个
<application android:theme="@style/Theme.AppCompat.Light">
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyBNHcyplkOpzO_...remainder redacted"/>
</application>
这是在设备上工作。我测试时保留了一个应用程序标签,但异常消失了。