ACluelessProgramer ACluelessProgramer - 3 months ago 18
Java Question

"com.example restricted" Google Play error; even when changing the package name

I went to publish my first android app from Android Studio. When I went to upload to Google Play, I got this error:


Upload failed: You need to use a different package name because "com.example" is restricted.


When I renamed the package name, it still gave me the error message. I tried making a new package and moving everything to that, but the error still persists. I've deleted any trace of the com.example package. I also made sure to change the Android Manifest.xml to the new package.

The only thing that still says the old package name is the BuildConfig.java, which contains this line followed by the rest of my old package name:

public static final String PACKAGE_NAME = "com.example"


If someone can please help me and answer to this post, I would greatly appreciate it. I'm using Ubuntu Linux 14.04.1.

Answer

This is related to a recent change in the Android Gradle plugin that split the application's identifier from the Java package name.

The application's identifier is used by Android to identify your application. It is also used as the identifier in the Play Store's URLs. This is often, but not always the same as the Java package name.

As of version 0.11 of the Gradle Plugin, the application ID is set in your build.gradle using the applicationId setting like so:

android {
    defaultConfig {
        applicationId "com.yourdomain.yourapp"
    }
}

Setting this should clear up your issue.

The error message in the developer console likely just hasn't changed to reflect the new terminology.

From the Gradle Plugin version 0.11 release notes:

One of the user visible changes in 0.11 is that we've deprecated the packageName and packageNameSuffix settings, and have renamed them to applicationId and applicationIdSuffix. The purpose of this is to make it clear that this application id is decoupled from package declarations in your manifest, and in particular, the R class and the BuildConfig class, and all the implementation classes inside your app, can be renamed and refactored freely; you just need to keep applicationId the same. If you open your build.gradle file, lint is highlighting these deprecated calls and offering quickfixes to update them.