3

I want to keep a stable version of my app on my phone, and continue developing... which would put the app on the phone twice, if there's a practical way to do that.

A search led to guys doing what I already had considered: re-factoring the package name, and maybe using a different icon file. That's kind of unhandy, and prone to doing something wrong, or forgetting, etc.

Using Android Studio, is there something fancy a person could do within the build.gradle files, or one of the other config files, to make this work easily?

EDIT ---

So, from suggestions below, I added the following block to build.gradle, above the 'defaultConfig' block.

buildTypes {
    debug {
        versionNameSuffix ".DB"
        applicationIdSuffix ".debug"
    }
}

As far as having a different icon to tell the builds apart, for now, I have added a single 72x72 icon variant into the res/drawable-hdpi folder. I've got comments in my manifest file with both icon names. I can just copy and paste into the android:icon line, to change icons.

stkent
  • 19,772
  • 14
  • 85
  • 111
wwfloyd
  • 312
  • 3
  • 11

2 Answers2

3

you can add to your buildTypes{ }

 debug {
        versionNameSuffix "-DEBUG"
        applicationIdSuffix ".debug"
    }
Yassine BELDI
  • 562
  • 5
  • 16
  • Thank you. I did end up with just what you suggested. But, I was unaware of the buildTypes existence or placement, which I found following links in the accepted answer. And, that answer did provide another option, and more detail. – wwfloyd Dec 30 '14 at 03:07
2

Check out gradle's product flavors. You could use a different package name in two different flavors, and then be able to install both flavors on your phone at once. Note: changing package names in this way may force other tweaks (e.g., if you use a Google API key for maps, you may have to allow both package names to use the generated key explicitly).

You should be able to do this same package renaming within the existing debug and release build types, but I get the sense you want both stable and cutting-edge builds to be debug variants.

Tweaked code example from the docs linked:

productFlavors {
    flavor1 {
        packageName "com.example.flavor1"
    }

    flavor2 {
        packageName "com.example.flavor2"
    }
}

If you go this route, be sure to read the "Build Type + Product Flavor = Build Variant" section of the linked docs too. Other gradle stuff you should read up on for a complete picture: applicationId, packageNameSuffix, applicationIdSuffix.

stkent
  • 19,772
  • 14
  • 85
  • 111
  • Very nice, thank you. It had not even occurred to my that this mysterious Gradle might have documentation, heh. Actually, I did want .APK file for my stable build, so was able to just adapt the 'buildtypes' block given in [the docs](http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Basic-Build-Customization), leaving out the 'jnidebug' stuff. ybeldi alluded to this in his answer, but, I did not yet know about buildTypes in build.gradle. – wwfloyd Dec 30 '14 at 03:05
  • Glad you found a solution! Gradle stuff is _decently_ documented, but there are definitely some parts that could still do with a little more coverage. – stkent Dec 30 '14 at 03:06
  • I think the correct answer would be buildTypes not flavors. – Patrick May 23 '15 at 11:21