1

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.

Bryan Herbst
  • 66,602
  • 10
  • 133
  • 120
ACluelessProgramer
  • 308
  • 1
  • 5
  • 13

1 Answers1

8

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.

Bryan Herbst
  • 66,602
  • 10
  • 133
  • 120
  • I don't have applicationId in my build.gradle. Should I just add the bit of code you put? When I do add it, I get an error like this: Error:(11, 0) Build script error, unsupported Gradle DSL method found: 'defaultConfig()'! or android()'! Is there a specific place i'm supposed to put it? I'm using Gradle 0.12.2. Thanks for your patience. – ACluelessProgramer Oct 03 '14 at 20:41
  • You should already have a build.gradle file with an `android {}` block, and probably a `defaultConfig {}` block in that. Some projects might have 2 build.gradle files, so make sure you are editing the one in your application module's folder. – Bryan Herbst Oct 03 '14 at 20:49
  • I found the second build.gradle like you said, and sure enough, the old package name was there. I changed it and it seems to be working. I've reached my limit of APK uploads for today, so I'll let you know if it worked. If it works, I'll mark your answer as solved. Thanks for your help. – ACluelessProgramer Oct 03 '14 at 21:07