AR Cloud Anchor Hosting Error: ERROR_NOT_AUTHORIZED Android - android

I am getting this error on Android after setting up the cloud anchor quick start sample app https://developers.google.com/ar/develop/java/cloud-anchors/cloud-anchors-quickstart-android.
Here is the logcat when error occurs:
05-10 17:52:07.258 3214-3273/com.google.ar.core.examples.java.cloudanchor E/zygote64: The String#value field is not present on Android versions >= 6.0
05-10 17:52:07.528 3214-3273/com.google.ar.core.examples.java.cloudanchor E/AnchorServiceClient: AnchorServiceClient Exception
aua: PERMISSION_DENIED: The request is missing a valid API key.
at bhd.a(PG:58)
at bhd.a(PG:29)
at com.google.ar.persistence.AnchorServiceClient.a(PG:17)
at com.google.ar.persistence.AnchorServiceClient.createAnchors(PG:26)
I have:
Added app to Firebase project that contains realtime DB. Set up Rule for public.
Enabled Cloud Anchor
API, and added API key in Cloud credentials and then in manifest.
Here is a copy of the manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.google.ar.core.examples.java.cloudanchor">
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.INTERNET" />
<!-- This tag indicates that this application requires ARCore. This results in the application
only being visible in the Google Play Store on devices that support ARCore. -->
<uses-feature android:name="android.hardware.camera.ar" android:required="true"/>
<meta-data
android:name="com.google.android.ar.API_KEY"
android:value="**obsured**"/>
<application
android:allowBackup="false"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:usesCleartextTraffic="false"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".CloudAnchorActivity"
android:label="#string/app_name"
android:configChanges="orientation|screenSize"
android:exported="true"
android:theme="#style/Theme.AppCompat.NoActionBar"
android:screenOrientation="locked">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- This tag indicates that this application requires ARCore. This results in the Google Play
Store downloading and installing ARCore along with the application.
Application code must still call ArCoreApk.requestInstall() before beginning an ARCore
sessions, in case the user uninstalls ARCore for any reason. -->
<meta-data android:name="com.google.ar.core" android:value="required" />
</application>
</manifest>
Before even attempting to do the Android version, I set up the iOS quick start sample app and that works fine - I can be a host, add an object and then resolve and find the object.
The Android version is to communicate with the same Firebase DB that iOS app did and is to demonstrate cloud anchors across iOS and Android.
I have also tried setting up the Android sample app with a new Firebase project and get the same error on Android.
If there is anyone who has tried AR Cloud Anchor for Android, please let me know why the API key is being rejected by the Google Cloud Platform while the iOS version works just fine with the same backend set up.
Thank you,

I figured out the answer to my own question.
Looks like the:
<meta-data
android:name="com.google.android.ar.API_KEY"
android:value="**obsured**"/>
...
needs to be placed within the Application element in the manifest file like this:
<application
android:allowBackup="false"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:usesCleartextTraffic="false"
tools:ignore="GoogleAppIndexingWarning">
<meta-data
android:name="com.google.android.ar.API_KEY"
android:value="**obsured**"/>
<activity
android:name=".CloudAnchorActivity"
android:label="#string/app_name"
android:configChanges="orientation|screenSize"
android:exported="true"
android:theme="#style/Theme.AppCompat.NoActionBar"
android:screenOrientation="locked">
...

Related

Camera2 API compatibility issues with google play store

I have developed an android app that uses the camera2 API. I am able to run this app on my own physical device when I'm debugging, but when I try to publish the app to the google play store, it says that my device isn't compatible - in fact, no devices are compatible with my app.
I have been in contact with google support, and they said that "your app is not compatible with most devices due to a conflict in your app’s manifest because of the following missing device feature: android.hardware.camera2. "
I have noticed that the min-sdk version in my gradle file was set to 15.
So my question is: Will my app become compatible with my devices if I change the min-sdk version to 21, or do I need to rewrite my entire code to use the deprecated camera API instead?
Thanks in advance.
*Edit:
This is my android manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="...">
<uses-feature
android:name="android.hardware.camera2"
android:required="true"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:name=".app.AppController"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<meta-data
android:name="com.google.android.gms.vision.DEPENDENCIES"
android:value="barcode"/>
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar"
android:screenOrientation="portrait">
</activity>
<activity
android:name=".ResultsActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar"
android:screenOrientation="portrait">
</activity>
<activity
android:name=".QRScanner"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
There is no such feature as "android.hardware.camera2", so if you require it for your app to be installable on a device, you won't be installable anywhere, since no device anywhere reports that feature.
The camera2 API exists on all devices running Android 5.0 or later, it doesn't have a feature. Remove the feature line, and use the min-sdk line if you don't want to deal with devices too old to support camera2.

Cannot open Camera An error occurred while connecting to camera: 0

I started developping an app and I need to use the camera of my phone, and when I use the method Camera.open(), either with cameraId or not, it returns the error "An error occurred while connecting to camera: 0". My AndroidManifest.xml is:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.telecombretagne.holowater">
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.autofocus" />
<uses-feature android:name="android.hardware.flash" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".camera"
android:label="#string/title_activity_camera"
android:theme="#style/AppTheme.NoActionBar"></activity>
</application>
</manifest>
My phone's Android Version is 6.0.1, and it's a BQ Aquaris M5.
Thanks in advance.
Devices that are running Marshmallow requires permission to be set on runtime, here's my answer from another similar question here :)
From https://developer.android.com/training/permissions/requesting.html
Note: Beginning with Android 6.0 (API level 23), users can revoke permissions from any app at any time, even if the app targets a lower API level. You should test your app to verify that it behaves properly when it's missing a needed permission, regardless of what API level your app targets.
Aside from the permissions set in the manifest, you'll need to request/check for permission on runtime. There are sample codes in there you can use, or...
Quick solution,
go to Settings-> Apps->(Your app name)->Permissions and enable the camera permission.
Done, although not recommended for final product
then try your app again. Should be working now :D
try also adding the camera ID, like
Camera.open(Camera.CameraInfo.CAMERA_FACING_BACK);

Migrated to Android Studio - now my app requests additional permissions

I just migrated an app from Eclipse to Android Studio. I tried exporting a signed APK and uploaded it to Google Play just to check that everything was working.
That's when I noticed that my app now requests two additional permissions except the ones that I have declared in my manifest! The two permissions are android.permission.WAKE_LOCK and com.google.android.c2dm.permission.RECEIVE.
What's going on here? I haven't changed any code since the last time I uploaded the app, and the manifest doesn't declare these permissions. I'm guessing some Google component is responsible for this, but why did this happen because I migrated to Android Studio? Can I turn off these permissions?
I'm using Google Play Services and Google AdMob, but I've been doing that for a long time without these permissions...
manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.app"
android:versionCode="70"
android:versionName="7.0" >
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.android.vending.CHECK_LICENSE" />
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="23" />
<application android:name="com.example.app.MyApplication"
android:icon="#mipmap/ic_launcher_icon"
android:label="#string/app_name"
android:allowBackup="true"
android:uiOptions="none">
<meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
<activity android:name="com.example.app.MainActivity"
android:label="#string/app_name"
android:theme="#style/Theme.MyTheme.App"
android:windowSoftInputMode="adjustPan" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.app.OtherActivity"
android:label="#string/otherActivityTitle"
android:theme="#style/Theme.MyTheme.App"
android:parentActivityName="com.example.app.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.app.MainActivity" />
</activity>
<activity
android:name="com.example.app.PreferencesActivity"
android:label="#string/prefsTitle" >
</activity>
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="#android:style/Theme.Translucent" />
</application>
</manifest>
Here's a screenshot of the APK built using Android Studio:
I couldn't change the language to english, but it basically says it's now supporting 22 less devices, requires 2 new permissions and uses OpenGL 2.0+ instead of 1.0+.
Here's a screenshot of the same APK built using Eclipse:
After some more searching I found this thread on Stackoverflow: Android Studio adds unwanted permission after running application on real device.
One of the answers there (not the accepted one) solved my issues. It seems that the Android Studio import process added this dependency to my build.gradle:
compile 'com.google.android.gms:play-services:+'
After changing it to
compile 'com.google.android.gms:play-services-base:8.4.0' // Needed for API Availability test
compile 'com.google.android.gms:play-services-ads:8.4.0'
compile 'com.google.android.gms:play-services-analytics:8.4.0'
the APK no longer requests the unwanted permissions, it targets the same devices as before and uses the same OpenGL version as before - i.e. everything is back the way it was with Eclipse! Except now the file size of the APK is 1 MB smaller as an added bonus!
For people coming here in the future, you might want to investigate what Google Play Services version numbers you should use at Gradle, please and/or Setting up Google Play Services.
Change it to:
android:targetSdkVersion="22"

Android: Publishing an App in Google Play

I have developped an applicaction that basically download a file from a Server via Bluetooth and store it in the memory of the mobile phone.
I read what is needed to publish and application in http://developer.android.com/tools/publishing/publishing_overview.html
and I followed the steps:
Remove any "android:debuggable" in the Android Manifest.
Remove any Log calls
Sign the file: Right click on the project->Export -> Android ->
Export Android Application ... during the process I use an
AppKey.keystored that I created before.
I apply Zipalign
http://developer.android.com/tools/publishing/app-signing.html#signing-manually
Once I finish that I upload the App to the Google Play Store.
I downloaded it with three diferent devices, with the following version of Android:
4.2.2 (It is the one I used to develop, debbug and test the App while writting it on Eclipse)
4.3
4.4
But it only works properly in the device with 4.2.2. In the other two devices the Application crash when I launch it.
This is the Android manifest of the Application, all the code is too long to upload it here. But I feel there problem must be or in the manifest or in the way I'm exporting/signing the file.apk
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cliente_bluetooth"
android:versionCode="3"
android:versionName="1.3" >
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.cliente_bluetooth.Cliente_Bluetooth"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
This is the link of the App in the Play Store:
https://play.google.com/store/apps/details?id=com.cliente_bluetooth
Can anyone find a mistake in the process of publishing? am I skipping or missunderstanding any step?
Thank you very much for your time

How can I define local environment variables in android studio?

I and a few colleagues are building an app and using git for version control.
Our app utilized the Google Maps Api, which generates unique api keys based on SHA1 certificates. To utilize maps, the api key must be referenced in the manifest as such
....
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="api_key_goes_here"/>
</application>
We've each generated our own api keys based on builds of the app on our personal machines, but we'd like to have a properties file on each of our machines not checked into version control which stores our unique api key so we don't have to manually change the api key in the manifest each time we pull from the repository.
Is this possible? I know there are properties files in android studio but I haven't a clue how to use them, especially in this case.
EDIT:
Full manifest:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:name=".Application">
<activity android:name="com.misfiremedia.parseexperiment.app.DispatchActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.misfiremedia.parseexperiment.app.SignUpActivity">
</activity>
<activity
android:name="com.misfiremedia.parseexperiment.app.WelcomeActivity"
android:configChanges="orientation|keyboardHidden"/>
<activity
android:name=".EmailLogInActivity"
android:configChanges="orientation|keyboardHidden"/>
<activity
android:name="com.misfiremedia.parseexperiment.app.HomeActivity"
android:configChanges="orientation|keyboardHidden"/>
<activity
android:name="com.misfiremedia.parseexperiment.app.home.PostLocationActivity"
android:configChanges="orientation|keyboardHidden"/>
<activity
android:name=".NewPostActivity"
android:configChanges="orientation|keyboardHidden"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version"/>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="THIS_IS_THE_KEY_WE_NEEDED_TO_HAVE_DIFFERENT"/>
</application>
In Android there is a concept of buildTypes, so what you can do create three buildTypes or how many you are required in your team.
Like one, two and three as shown in picture below with three different manifests which all has different keys in each.
Now team memebers can choose their respective buildVariant and work, selected buildVariant doesnt have any affect when someone takes pull from git, it maintain the selection.

Categories

Resources