简体   繁体   English

生成签名apk android studio

[英]Generate signed apk android studio

I am new to android development and just finished my first app.我是 android 开发的新手,刚刚完成了我的第一个应用程序。 I want to generate a signed apk in android studio.我想在 android 工作室中生成一个签名的 apk。 I read the developer docs but couldn't understand the steps.我阅读了开发人员文档,但无法理解这些步骤。 When I click on Build>Generate Signed APK... , it shows me a dialog box asking the following:当我单击Build>Generate Signed APK...时,它会显示一个对话框,询问以下内容:

Keystore path  //with two options create new and choose existing
Keystore password
Key alias
key password

I don't get what is keystore even after googling it.即使在谷歌搜索之后我也没有得到什么是密钥库。 When I choose create new it asks me to select a path and locate a .jks file which I don't have.当我选择create new时,它会询问我 select 路径并找到我没有的.jks文件。 Can anyone please explain and list the steps in order to generate a signed apk.谁能解释并列出生成签名apk的步骤。

I dont think anyone has answered the question correctly.So, for anyone else who has the same question, this should help :我认为没有人正确回答了这个问题。所以,对于有同样问题的其他人,这应该会有所帮助:

Step 1 Go to Build>Generate Signed APK>Next (module selected would be your module , most often called "app")第 1 步转到 Build>Generate Signed APK>Next(选择的模块将是您的模块,通常称为“app”)

Step 2 Click on create new第二步点击新建

Step 3 Basically, fill in the form with the required details.第 3 步基本上,用所需的详细信息填写表格。 The confusing bit it is where it asks for a Key Store Path .令人困惑的一点是它要求Key Store Path Click on the icon on the right with the 3 dots ("..."), which will open up a navigator window asking you to navigate and select a .jks file.Navigate to a folder where you want your keystore file saved and then at the File Name box at the bottom of that window, simply enter a name of your liking and the OK button will be clickable now.单击右侧带有 3 个点(“...”)的图标,这将打开一个导航器窗口,要求您导航并选择一个 .jks 文件。导航到要保存密钥库文件的文件夹,然后在该窗口底部的“文件名”框中,只需输入您喜欢的名称,即可单击“确定”按钮。 What is happening is that the window isnt really asking you chose a .jks file but rather it wants you to give it the location and name that you want it to have.正在发生的事情是,窗口并没有真正要求您选择 .jks 文件,而是希望您为其提供您希望它拥有的位置和名称。

Step 4 Click on Next and then select Release and Voila !第 4 步单击下一步,然后选择发布和瞧! you are done.你完成了。

Use Keytool binary or exe to generate a private keystore.使用 Keytool 二进制或 exe 生成私有密钥库。 Instructions here . 说明在这里 You can then sign your app using this keystore.然后,您可以使用此密钥库为您的应用程序签名。 Keytool gets installed when you install Java.安装 Java 时会安装 Keytool。

NOTE: Save/backup this keystore because once you publish an app on play by signing it with this keystore, you will have to use the same keystore for any future updates.注意:保存/备份此密钥库,因为一旦您通过使用此密钥库对其进行签名来发布应用程序,您将必须使用相同的密钥库进行任何未来的更新。 So, it's important that you back it up.所以,备份它很重要。

HTH. HTH。

Read this my answer here在这里阅读我的答案

How do I export a project in the Android studio? 如何在 Android Studio 中导出项目?

This will guide you step by step to generate signed APK and how to create keystore file from Android Studio.这将指导您逐步生成签名的 APK 以及如何从 Android Studio 创建密钥库文件。

From the link you can do it easily as I added the screenshot of it step by step.从链接中,您可以轻松完成,因为我逐步添加了它的屏幕截图。

Short answer简短的回答

If you have Key-store file then you can do same simply.如果你有密钥库文件,那么你可以简单地做同样的事情。

Go to Build then click on Generate Signed APK转到 Build 然后单击 Generate Signed APK

The "official" way to configure the build.gradle file as recommended by Google is explained here . 此处解释了 Google 推荐的配置 build.gradle 文件的“官方”方式。

Basically, you add a signingConfig , in where you specify the location an password of the keystore.基本上,您添加一个signingConfig ,在其中指定密钥库的密码位置。 Then, in the release build type, refer to that signing configuration.然后,在发布构建类型中,参考该签名配置。

...
android {
    ...
    defaultConfig { ... }
    signingConfigs {
        release {
            storeFile file("myreleasekey.keystore")
            storePassword "password"
            keyAlias "MyReleaseKey"
            keyPassword "password"
        }
    }
    buildTypes {
        release {
            ...
            signingConfig signingConfigs.release
        }
    }
}
...
  1. Go to Build -> Generate Signed APK in Android Studio.在 Android Studio 中转到Build -> Generate Signed APK
  2. In the new window appeared, click on Create new... button.在出现的新窗口中,单击Create new...按钮。
  3. Next enter details as like shown below and click OK -> Next .接下来输入如下所示的详细信息,然后单击OK -> Next 在此处输入图像描述
  4. Select the Build Type as release and click Finish button.选择构建类型作为发布,然后单击完成按钮。
  5. Wait until APK generated successfully message is displayed as like shown below.等待直到显示APK 生成成功消息,如下图所示。 在此处输入图像描述
  6. Click on Show in Explorer to see the signed APK file.单击在资源管理器中显示以查看签名的 APK 文件。

For more details go to this link.有关更多详细信息,请访问 链接。

Simple 5 visual steps:简单的 5 个视觉步骤:

Step 1: Click Build -> Generate Signed Build/APK第 1 步:点击 Build -> Generate Signed Build/APK

建造

Step 2: Choose APK -> Next第 2 步:选择 APK -> 下一步APK

Step 3: Click Create new ...第三步:点击Create new ... 创建新的 ...

Step 4: Fill necessary details第 4 步:填写必要的详细信息充满

⚠️ Important Note: Make sure to store this keystore file safely, because same keystore file will be required for consecutive store upload. ⚠️ 重要提示:请务必安全存储此密钥库文件,因为连续上传存储库需要相同的密钥库文件。

Step 5: Choose build variant debug/release & Signature Versions (V2)第 5 步:选择构建变体debug/release和签名版本 (V2) 在此处输入图像描述

All done, now your Signed APK will start building and should popup on bottom right corner once available.一切都完成了,现在您的签名 APK 将开始构建,并且一旦可用,应该会在右下角弹出。 Click locate to get your signed APK file.单击locate以获取您签名的 APK 文件。

Easy?简单的?

I had the same problem.我有同样的问题。 I populated the field with /home/tim/android.jks file from tutorial thinking that file would be created.我用教程中的 /home/tim/android.jks 文件填充了该字段,认为该文件将被创建。 and when i would click enter it would say cant find the file.当我点击输入时,它会说找不到文件。 but when i would try to create the file, it would not let me create the jks file.但是当我尝试创建文件时,它不会让我创建 jks 文件。 I closed out of android studio and ran it again and it worked fine.我关闭了 android studio 并再次运行它,它工作正常。 I had to hit the ... to correctly add my file.我必须点击 ... 才能正确添加我的文件。 generate signed apk wizard-->new key store-->hit ... choose key store file.生成签名的apk向导->新密钥库->点击...选择密钥库文件。 enter filename I was thinking i was going to have to use openjdk and create my own keyfile, but it is built into android studio输入文件名我在想我将不得不使用 openjdk 并创建自己的密钥文件,但它内置于 android studio

you can add this to your build gradel您可以将其添加到您的构建等级中

android {
    ...
    defaultConfig { ... }
    signingConfigs {
        release {
            storeFile file("my.keystore")
            storePassword "password"
            keyAlias "MyReleaseKey"
            keyPassword "password"
        }
    }
    buildTypes {
        release {
            ...
            signingConfig signingConfigs.release
        }
    }
}

if you then need a keyHash do like this via android stdio terminal on project root folder如果你然后需要一个 keyHash 通过项目根文件夹上的 android stdio 终端执行这样的操作

keytool -exportcert -alias my.keystore -keystore app/my.keystore.jks | openssl sha1 -binary | openssl base64

Note : If its a React Native project注意:如果它是一个 React Native 项目

If you open the root project folder in Android Studio, you wont see the options suggested in other answers in this page.如果您在 Android Studio 中打开根项目文件夹,您将不会在此页面的其他答案中看到建议的选项。

在此处输入图像描述

Solution解决方案

Instead of the root folder I opened the packages/native/android folder.我没有打开根文件夹,而是打开了packages/native/android文件夹。 Then only I could see the options to build signed APK.然后只有我可以看到构建签名 APK 的选项。

https://i.stack.imgur.com/k8Elg.png

Official Android Documentation on the matter at hand with a step-by-step guide included on how to generate signed APK keys in Android Studio and even on how to setup the automatic APK key generation in a Gradle build.手头的官方 Android 文档,其中包括如何在 Android Studio 中生成签名的 APK 密钥,甚至如何在 Gradle 构建中设置自动 APK 密钥生成的分步指南。

https://developer.android.com/studio/publish/app-signing.html https://developer.android.com/studio/publish/app-signing.html

Look under the chapter: Sign your release build查看章节:签署您的发布版本

Dialog is slightly confusing when it asks for a Key Store Path.对话框在询问密钥存储路径时会有些混乱。 But this is actually where it will create Keystore.但这实际上是它将创建 Keystore 的地方。 The label can be " save key store at : "标签可以是“将密钥存储在:

Comments inline.内联评论。

在此处输入图像描述

However, you can add more than one key to the same Keystore.但是,您可以向同一个 Keystore 添加多个密钥。 In that case, you may also choose an existing Keystore.在这种情况下,您还可以选择现有的 Keystore。

Please NOTE that Google Playstore makes it quite difficult to change signing keys after the first release.请注意,Google Playstore 在首次发布后很难更改签名密钥。 So make sure you choose a location that is safe and can be remembered.因此,请确保选择一个安全且易于记忆的位置。 Note down location and password details somewhere.在某处记下位置和密码详细信息。

  1. Generate a signed APK file, open the Build menu from the toolbar and select Generate Signed Bundle/APK .生成签名的 APK 文件,从工具栏打开 Build 菜单,然后 select Generate Signed Bundle/APK 在此处输入图像描述
  2. Select between creating an Android App Bundle and APK file. Select 在创建Android App BundleAPK文件之间。 在此处输入图像描述
  3. Enter Key store path , Key store password , Key alias , and the Key password.输入密钥库路径密钥库密码密钥别名密钥密码。 在此处输入图像描述
  4. if you're creating a Signed APK file in first time, you will have to create a new key store Click Create new.. below of Key store path .如果您是第一次创建签名的 APK 文件,则必须创建一个新的密钥库点击Key store path下方的Create new..。 在此处输入图像描述
  5. Enter all information like Path, Password, Confirm password, Alias Name, Password, Confirm,First name last name,Organization unit,Organization name, Country code, City, State .输入所有信息,如路径、密码、确认密码、别名、密码、确认、名字姓氏、组织单位、组织名称、国家代码、城市、State 在此处输入图像描述
  6. You have filled in the details for the certificate, select OK and Then, select Next .您已经填写了证书的详细信息, select OK然后, select Next
  7. You will now be able to see the destination of your Signed APK file.您现在将能够看到您的签名 APK 文件的目的地。 Below that, you will see two more options: Debug and Release .在此之下,您将看到另外两个选项: DebugRelease 在此处输入图像描述
  8. There are two more checkboxes towards the bottom of the screen.屏幕底部还有两个复选框。 Select V2 (Full APK Signature) and click Finish . Select V2(完整的 APK 签名)并单击Finish

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM