Reputation: 43
I am new to espresso testing in android. When I try to build test apk I am getting this error:
Package 'com.class.foo.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?
Upvotes: 3
Views: 8446
Reputation: 529
Using the packageName extracted from the AndroidManifest.xml,
You shold remove package form AndroidManifest.xml file.
Add a namespace property under the android block in the build.gradle file.
Like this:
// build.gradle
android {
namespace "packageName"
...
}
See detail : https://discuss.gradle.org/t/namespace-not-specified-for-agp-8-0-0/45850
Upvotes: 0
Reputation: 6178
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.
Upvotes: 6
Reputation: 59004
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.
Upvotes: 3