Home » Android » ant – Can I build my Android app as debug but sign with release keystore

ant – Can I build my Android app as debug but sign with release keystore

Posted by: admin May 14, 2020 Leave a comment


I’m trying to test in-app billing in my app. I have billing and product id’s all setup in the Play store but to test a transaction I need to sign my app with my release keystore otherwise it fails.

I’m using IntelliJ Idea (Ver. 11 CE) and can’t quite figure out how to configure the project to build with debug set and sign with my release keystore before deploying to my device.

I see I can set an ant target for a configuration and I’m assuming that’s the way to go but since my build.xml imports the Android SDK /tools/ant/build.xml there aren’t any targets in to choose.

To debug do I merely need to enable set android:debuggable=”true” in the manifest? Anyone have a suggestion for an ant target that would do the things I need? One that I can add to my build.xml?

How to&Answers:

With pointers in the right direction form Ixx I ended up setting android:debuggable=”true” and using the command line to build and deploy. Then attaching to the running process to debug.

My application is setup to build at the command line with an ant build.xml file that imports androidSDK/tools/ant/build.xml and a supporting build.properties file. I discovered that when I set android:debuggable=”true” and then do ‘ant release’ the build process will create a debuggable apk and sign it with the release key.

I created a target in my build.xml file that I could set for this case called set-debuggable

<target name="set-debuggable" description="sets internal named property">
    <echo>Setting internal named property...</echo>
    <property name="set.debuggable" value="true" />

Then in my -pre-build target I added

            <isset property="set.debuggable"/>



This creates my debuggable apk that is signed with my release key when I use ‘ant set-debuggable release’. Then I use ‘adb install -r myApp-release.apk’ to re-install the new build. I can then launch and attach to the running application for debugging through in-app purchases.

It appears as though both IntelliJ Idea and Eclipse use a self signed debug key somewhere on your system to build and deploy a debug apk from the IDE.

In hindsight I might have been able to replace the debug key that the IDE created with my release key and attempted to get the build to sign with that key (and find the password to use the key) but the build process above took me very little time to setup and start using. If anyone goes in this direction and gets it working, please add a comment to my answer.


As of IntelliJ IDEA 12 (don’t know about the previous versions), you can set a “Custom debug keystore” in the Android facet for the top level module. This way you can control how your APK is signed and actually use your release keys for debugging from the IDE.


I have this in build.xml to set debuggable attribute:

<condition property="build.env" value="${build.env}" else="local">
    <isset property="build.env" />

<!-- set debuggable=false for release and true for debug and others -->
<condition property="isDebuggable" value="false" else="true">
        <equals arg1="${build.env}" arg2="release" />

Where build.env is passed to the ant program like this (in the case of “release”):

ant <targets> -Dbuild.env=release

In order to sign, you add this to the property files:


Debug app has a debug keystore (although I currently don’t remember exactly why this keystore is necessary)->here‘s more information on it. Probably you just have to use the release keystore instead.


IntelliJ is using .android/debug.keystore file by defult for signing debug version of your application. You could change this file with your release keystore or import your release certificate to debug.keystore file. I have prepared step by step instructions for this at http://www.denizoguz.com/2013/01/12/failure-install_parse_failed_inconsistent_certificates/


Given that Lint now advises against hardcoding of “android:debuggable” flag in AndroidManifest.xml I’ve come with a better solution (at least for my case). Just define a new ant target in your custom_rules.xml that does everything exactly the same as the android debug target does, but signs the apk with release key as well.

<target name="build-debug" depends="-set-debug-files, -do-debug, -release-sign, -post-build" />

The only subtask that needs to be added is “-release-sign” before “-post-build” and then run your “bulid-debug” instead of android “debug” target.

Or, you can just “-release-sign” to debug dependency like this:

<target name="build-debug" depends="debug, -release-sign" />

but this doesn’t work for me, because I do some extra stuff on “-post-build” and need to sign the package before “-post-build”.


Try setting the debuggable flag to true in your android manifest.


Debuggable Flag