3

Say I have a production version com.android.xyz and this is production then I am developing something and i want to load both this version and the production version on my phone so it's side by side. I know I can create a new package like com.android.abc and then I would have a second app which is basically a clone of com.android.xyz.

Thoughts?

Thanks in advance, Reid

reidisaki
  • 1,525
  • 16
  • 29
  • 1
    AFAIK, changing the package name is the only way to do this. – Code-Apprentice May 09 '14 at 22:15
  • ahh yeah i know the package name is basically the way to do this, so I would simply change the package name, and run a script to go into each file and project and change everything to reference the new package name using some kind of script. – reidisaki May 09 '14 at 22:30
  • I think you might be confusing the **Android** package name with the **Java** package structure. You can change the former without changing the later. – Code-Apprentice May 10 '14 at 03:19
  • yeah so when I change the android package name, then the whole code doesn't compile. I'll try this again on Monday though. Thanks! – reidisaki May 11 '14 at 00:32

2 Answers2

4

IF you are using Android Studio with Gradle, there is an easy way to do this. I still keep the the same packageName in AndroidManifest.xml (at least current gradle needs this duplicate definition)

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:installLocation="internalOnly"
package="com.android.xyz">

build.gradle

def devBuildName = "dev"
def testBuildName = "test"

android {
defaultConfig {
    versionCode 70
    versionName "2.2.3"
    minSdkVersion 10
    targetSdkVersion 19
    packageName "com.android.xyz"
}

buildTypes {
    debug {
        packageNameSuffix "."+devBuildName
        versionNameSuffix "-"+devBuildName.toUpperCase()
    }

    test.initWith(buildTypes.debug)
    test {
        packageNameSuffix "."+testBuildName
        versionNameSuffix "-"+testBuildName.toUpperCase()
    }
}
}

You can look at my full dev/release example at github.

frederick_c_siu
  • 540
  • 3
  • 8
  • 4
    This just requires Gradle. Android Studio uses Gradle, but you do not need Android Studio to use Gradle. – CommonsWare May 09 '14 at 22:32
  • yes i think i'm gonna have to give gradle a try! Thanks everyone! – reidisaki May 10 '14 at 02:33
  • The other way is to do it this way: http://stackoverflow.com/questions/3697899/package-renaming-in-eclipse-android-project manually , but its just a 2 button clicks. – reidisaki May 12 '14 at 15:46
0

You need to change the package name. IMO the easiest way to do this is by writing a perl/python script to iterate through the files and change the package name based on the build type. Or run a C style macro preprocessor over the files first.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127