Android exceptions claim missing API key in device install, but works on emulator #appcelerator - api

My app builds and installs in android emulator, but errors out during install/launch on my Sammy S5. The error seems to be related to the google maps API key which is in my tiapp.xml. The section in question is:
<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>
As you can see, the API key is clear and obvious and works in the emulator, but the packaged and signed apk installs and flames out with "Ti Application" errors and "Androd Runtime" errors in my Appcelerator console
[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

It appears your device/target is requiring a new key name. Try changing your key from com.google.android.maps.v2.API_KEY to com.google.android.geo.v2.API_KEY. Google changed the key from maps to geo to support multiple APIs.
From the docs:
For backwards compatibility, the API also supports the name com.google.android.maps.v2.API_KEY. This legacy name allows authentication to the Android Maps API v2 only. An application can specify only one of the API key metadata names. If both are specified, the API throws an exception.

Does the error looks like this
[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
If so, Try to keep one application tag in the Android manafest in ti.app xml file. Like this
<application android:theme="#style/Theme.AppCompat.Light">
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyBNHcyplkOpzO_...remainder redacted"/>
</application>
This is working on device. I test with keeping one application tag and the exception was gone.

Related

Android EMM AppConfig

I am trying to setup AppConfig variables through our EMM server for an internal-only app.
I have reviewed the documentation "Set up managed configurations" here https://developer.android.com/work/managed-configurations and verified that my AndroidManifest.xml and app_restrictions.xml files are correctly populated.
AndroidManifesst.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
<application>
...
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/file_paths"></meta-data>
<meta-data
android:name="android.content.APP_RESTRICTIONS"
android:resource="#xml/app_restrictions"></meta-data>
</provider>
</application>
...
</manifest>
app_restrictions.xml:
<?xml version="1.0" encoding="utf-8"?>
<restrictions xmlns:android="http://schemas.android.com/apk/res/android">
<restriction
android:key="app_configurator"
android:title="#string/app_configurator"
android:restrictionType="bool"
android:defaultValue="false">
</restriction>
<restriction
android:key="z_number"
android:title="#string/z_number"
android:restrictionType="string"
android:defaultValue="Testing123">
</restriction>
</restrictions>
In testing, using the Test DPC app with Device Owner:
the button "LOAD APP MANIFEST RESTRICTIONS" does nothing (when I expect it should load the details defined in app_restrictions.xml)
if I manually add the keys and values my app responds as expected
When publishing, through Managed Google Play and setting up the app from our EMM solution:
the app configuration tab is not populated with any parameters and a message "This app doesn't support app configuration." is shown leaving no way to configure the app.
Given that the app does respond when the values are set, but the inability to set the values seems to indicate the Test DPC and the EMM solution cannot read the values of my app_restrictions.xml.
The documentation indicates that the above two files are all that is needed. However, I have seen some reference to Google Play services providing this information to MDMs so I'm not sure I understand the process here to investigate further.
Hoping someone could help me with some pointers.
In the AndroidManifest.xml file, the location of the 'meta-data' tag is incorrect. The issue is resolved after the following update:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
<application>
<meta-data
android:name="android.content.APP_RESTRICTIONS"
android:resource="#xml/app_restrictions"></meta-data>
...
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/file_paths"></meta-data>
</provider>
</application>
...
</manifest>

How to remove "android.hardware.location" permission request from ejected Expo project?

I have an React Native Expo project that started out using the Expo "managed workflow". However, since then I have ejected out of the managed workflow (while still using some expo modules).
The issue I'm experiencing is that Expo seems to have added arbitrary permission requests to my Android app.
I must remove this particular permission request from the app: android.hardware.location.
I've tried many ways to remove it in my AndroidManifest.xml file, for example:
<uses-permission tools:node="remove" android:name="LOCATION_HARDWARE" />
<uses-permission tools:node="remove" android:name="ACCESS_COARSE_LOCATION" />
<uses-permission tools:node="remove" android:name="ACCESS_FINE_LOCATION" />
<uses-feature android:name="android.hardware.location" android:required="false" tools:node="remove" />
But in the end the bundled Android app still requests the android.hardware.location permission.
How can I remove it before bundling the app?
for excluding any permission that expo is adding automatically, according to the expo documentation you should just add tools:node="remove" to your manifest permission element. now if you want to remove location permission this should solve your issue:
<manifest ... xmlns:tools="http://schemas.android.com/tools">
...
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" tools:node="remove" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" tools:node="remove" />
...
</manifest>
By adding these, hardware location permission should be gone too.
don't forget to add tools namespace to the root element of your manifest
This issue was resolved by removing the expo dependency from package.json.
The expo dependency required expo-location which in turn requested various android location permissions.

Play store console detects android.permission.READ_PHONE_STATE requirement for a Vanilla React Native app

I created a react native app using react-native init. Did not change a single line of code. (Note: react-native version is 0.55.4)
I generated a singed release APK by following steps given in the official docs.
I tried to upload this APK to Google Play console.
I got the following error:
Your APK or Android App Bundle is using permissions that require a privacy policy: (android.permission.READ_PHONE_STATE)
This is an unexpected behaviour right? Why will a vanilla app require this permission? How can I solve this issue?
Edit 1
My Android manifest is the default one created by react-native init.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.praveenavtestproject">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<application
android:name=".MainApplication"
android:label="#string/app_name"
android:icon="#mipmap/ic_launcher"
android:allowBackup="false"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
Edit 2
My app doesn't need any permission to work. It just displays 3 lines of text from a historical literature. It is just for information purpose. In Play Store Console, under Store listing tab, at the bottom, there is a Privacy Policy section. It says If you wish to provide a privacy policy URL for this application, please enter it below. Also, please check out our User Data policy to avoid common violations.
I am not providing a privacy policy URL. My app is not supposed to be accessing any user data or phone state. Does React Native access it by default? Can that be the reason for this issue?
Edit 3
Looks like this issue is already being looked at by React Native team.

Xamarin Android app crashes when using GCM

Im following the tutorial to add Google Cloud Messaging to your xamarin android project (Walkthrough - Using Remote Notifications in Xamarin.Android).
But im having trouble trying to connect to Google Services.
Everytime i try to build/ run my app, Visual Studio just trys to launch the app but then stops about a second later.
Heres the output message:
Android application is debugging. The application could not be
started. Ensure that the application has been installed to the target
device and has a launchable activity (MainLauncher = true).
Additionally, check Build->Configuration Manager to ensure this
project is set to Deploy for this configuration.
Here is my manifest file also:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="PushNotificationsAndroid.PushNotificationsAndroid"
android:versionCode="1"
android:versionName="1.0"
android:installLocation="auto">
<uses-sdk android:minSdkVersion="16" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />
<user-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="PushNotificationsAndroid.PushNotificationsAndroid.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="PushNotificationsAndroid.PushNotificationsAndroid.permission.C2D_MESSAGE" />
<application android:label="PushNotificationsAndroid"></application>
</manifest>
I commented out some of the permission lines and this issue seems just to happen when i added the line:
<permission android:name="PushNotificationsAndroid.PushNotificationsAndroid.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
Can anyone give me some advice to why this is happening?
Found a solution. I just had to make the package name lowercase for some reason
com.notifications.pushnotificationsandroid

Unable to install Android apk from AppCenter

I have an ant script that builds&deploy a MFP app for android (wlapp and apk). I also upload the app to AppCenter.
The problem is that I cannot install (on a device - Huawei P6) the apk from the AppCenter using the AppCenter app - it downloads the app but the installation is not successful. The uploaded app is not signed.
Running the Android app from the MFP Studio works fine.
What steps do I have to perform in order to make the installation from AppCenter app work? Where can I see the logs from AppCenter?
Thanks!
Ant target:
<target name="build-android-windows" if="isWindows" description="Build the Android .apk" depends="">
<!-- These must be set in your local.properties file in the root of the android project.
This is sensitive information and is not checked into the repository
<fail unless="android.store" message="Property android.store missing" />
<fail unless="android.alias" message="Property android.alias missing" />
<fail unless="android.store.password" message="Property android.store.password missing" />
<fail unless="android.alias.password" message="Property android.alias.password missing" />
-->
<!-- use android.release_target if defined, otherwise default to 'release' -->
<property name="android.release_target" value="release"/>
<!-- call the project's build.xml to clean -->
<ant antfile="${src.dir}/apps/${curBrand}/android/native/build.xml" inheritAll="false" useNativeBasedir="true" target="clean"/>
<!-- call the project's build.xml to make a build -->
<ant antfile="${src.dir}/apps/${curBrand}/android/native/build.xml" inheritAll="false" useNativeBasedir="true" target="${android.release_target}" />
<!-- copy the file to build.dir -->
<copy file="${src.dir}/apps/${curBrand}/android/native/bin/${curBrand}-${android.release_target}-unsigned.apk" tofile="${build.dir}/android/${build.apk}" overwrite="true" failonerror="true"/>
</target>
As Vivin suggested in the comments, the AppCenter is not Google Play meaning it is not a "trusted source" at least from the device's perspective, thus you may need indeed to enable that option in Android's options.
The second option is as I mentioned - to sign the .apk. When you build directly from Eclipse it uses debug signing by default and goes straight into the device.