uni-app is packaged into an apk file

Signature preparation:

1. Generate a signature - Requirements: configure the java environment, and the jdk version cannot be too high, otherwise the MD5 fingerprint cannot be viewed

1.找到jdk->bin目录,打开cmd窗口
2.运行生成证书命令,注意:记住定义的别名,之后会配置
keytool -genkey -alias 你定义的别名 -keyalg RSA -keysize 2048 -validity 36500 -keystore 名字.keystore
3.填写密码,姓名,等等
示例:
密码:xxxxx
姓名:xx
组织单位:xx
组织名称:xx
城市:dl
省/市/自治区:ln
国家:china
是否确定:y
之后会提示输入密钥,回车默认和原先一样就行
4.查看签名文件中的MD5,SHA1,SHA256证书指纹,注意:记录好,之后会用到
keytool -list -v -keystore 名字.keystore
4.找到jdk->bin目录下生成的签名文件,xxx.keystore,注意:记住位置,之后会用到
修改别名
keytool -changealias -keystore xxx.keystore -alias 当前别名 -destalias 修改后的别名
按提示输入xxx.keystore密码后修改成功。

uniapp developer center preparation

2. Go to the developer center on the uniapp official website to apply for an appId

Developer Center URL:

https://dev.dcloud.net.cn/pages/app/detail/info

3. Developer Center -> Application Management -> My Apps -> Create App

Please add a picture description

应用类型:uni-app
应用名称:自定义

4. Return to My Apps -> Click on the blue link App Name -> Offline Packaging Key Management -> Add

配置内容:
所属平台:Android App
版本:按需选择,我选择了正式版
包名:示例:com.xx.xxApp
Android 应用签名SHA1值: 复制签名证书的
Android 应用签名MD5: 复制签名证书的
Android 应用签名SHA256: 复制签名证书的
然后点击提交即可

5. After submitting, generate an offline packaging Key, and remember the App Key and appid in it

Please add a picture description

HbuilderX ready

Hbuilder下载地址:
https://www.dcloud.io/hbuilderx.html

6. Open HbuilderX, open the project, and modify the appid of manifest.json to be consistent with the application

Please add a picture description

7. HbuiderX->Publish->Native app-local packaging->Generate local packaged app resources

Please add a picture description

Extra: HBuilderX1.9.0 and above versions add the following configuration to avoid pop-up prompt box

"app-plus": {  
    "compatible": {  
        "ignoreVersion": true //true表示忽略版本检查提示框,HBuilderX1.9.0及以上版本支持  
    },  
//....  
},  

Android studio environment preparation

Android Studio 下载地址:
Android Studio官网:
https://developer.android.google.cn/studio/index.html
Android Studio中文社区
http://www.android-studio.org/

8. Download the App offline SDK, and unzip the file after downloading

App离线SDK下载:最新android平台SDK下载:
https://nativesupport.dcloud.net.cn/AppDocs/download/android.html#

9. Use Android studio to open the HBuilder-Integrate-AS in the decompressed file. Note: the decompressed location cannot have a Chinese path, otherwise Android studio cannot open it

10. Delete all files under HBuilder-Integrate-AS->simpleDemo->src->mian->assets->apps

11. Copy the packaged file of HbuilderX to the apps in the above path, note: all the contents of the folder starting with UNI include the UNI folder

12. Modify the appid in dcloud_control.xml under HBuilder-Integrate-AS->simpleDemo->src->mian->assets->data, pay attention to the appid, it must be consistent with the project packaged by HBuilderX

<hbuilder>
<apps>
    <app appid="修改为开发者中心申请的appid" appver=""/>
</apps>
</hbuilder>

Please add a picture description

13. Open AndroidMainifest.xml under HBuilder-Integrate-AS->simpleDemo->src->mian

<meta-data
            android:name="dcloud_appkey"
            android:value="此处修改为开发者中心申请的appKey" />

Please add a picture description

14. Put the previously generated signature under HBuilder-Integrate-AS->simpleDemo

Please add a picture description

15. Open build.grade under HBuilder-Integrate-AS->simpleDemo

1. Modify defaultConfig

defaultConfig {
    applicationId "修改为开发者中心填写的包路径"
    minSdkVersion 21
    targetSdkVersion 28
    versionCode 1(与HbuilderX中mainifiest.json里versionCode一致)
    versionName "1.0"(与HbuilderX中mainifiest.json里versionName一致)
    multiDexEnabled true
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

2. Modify signingConfigs

    signingConfigs {
        config {
            keyAlias '签名文件的别名'
            keyPassword '签名文件的密码'
            storeFile file('test.keystore(签名文件名称)')
            storePassword '签名文件si的密码'
            v1SigningEnabled true
            v2SigningEnabled true
        }
    }

~ Extra articles in Android studio: 1. Solve the problem that dependencies cannot be pulled, 2. Debugging problems on real devices

1. Solve the problem that dependencies cannot be pulled

如果是第一次安装Android studio,下面下载的SDK可能依赖拉取不下来,导致无法进行打包
  1. Create a new project with Android studio
  2. Phone And Table default, click next
  3. Language select java Other modification as needed

Please add a picture description

  1. In the newly created project, copy build.gradle and setting.gradle under My Application
    insert image description here

  2. Overwrite our build.gradle and setting.gradle in our previous HBuilder-Integrate-AS project
    insert image description here

2. Real machine debugging problem

​ 1.Android studio->file->setting->Appearance & Behavior->System Settings->Android SDK

SDK Platforms测试机的安卓版本所需选择
SDK Tools除了默认的,还得选择Google USB Driver

Please add a picture description

2. After installing the Android SDK configuration, the system environment variable configuration, the path is as follows:

C:\Users\Administrator\AppData\Local\Android\Sdk\platform-tools

3. Connect the data cable to the mobile phone and turn on the developer mode of the mobile phone at the same time

4. Open the device manager, find the portable device, find the test machine, right click and select change driver
insert image description here

5. Select Browse my computer to find driver software, select the following path directory

C:\Users\Administrator\AppData\Local\Android\Sdk\extras\google\usb_driver

16. Package apk

1.Android studio->Build->Generate Signed Bundle / APK…

Please add a picture description

2. Select APK in the pop-up box, and then select Next

3. Configure the signature file

Key store path中选择Choose existing....,然后选中HBuilder-Integrate-AS->simpleDemo下的签名文件
Key store password: 签名文件的密码
Key alias: 签名文件的别名
Keyt password: 签名文件的密码(与上面一致)

Please add a picture description

4. After the configuration is complete, the next step is to select release, and finally Finish to package it into apk

5. Package file address

解压的SDK目录下:
[email protected]_20221122\HBuilder-Integrate-AS\simpleDemo\release

Guess you like

Origin blog.csdn.net/qq_45158026/article/details/128202417