4

I created a new Google Maps Activity, and the only thing I did was stick my API key into the .xml file. When I run the project, I get an: "Error: '-' is not a valid resource name character" in the .xml file. What is wrong with the project, and how can I fix the error? .xml file error

8
  • check your .xml resource file.you declare the some resource with - (hyphen) and android not allow a use of hyphen in resource file name of resource ids so check it once Commented Dec 23, 2015 at 5:31
  • see this code.google.com/p/android/issues/detail?id=31 Commented Dec 23, 2015 at 5:33
  • The only hyphen I have in the .xml file is the hyphen in the API key, no other "-"s in the entire file. Commented Dec 23, 2015 at 5:40
  • I added a screenshot of Android Studio with the error. Commented Dec 23, 2015 at 5:56
  • issue in google_maps_api.xml Commented Dec 23, 2015 at 5:57

3 Answers 3

6

i had this error, mainly it is where you place the key... Replace the YOUR_KEY in the code with your API key that start with Alza

from

 <string name="google_maps_key"
    templateMergeStrategy="preserve"
    translatable="false">YOUR_KEY</string>

to

 <string name="google_maps_key"
    templateMergeStrategy="preserve"
    translatable="false">AIzaSyBs8wUvJW-zOZixEiPmedagyrW8Y7VcW4I</string>
Sign up to request clarification or add additional context in comments.

Comments

1

in your android studio on google_maps_api.xml there will something like this :

You can also add your credentials to an existing key, using this line: 47:2A:E4:BC:00:1D:21:E2:FA:20:B9:AB:70:FB:75:E7:23:16:37:C1;com.example.radio.demomap

notice that it is separated by a semicolon

47:2A:E4:BC:00:1D:21:E2:FA:20:B9:AB:70:FB:75:E7:23:16:37:C1 ; com.example.radio.demomap

now when you go to google console developer to create credentials

example

type your package name and fingerprint certificate key and enter create you will get your correct key

Comments

1

You should put the key this way:

<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">**YOUR_KEY**</string>

Not this way:

 <string name="**YOUR_KEY**" templateMergeStrategy="preserve" translatable="false"></string>

1 Comment

Ahh... I'm an idiot. To be fair, the comment block is a bit misleading when it says Once you have your key (it starts with "AIza"), replace the "google_maps_key" string in this file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.