Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Publish an Android App Publishing on Google Play Uploading an APK

Thomas Moore
Thomas Moore
4,275 Points

Couldn't upload apk because "com.example" is restricted. What?

Tried to upload the apk for my android app and couldn't because "com.example" is restricted. Where is that coming from? How do I fix?

7 Answers

You have to rename your package name, as com.example is more of a placeholder, if you want to upload it to google play for example... you can't use that as a package name. Your package name has to be unique so that it won't match any existing package name but since com.example is the placeholder it is probably not a unique value. Try renaming your package.

Thomas Moore
Thomas Moore
4,275 Points

Word. How do I rename the root package (com.example)? When I refactor it from the directory, it only let's me rename the last clause of the package name.

Which directory? I suggest you go to your manifest file and there is an attribute called...package. Try refactoring that one and let me know if it works.

Thomas Moore
Thomas Moore
4,275 Points

Oh wait, no. That hasn't fixed it. Even though I've deleted and regenerated the APK, I still get the same error, though I don't know where com.example is in my project now.

If that didn't work, try this technique.

Hi Ben could you tell me how to fix this with Android Studio as its really starting to bug me?

Ben Jakuben
Ben Jakuben
Treehouse Teacher

You need to set the package name using the applicationId in your project's build.gradle file:

    defaultConfig {
        applicationId "teamtreehouse.com.funfacts"
        minSdkVersion 14
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }

Then you can right-click on the package in your main/java folder and select Refactor > Rename. Select Refactor Package and type the new one you just used in applicationId.

You'll need to re-sync Gradle and rebuild the project after this, of course. :)

Hope this helps...let me know if you run into trouble from this.

Juan ladron de guevara
Juan ladron de guevara
3,335 Points

Hi,

I canΒ΄t fix it, the folder does not let me change the name. It send me a message " Not a valid identifier name" . I tried with the answer of your last post.

Juan ladron de guevara
Juan ladron de guevara
3,335 Points

Same as Thomas, it only let me rename the last clause of the package name, even after set the new package name in the applicationId

Juan ladron de guevara
Juan ladron de guevara
3,335 Points

I Fixed it by :

create a new package with the desired name by right clicking on the java folder -> new -> package.

Then, select and drag all your classes to the new package. AndroidStudio will refactor the package name everywhere.

Finally, delete the old package.

http://stackoverflow.com/questions/16804093/android-studio-rename-package

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

Are you working with the old Crystal Ball app? I covered how to change a package name in a previous video that is now retired. You can still access it here, though: http://teamtreehouse.com/library/build-a-simple-android-app/sharing-your-creation/getting-ready-for-google-play-2

Check the 1:20 mark for where I talk about renaming the package. Sorry for the confusion!

Thomas Moore
Thomas Moore
4,275 Points

Oh no worries! You guys have been great at answering my questions. Thank you so much!

Hi there to change this go select file on windows. then Prodject Structure and then select app and Flavors.

From there you can change this Application Id.

Rakeem Williamson
Rakeem Williamson
7,163 Points

developing for android is so complicated

I have tried all the methods above. They are all doesn't work. It still shows that "com.example" is restricted.

I got it.

hi Wen, have you got the answer, i am facing the same problem here :(