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 trialThomas Moore
4,275 PointsCouldn'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
Gloria Dwomoh
13,116 PointsYou 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.
Unsubscribed User
3,268 PointsHi Ben could you tell me how to fix this with Android Studio as its really starting to bug me?
Ben Jakuben
Treehouse TeacherYou 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
3,335 PointsHi,
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
3,335 PointsSame 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
3,335 PointsI 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
Treehouse TeacherAre 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
4,275 PointsOh no worries! You guys have been great at answering my questions. Thank you so much!
Unsubscribed User
3,268 PointsHi 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
7,163 Pointsdeveloping for android is so complicated
Wen Bo
6,182 PointsI have tried all the methods above. They are all doesn't work. It still shows that "com.example" is restricted.
Wen Bo
6,182 PointsI got it.
Carla Brooks
803 Pointshi Wen, have you got the answer, i am facing the same problem here :(
Thomas Moore
4,275 PointsThomas Moore
4,275 PointsWord. 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.
Gloria Dwomoh
13,116 PointsGloria Dwomoh
13,116 PointsWhich 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
4,275 PointsThomas Moore
4,275 PointsOh 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.
Gloria Dwomoh
13,116 PointsGloria Dwomoh
13,116 PointsIf that didn't work, try this technique.