Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio - Run signed apk on emulator

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?

like image 618
ppp Avatar asked Jul 22 '14 18:07

ppp


People also ask

Can drag and drop APK to emulator?

Install an APK via drag-and-drop or connect to Android tools over ADB. The Visual Studio Emulator for Android fits nicely into your existing Android development environment, with APK and file installation that is as simple as dragging and dropping items on the emulator screen.

Can I upload unsigned APK to play store?

You cannot upload to Google Store a not signed and not aligend APK. Ask your developer to give you the signed and aligend APK. Or you can ask them to provide the key to you so you can sign and align it yourself using that key .


2 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.

like image 143
AgentKnopf Avatar answered Sep 19 '22 19:09

AgentKnopf


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.

like image 22
Scott Barta Avatar answered Sep 20 '22 19:09

Scott Barta