google-ar / arcore-android-sdk

ARCore SDK for Android Studio
https://developers.google.com/ar
Other
4.96k stars 1.22k forks source link

AR Cloud Anchor Hosting Error: ERROR_NOT_AUTHORIZED #377

Closed mervyn-thyng closed 6 years ago

mervyn-thyng commented 6 years ago

I am getting this error on Android after setting up the quick start sample app com.google.ar.core.examples.java.cloudanchor.

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:

  1. Set up Firebase Realtime DB. Rule for public.
  2. Enabled Cloud Anchor API, and added API key in Cloud credentials and then in manifest.

Before 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 the 2 platforms.

I have also tried setting up the Android sample app with a new Firebase project and get the same error on Android.

Please advise what I am missing.

Thank you,

asadullahnaweed commented 6 years ago

Could you please reproduce the AndroidManifest.xml file you're using?

mervyn-thyng commented 6 years ago
<?xml version="1.0" encoding="utf-8"?>
<!--
   Copyright 2018 Google Inc.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
-->
<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>
adriancampos commented 6 years ago

I had to place the API key inside of the application element to get it to work.

End result looked like this:

...
  <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"/>

  <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">
...
mervyn-thyng commented 6 years ago

Yes! that did it. Thank you. It would be great if the docs were more specific as well as codelab docs (which specifically instructs to place meta element out of the application element).

Thanks again!

asadullahnaweed commented 6 years ago

It would be great if the docs were more specific as well as codelab docs (which specifically instructs to place meta element out of the application element).

Could you please provide a link to where this statement is made?

fionarobinson commented 6 years ago

Thanks for pointing this out! We've now clarified this instruction in our documentation: https://developers.google.com/ar/develop/java/cloud-anchors/cloud-anchors-quickstart-android#add_an_api_key

Hope this helps!

gitunit commented 5 years ago

one year later this mistake in the codelab still exists. please fix to prevent confusion. https://codelabs.developers.google.com/codelabs/arcore-cloud-anchors/#2

amirtha17 commented 1 year ago

Am getting the same error not authorized even after using key less authentication, this meta-data isn't being used in the newer version, I tried putting that meta-data inside application too but it doesn't work... any help?