Android Studio - 在模拟器上运行签名的 apk [英] Android Studio - Run signed apk on emulator

查看:78
本文介绍了Android Studio - 在模拟器上运行签名的 apk的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这听起来可能非常微不足道,但作为一个 Android 新手,我发现自己被大量哈希令牌密钥库和密钥工具所淹没,这可能有点让人不知所措.

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.

我试图让 android studio 在用我的自定义密钥库而不是 debug.keystore 签名的模拟器上运行我的应用程序

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

这是一个选项,还是我每次进行更改时都必须生成一个签名的 .apk,然后通过 adb 安装它,然后从模拟设备的菜单中运行它?

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?

推荐答案

在使用 Android Studio UI 创建签名配置时遇到问题后,我成功地通过 gradle 构建文件对其进行了设置.

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.

打开你的项目 build.gradle 文件.它应该包含如下内容:

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
}

如果它不在那里,请在 android {

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")
    }
}

现在在 build.gradle 文件所在的同一目录中,您应该有一个 gradle.properties 文件(如果没有,请创建它).我们现在将上面使用的属性添加到属性文件中以映射值:

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

keystore.jsk 文件(通过 Android Studio 生成)位于应用程序目录(属性文件所在的目录)上方一个目录的示例:

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

因此请确保在 Android Studio 中将您的构建变体设置为调试".如果您想为发布版本执行所有这些操作,请将您的构建变体切换为 release 并将您的签名配置切换为 release {...} 而不是 debug{...} 或者如果您想在它们之间切换,则只需添加两者.

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.

这篇关于Android Studio - 在模拟器上运行签名的 apk的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆