I was getting this because I had a package name with a -
in it (i.e. test-support
). In the module's AndroidManifest.xml
I had
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.thomas.myapp.test-support" />
The Java Language Spec says
If the domain name contains a hyphen, or any other special character not allowed in an identifier (§3.8), convert it into an underscore.
I didn't convert to an underscore, but just removing the hyphen works. I changed the AndroidManifest.xml
to
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.thomas.myapp.testsupport" />
and it works fine now. Khemraj's answer put me on the right track to figuring this out.