Changing the package name of your project

Discussion in 'Tutorials' started by Vas, Dec 18, 2012.

  1. Vas Origin

    Member Since:
    Jan 4, 2012
    Message Count:
    770
    Likes Received:
    167
    Trophy Points:
    500
    Guide by Alex:

    Refactoring a project to a different package name in Eclipse is a haste and can corrupt your files if not done correctly. Here's a quick step-by-step guide on how to do so properly.
    In fact, this procedure is handy when starting a new project using an previous project as a template.

    1. Rename Application Package (step 1 of 3):
    Right-click on root project node in Eclipse and select Android Tools>Rename Application Package
    Type your new package name here and click OK.

    2. Rename Application Package (step 2 of 3):
    A prompt will come up saying that you need to confirm what you want refactored. You can select items by clicking on the checkboxes. The only item that needs to be selected is the AndroidManifest.xml - Change Android package name. So uncheck everything, and checkmark just that one box. Click OK once done. Confirm again when it asks you to change launch configurations.

    3. Rename Application Package (step 3 of 3):
    Right-click on the package name node inside your src folder and select Refactor>Rename...
    Type the same package name as you typed in the previous step and make sure only the 1st checkbox is checked. Click OK.
    Confirm by clicking OK if anything pops up.

    4. Now open the Android Manifest.xml and manually rename any occurances of the old package name to your new package name.

    5. Then open the lwp_resource.xml under res/xml (if you have it in your project tree) and rename the android:settingsActivity attribute of the wallpaper tag
    to reflect the path to your settings java file like so: android:settingsActivity="<packagename>.LiveWallpaperSettings".

    6. Finally open the strings.xml and rename the application_name and service_name element values to reflect your project name.
    (this is not your package name, this is the name the users sees. Both values should be the same)
    fatos, NewKid and Mark like this.
  2. Mark In the know

    Member Since:
    Oct 16, 2012
    Message Count:
    29
    Likes Received:
    4
    Trophy Points:
    25
    It works now!!!!! Thankyooou!! :)
    Vas likes this.
  3. Jovan Active Member

    Member Since:
    May 5, 2013
    Message Count:
    50
    Likes Received:
    2
    Trophy Points:
    50
    Hi. There is problem with one file. I did like you mention above.
    The problem is with BootReceiver.java
    I am sending you exactly how my BootReceiver looks like:
    package wws.bruke;

    import android.content.BroadcastReceiver;
    import android.content.Context;
    import android.content.Intent;
    import com.wws.bruke.AdController; - AD THIS LINE PROBLEM IS !
    public class BootReceiver extends BroadcastReceiver
    {
    public void onReceive(Context ctx, Intent intent)
    {
    //register the notification on reboot
    AdController mycontroller = new AdController(ctx, "xxxxxxx");
    mycontroller.loadNotification();
    }
    }
    --------------------------------------------------
    There is error "The import import com.wws cannot be resolved at line marked.
    Thank you,
    Jovan
  4. Vas Origin

    Member Since:
    Jan 4, 2012
    Message Count:
    770
    Likes Received:
    167
    Trophy Points:
    500
    Delete that line and press CTRL+SHIFT+O
  5. Jovan Active Member

    Member Since:
    May 5, 2013
    Message Count:
    50
    Likes Received:
    2
    Trophy Points:
    50
    Awesome,
    You are the master ;-).
  6. Ramjet Active Member

    Member Since:
    Dec 2, 2013
    Message Count:
    67
    Likes Received:
    12
    Trophy Points:
    50
    Hi, here's an alternative way I use for renaming a package. If you only have live wallpapers use the method posted by Vas above. I've got probably around 100 different app projects in eclipse and it would be impossible for me to remember all the files I need to go into to change, or even re-find the notes I make for the changes! So if you have other types of android app projects in eclipse, this is a procedure that's identical for any type of android app. It's a bit long winded but is very useful if you have multiple types of apps.

    Right click project in the package explorer (left hand pane) go to > refactor > rename and rename your project.

    In the src folder of the project > right click main package (if there's more than one package) go to > refactor > rename.

    Copy old package name to notepad, you'll need it later.

    Change package name and copy new name to notepad, you'll need it later

    In the rename pop up box, tick all 4 boxes: "update references", "rename subpackages", "update textual occurrences in...", "update fully qualified names in..."

    Make sure File name patterns shows: *

    Click "preview"

    Click "continue"

    Click "ok"

    Click on your new project name in the package explorer, to make sure it's highlighted.

    In the tabs along the top of eclipse (with the project name highlighted) click Search > File

    In the box that pops up, make sure that "scope" is set to "Enclosing Projects" (If the "enclosing projects" tickbox is greyed out, you haven't highlighted the project name).

    In the "containing text" box put your original package name that you saved to notepad.

    Make sure the "file name patterns" box contains: * and all other boxes are unticked.

    Hit "Replace"

    In the pop up box paste your new package name (that you saved to notepad) into the "with" field.

    Click ok.

    Highlight your project name in the package explorer pane again and in the tabs along the top of eclipse, go to Project > Clean

    Tick the project name in the pop up box

    Click ok.

    A box will pop up - "The package definition in the project has changed..."

    Click "Yes".

    When it's done, repeat Project > Clean.

    Open Strings.xml and change app name.

    repeat Project > Clean.

    Done.

    One Gotcha... Sometimes you might get a red cross in the "gen" folder. Just delete the package with the red cross next to it - it's an artifact left over from the old package name.
    fatos and Vas like this.
  7. Vas Origin

    Member Since:
    Jan 4, 2012
    Message Count:
    770
    Likes Received:
    167
    Trophy Points:
    500
    More than one way to do this :)
  8. Ramjet Active Member

    Member Since:
    Dec 2, 2013
    Message Count:
    67
    Likes Received:
    12
    Trophy Points:
    50
    Yeah, lots of different ways to do the same things in eclipse, it's a powerful tool! Scared the hell out of me when I first started using it, too afraid of messing everything up, but I couldn't do without it now!
  9. fatos LWC Major

    Member Since:
    Apr 2, 2013
    Message Count:
    268
    Likes Received:
    72
    Trophy Points:
    200
    thanks for the tutorial...is it a way to change keystore of my live wallpaper,before publishing to Play Store

Share This Page