Uni-app offline packaging apk
1. Android Studio download
2. HBuilderX download
3. App offline SDK download
-
After downloading, unzip the file and renameHBuilder-Integrate-ASbuild-template a> and copy it to a folder specially used for packaging as a packaging template
-
There is a simpleDemo folder in this folder
-
Right now
build-template\simpleDemo\src\main\assets\apps
-
Delete the contents of the apps folder
-
Run HbuilderX
-
Choose to generate local packaged APP resources
-
After packaging is completed, the console will prompt the following content
-
Find the packaged resource directory and copy the folder below to the folder specially used for packaging, namelybuild-template\simpleDemo\src\main\assets\apps under the folder
-
4. Apply for Appkey
-
Install the JRE environment (JRE8 environment is recommended, you can skip it if you already have one)
-
You can download the jre installation package from Oracle official:
-
It is recommended to add the JRE installation path to the system environment variables
-
Use the keytool -genkey command to generate a certificate:
-
cmd Enter the following command to switch to the D drive
d:
keytool -genkey -alias testalias -keyalg RSA -keysize 2048 -validity 36500 -keystore test.keystore
- testalias is the certificate alias, which can be modified to the characters you want to set. It is recommended to use English letters and numbers.
- test.keystore is the name of the certificate file. It can be modified to the file name you want to set, or you can specify the complete file path.
- 36500 is the validity period of the certificate, which means 100 years of validity, in days. It is recommended to set the time longer to avoid certificate expiration.
-
After pressing Enter, you will be prompted:
Enter keystore password: //输入证书文件密码,输入完成回车 Re-enter new password: //再次输入证书文件密码,输入完成回车 What is your first and last name? [Unknown]: //输入名字和姓氏,输入完成回车 What is the name of your organizational unit? [Unknown]: //输入组织单位名称,输入完成回车 What is the name of your organization? [Unknown]: //输入组织名称,输入完成回车 What is the name of your City or Locality? [Unknown]: //输入城市或区域名称,输入完成回车 What is the name of your State or Province? [Unknown]: //输入省/市/自治区名称,输入完成回车 What is the two-letter country code for this unit? [Unknown]: //输入国家/地区代号(两个字母),中国为CN,输入完成回车 Is CN=XX, OU=XX, O=XX, L=XX, ST=XX, C=XX correct? [no]: //确认上面输入的内容是否正确,输入y,回车 Enter key password for <testalias> (RETURN if same as keystore password): //确认证书密码与证书文件密码一样(HBuilder|HBuilderX要求这两个密码一致),直接回车就可以
-
After the above command is completed, the certificate will be generated, and the path is "D:\test.keystore"
-
-
View certificate information
Run cmd under D drive
keytool -list -v -keystore test.keystore Enter keystore password: //输入密码,回车
The following format information will be output:
Only SHA1 and SHA256, but also requires an MD5
-
At this time, you need to download a openssl software and add it to the environment variable
-
After the installation is complete, execute the following command to see the output md5
keytool -exportcert -keystore xxx.keystore | openssl dgst -md5
-
-
-
Record the SHA1 SHA256 MD5 generated above
-
Login Developer Center
-
Create and view offline AppKey in Application Management - Click Application - Platform Information:
- Enter the corresponding SHA1 SHA256 MD5 when creating
5. Configure Android Studio
-
build.gradle configuration
signingConfigs { config { keyAlias '签名别名' keyPassword '签名密码' storeFile file('xxx/xxx/xxx.keystore或xxx/xxx/xxx.jks') // 路劲为相对路径或绝对路径 storePassword '证书文件密码' v1SigningEnabled true //兼容v1 v2SigningEnabled true //兼容v2 } } buildTypes { debug { signingConfig signingConfigs.config ... } release { signingConfig signingConfigs.config ... } }
-
Note: The signature information needs to be consistent with the background. Inconsistency will also cause the appkey verification to fail.
- The signature alias is the alias required when generating a certificate using the keytool tool, which is the testalias above.
- The certificate signing password is the certificate password required when generating a certificate using the keytool tool.
- Certificate file password is the certificate file password that is required when using the keytool tool to generate a certificate (press enter in that step, the certificate password is the same as the certificate file password)
- storeFile is the location of the generated keystore file
-
Androidmanifest.xml configuration
-
After obtaining the AppKey of the android platform! Open the Android project, configure the Androidmanifest.xml file of the main APP, find the meta-data node, the name is dcloud_appkey, and the value is the applied AppKey as follows:
<application ...> <meta-data android:name="dcloud_appkey" android:value="替换为自己申请的Appkey" />
-
Find the data directory under the assets directory
- Set the appid in dcloud_control.xml to the appid when applying for AppKey
- Set applicationId in build.gradle to the package name when applying for AppKey
- Set the appid in dcloud_control.xml to the appid when applying for AppKey
-
-
Set application name
-
Edit strings.xml in the values directory under the res directory
-
Set to the name of the application
-
-
settings icon
- In the drawable directory in the res directory
- icon.png : logo picture
- push.png: message push logo
- splash.png: splash page
- In the drawable directory in the res directory
-
Set version number
6. Packing
After packaging is completed, you can view the packaged apk file in build-template\simpleDemo\release
End of full text