Sam Borick
Sam Borick

Reputation: 955

Android Studio Generates bad manifest code

I'm working on creating a simple test project that lets me manage a service with AlarmManager. I somehow managed to create a new broadcast reciever with the name +.java in my service folder, so now Android Studio generates this invalid block of code in the AndroidManifest:

<receiver
        android:name=".service.+"
        android:enabled="true"
        android:exported="true" />

Which generates the error

Error:(32) Tag <receiver> attribute name has invalid character '+'.

When I remove the block and rebuild, Android Studio regenerates the block and the error repeats. Since this is a minor test project it's not a huge issue, but what if this happened in a larger project where I can't just nuke the whole directory?

My question is, how or where can I tweak what blocks of code Android Studio generates in order to resolve strange issues like this one?

Upvotes: 2

Views: 119

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007484

There is a long-standing issue in Android Studio, where the IDE opens up the wrong edition of a file when it encounters an error. In the case of the manifest, Android Studio tends to open up a code-generated manifest, from the manifest merger process, rather than the actual manifest file that was the source of the error. As a result, the unwary (or the wary who are short on sleep) will edit the generated manifest... which then gets regenerated and blows away the edit.

The workaround is to double-check which file it is that you are editing when your changes seem to evaporate. A good night's sleep helps.

::yawns::

According to the issue, this should be fixed in Android Studio 2.3, which is working its way towards shipping sometime here in early 2017.

Upvotes: 3

Related Questions