3

I am new to espresso testing in android. When I try to build test apk I am getting this error:

Package 'com.class.xxx.test' from AndroidManifest.xml is not a valid Java package name as 'class' is a Java keyword.

Is there any possible way to change the package name in the test build config or any other solution?

Thanks!

2 Answers 2

6

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.

3

As simple as it say.

not a valid Java package name, 'class' is a Java keyword.

There are some reserve keywords in Java. Which you can not use. You are using class, which is reserved word.

You can change class package name as solution.

List of Java reserved keywords.

4
  • I need to change the package name only on build for test apk do you maybe know how to do that?
    – AzAz
    Jul 23, 2018 at 10:31
  • Just use name refracting, select package to rename (class), then press shift + F6 to rename refract. It will handle all imports automatically. Jul 23, 2018 at 10:33
  • Yes but it is auto generated and when I change it it gets back to old one on build...
    – AzAz
    Jul 23, 2018 at 10:37
  • You can not change only test package name. I think, Change app package name, you need not change build.gradle package name, just use refracting in your manifest.xml package name. Jul 23, 2018 at 10:38

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.