35

I am developing an app which uses Google APIs. I have created credentials at "Google Developers Console". If I creates a signed APK, and run it on the phone, there is no problem.

The problem is, while I developing the app, when I click RUN button, it deploys an unsigned version of the app on the phone. Thus the application does not work.

How can I set Android Studio to make it deploy signed APK on the phone when click RUN button?

Glorfindel
  • 19,729
  • 13
  • 67
  • 91
fthdgn
  • 1,178
  • 1
  • 12
  • 16

4 Answers4

54

Add these values to your .gradle:

signingConfigs{
    debug{
        keyAlias 'your key alias'
        keyPassword 'your keypassword'
        storeFile file('keystore path')
        storePassword 'your storepassword'
    }
}
buildTypes {
    debug{
        signingConfig signingConfigs.debug
    }
}  

The keystore path in the file will be something like E:/xxx/xxx/xx.keystore.

Ninja
  • 2,289
  • 3
  • 18
  • 32
floatingmuseum
  • 678
  • 7
  • 10
  • 1
    I always get this error: "Installation failed with message Failed to finalize session : INSTALL_FAILED_INVALID_APK: /data/app/vmdl52362262.tmp/1_slice__ signatures are inconsistent. It is possible that this issue is resolved by uninstalling an existing version of the apk if it is present, and then re-installing." i uninstalled menually but your code not work for me why? – MarsPeople Jul 29 '17 at 18:52
  • 2
    i solved my "signatures are inconsistent" error with this: https://stackoverflow.com/a/42703302/1472483 – MarsPeople Jul 29 '17 at 19:16
  • 3
    Which level? `Project` or `Module` – SD826E Jan 19 '20 at 16:05
  • @SD826E I put this config in the Module level, something called 'app' – Ninja Feb 24 '21 at 08:20
19

Usually I do it from command line, installing via "adb install -r file.apk" (-r to preserve app's data)

Also it can be done via Gradle and project settings, see answers here: Android Studio - Run signed apk on emulator

Community
  • 1
  • 1
Mixaz
  • 3,749
  • 25
  • 51
  • this is the correct way: Generate signed Apk then install it with this command "adb install -r path_to/app-release.apk". Previous answer (modifying signingConfigs{}) will not generate a proper release version of the app like that you launch to the Google Play. – Dan Alboteanu Aug 10 '18 at 11:19
1

When I want to test my APK release I just use ADB-Link. Its free and very easy to setup. Just make sure to delete any previous builds that you installed on your device otherwise the installation will fail.

0

Maybe this is not an answer to your question about how to sign the app before running it, but have you thought about the option to create a new signature key for the debug key you are using? You could use a separate API key in debug mode.

I found some extra information about using a key in release and debug mode: Android: automatically choose debug/release Maps v2 api key?

Community
  • 1
  • 1
guido
  • 176
  • 4