Home » Android » Android Studio – Run signed apk on emulator

Android Studio – Run signed apk on emulator

Posted by: admin June 15, 2020 Leave a comment

Questions:

This may sound extremely trivial but as an android newbie I just found myself buried under a ton of hashes tokens keystores and keytools which can be a bit overwhelming.

I am trying to make android studio run my application on the emulator signed with my custom keystore and not the debug.keystore

Is this an option, or do I just have to generate a signed .apk every time I make changes, then install it via adb and then run it from the emulated device’s menu?

Also is that a good practice when testing applications or should I avoid it?

How to&Answers:

After running into problems when using the Android Studio UI to create a signing config I successfully managed setting it up via the gradle build file.

Open your projects build.gradle file. It should contain something like this:

android{
    //signingConfigs goes here
    defaultConfig{
        //SDK version, version code etc
    } 

     //Some more stuff
}

If it isn’t already in there, add the following snippet below android {

signingConfigs {
    debug {
        storeFile file(project.property("MyApp.signing"))
        storePassword project.property("MyApp.signing.password")
        keyAlias project.property("MyApp.signing.alias")
        keyPassword project.property("MyApp.signing.password")
    }
}

Now in the same directory where your build.gradle file lies you should have a gradle.properties file (if not, create it). We’ll now add the properties we used above to the properties file in order to map the values:

MyApp.signing=RelativeOrAbsolutePathToKeystore
MyApp.signing.password=yourPassword
MyApp.signing.alias=aliasNameOfYourKeystore

An example where the keystore.jsk file (generated via Android Studio) lies one directory above the app directory (in which the properties file is):

MyApp.signing=../myapp.keystore.jsk
MyApp.signing.password=helloworkd
MyApp.signing.alias=myapp_alias

The above configuration would then use the key to sign a debug build (because our signingConfigs was made for the debug build).

So make sure that in Android Studio, to set your build variant to “debug”. If you want to do all this for the release build switch your build variants to release and your signingConfigs to release {…} instead of debug{…} or simply add both if you want to switch between them.

Answer:

You can just add a signing config to the debug build type and it will use it. You can do it through the Project Structure dialog — in your module, select the “Signing” tab and configure your signing info, then in the “Build Types” tab, for the “Signing config” popup, choose it.

Answer:

Now it’s very simple in Android Studio 3

Configure the signingConfigs and release buildTypes in your build.gradle file and go to the build menu.

Build -> Select Build Variants

There has two options module and build variant.

Module will be app and Build Variant will be release