AzAz
AzAz

Reputation: 43

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

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

Answers (3)

BertKing
BertKing

Reputation: 529

  1. Using the packageName extracted from the AndroidManifest.xml,

  2. You shold remove package form AndroidManifest.xml file.

  3. 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

Thomas
Thomas

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

Khemraj Sharma
Khemraj Sharma

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

Related Questions