Author Topic: A simpler way to rename the application package  (Read 2906 times)

Offline littleguy

  • Moderator
  • double
  • *****
  • Posts: 1945
    • View Profile
A simpler way to rename the application package
« on: February 19, 2013, 08:32:51 PM »
Was talking with some of the Acralyzer devs and one mentioned that you don't need to change the package name for every class/activity to push out alternative versions of the app on the market.  You only need to change the application package name.  I've tried manually changing the name in the manifest, but that never works.  Build failure.  There's a little more to it than that obviously.

But then I discovered this gem.  The answer was right under my nose the whole time.  So I gave it a try and lo and behold, it worked.  Everything including the native emulator code worked just fine, no change in behavior.

One of the benefits of doing it this way (besides the fool-proof simplicity) is that different application packages will generate the same stack traces because the package names remain the same across the different apps.  With the current approach, you get two different error signatures in BugSense or Acralyzer (or whatever your crash report tool):
Code: [Select]
java.lang.Exception: BENIGN CRASH TEST
at paulscode.android.mupen64plus.util.CrashTester.testCrash(CrashTester.java:70)
Code: [Select]
java.lang.Exception: BENIGN CRASH TEST
at paulscode.android.mupen64plus.free.util.CrashTester.testCrash(CrashTester.java:70)

Using the simple method in the link, both apps generate the same stack trace (which is exactly what we want):
Code: [Select]
java.lang.Exception: BENIGN CRASH TEST
at paulscode.android.mupen64plusae.util.CrashTester.testCrash(CrashTester.java:70)

2012 Nexus 7, rooted stock Lollipop
Samsung Galaxy Victory, rooted stock Jelly Bean
Xperia PLAY, stock Gingerbread
OUYA, retail version

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3491
  • Developer
    • View Profile
    • PaulsCode.Com
Re: A simpler way to rename the application package
« Reply #1 on: February 19, 2013, 11:40:47 PM »
I'm so glad I have my PC and can use Eclipse again :)
Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
RAM: 1 GB
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
RAM: 2GB
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted

Offline xperia64

  • Moderator
  • double
  • *****
  • Posts: 591
    • View Profile
    • My Apps
Re: A simpler way to rename the application package
« Reply #2 on: February 20, 2013, 04:25:22 PM »
I'm curious as to how JNI still works..

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3491
  • Developer
    • View Profile
    • PaulsCode.Com
Re: A simpler way to rename the application package
« Reply #3 on: February 20, 2013, 04:53:42 PM »
I haven't tried it yet myself.  I assume it only changes the Application package name in the manifest, and not the Java package name(s).  The only reason this isn't easy to do manually with a simple edit of the manifest, is because ant uses the Application package name to generate R.java, not a Java package name (since you can potentially have multiple Java package names, how would it know the "right" one?)  If Eclipse is smart enough to generate R.java in the "right" place whenever the Application package name is changed (or add in the proper import calls), then that could be how they are doing it.  It would have no effect on JNI which deals with the Java package names, not the Application package name.
Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
RAM: 1 GB
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
RAM: 2GB
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted

Offline littleguy

  • Moderator
  • double
  • *****
  • Posts: 1945
    • View Profile
Re: A simpler way to rename the application package
« Reply #4 on: February 20, 2013, 05:17:39 PM »
That's exactly right.  The eclipse refactoring tool replaces all instances/imports of old.package.name.R with new.package.name.R, in all your java classes.  It also updates some of the namespaces in the related resource xml files.  It doesn't change any C code, at least not in mupen, and it doesn't rename the directory structure of the java files or change the java class packages.
« Last Edit: February 20, 2013, 05:20:21 PM by littleguy »
2012 Nexus 7, rooted stock Lollipop
Samsung Galaxy Victory, rooted stock Jelly Bean
Xperia PLAY, stock Gingerbread
OUYA, retail version