27

While continuing to develop my application and test it on a real phone, I need to have the release version of it on the same phone, for demonstration purposes (the release version is much more responsive, thanks to no-logs).

The problem is that the only way to make two applications co-exist on the same device in Android is by having different package names.

But package names require re-factoring and lots of propagating manual fixes... not to mention that this confuses version control...

Ideally, Eclipse+ADT would allow appending a modifier variable that would automatically generate a different package name for debug/release and would allow such co-existence, but I couldn't find any mechanism that allows doing that.

Do you know of any way to workaround this?

Creative solutions and ideas are welcome.

Marian Paździoch
  • 8,813
  • 10
  • 58
  • 103
an00b
  • 11,338
  • 13
  • 64
  • 101

5 Answers5

24

Use Android Studio because gradle make your life a lot easier - just use applicationIdSuffix

android {  
   ...  
   buildTypes {  
     release {...}  
     debug {  
       applicationIdSuffix '.debug' 
     }  
   }  
}

For more go here.

Marian Paździoch
  • 8,813
  • 10
  • 58
  • 103
2

The only way I know is to change the package name in your applications manifest file. Eclipse should handle all the code renaming for you.

Caner
  • 57,267
  • 35
  • 174
  • 180
  • Wow! That almost worked. I appended a 'd' at the end of the package name in the manifest file, cleaned the project to rebuild and Eclipse didn't complain at all. I happily proceeded to running it but then it "force-closed". It turns out that my application uses reflection (class factory) and Android didn't like the discrepancy between the manifest's package name and the .java package name at all. +1 for getting so close. – an00b Sep 07 '11 at 17:49
  • if your release build has proguard obfuscation activated, and if you added some custom _rules_ to proguard.cfg, those might contain package name too. Also if you created custom View widgets and added them in some XML layout, they also are named with package. – superjos Dec 16 '11 at 17:32
2

Could you put all your code in a Library Project and then just have two normal projects, that have different package names and just include the library project in both?

This should keep all your code in one place. The normal projects would most likely only need a valid manifest file that points to the activities in the library project.

mcnicholls
  • 846
  • 5
  • 10
  • The Library Project has debug logging, too... (IOW, a Library Project requires conditional building just like the application). This solution doesn't work for me but +1 for the creative suggestion. – an00b Sep 07 '11 at 17:39
0

In Android Studio, Adding build variants using Product Flavours which can be easily customized for various environments and to test side by side multiple app variants of same app. Check out this link for more information - Configuring Gradle

Fenil
  • 1,194
  • 10
  • 11
0

You may want to try this technique using ant, Jenkins and perhaps other tools to automate package renames as suggested by @LAS_VEGAS.

Although not what you asked for, this cool code snippet can help you find out at runtime whether your code is debug or release.

Another interesting such attempt can be found in this thread. I am not sure though if it works on Android.

Community
  • 1
  • 1
Bill The Ape
  • 3,261
  • 25
  • 44