Android Studio - Run signed apk on emulator

后端 未结 3 1532
情书的邮戳
情书的邮戳 2020-12-14 04:20

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.

3条回答
  •  感动是毒
    2020-12-14 05:09

    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.

提交回复
热议问题