简体   繁体   中英

Android Studio 2016 renaming com.example file error

I have installed Android Studio with the latest update and I have downloaded the sample app called MediaEffects . So I successfully downloaded the program and built it as an apk(also tested on my phone) to upload to the Google play store.

When I tried uploading the sample app, Google play developer console said something like com.example was not allowed. So I searched up how to rename the package and found some useful links to rename packages. So I right clicked the com.example.android and clicked Refactor and then rename. I renamed 'example' to something like 'media' right to change the package name anything other than example. And here's and image of the steps that concluded:

So first the in the debug menu area, I pressed Do Refactor and after a few seconds, an error message popped up

Error Message:

I also saw some other topics talking about something like oh run Android Studio with administrator privileges, but that didn't seem to work. So do you guys have any ideas how to rename the package from com.example.android to something like com.media.android? Or is it possible to copy and paste the code into another clean project I made? I have tried doing that, but it keeps saying error messages about certain files not being able to be found.(I think i need to edit some code lines but I'm not sure which files to edit) But please help is needed quickly!

First, just erase your current project and download (or extract, if you still got the .zip around) a fresh, new copy of it.

Now, follow the steps you took when you build your first project. Just to make sure everything's fine up to this point.

Once it runs, head back to Android Studio. You'll notice that on the top-left sidebar there's an item labeled Project . Click it if you haven't had it open already.

Next step is the most important: Just beside the dropdown, you'll see a small cog/gear icon on the right side of the top-bar. Click it and uncheck Compact empty middle packages .

取消选中“紧凑的空中间包”

Next, navigate to your app's Java source folder ( /app/src/main/java ). If you follow these steps correctly, you should see something similar to this in your Project sub-window:

your-project-name
  |
  +-...
  |
  +-app
  |  |
  |  +-build
  |  |  |
  |  |  +-...
  |  |
  |  +-src
  |  |  |
  |  |  +-main
  |  |  |  |
  |  |  |  +-java
  |  |  |  |  |
  |  |  |  |  +-com
  |  |  |  |     |
  |  |  |  |     +-example
  |  |  |  |        |  
  |  |  |  |        +-media
  |  |  |  |           |
  |  |  |  |           +-...
  |  |  |  +-...
  |  |  +-...
  |  +-...
  +-...

To rename your project's package, just select either one of com , example , or media and refactor the way you did with the first project.

The key here is to rename each folders separately. As an example, say you want to rename com.example.media to my.firstapp.newmedia , you do this:

  1. Right click com > Refactor > Rename > "my"
  2. Right click example > Refactor > Rename > "firstapp"
  3. Right click media > Refactor > Rename > "newmedia"

One more thing: When a dialog shows up, select Rename package and Android Studio should take care of the rest.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM