This article is aimed at uniAPP project which can carry out cloud packaging!
The preparatory work
- Uniapp projects;
- HBuilderX;
- Android Studio (android-studio 2020.3.1.24-windows.exe);
- SDK (version needs to be the same as HBuilderX version);
- Various permissions, key, appID, package name, alias, key password, certificate, SHA1, etc.;
The SDK directory
Download address: nativesupport.dcloud.net.cn/AppDocs/dow…
| - HBuilder - | - HBuilder Hello App offline packaging demo application - both - AS the simplest example of integrated uni - App SDK library file directory | | - SDK - Feature - Android. XLS Android platform details of the corresponding expansion Feature API | -- Readme. TXT release notes documents and matters needing attention | - UniPlugin - Hello - AS uni native plug-in development exampleCopy the code
Hbuilder-integrate-as is mainly used
1. Generate local packaged APP resources
HBuilderX menu: Publish = “Native APP local package =” Generate local package APP resources; The generated resources are used later
Two, prepare the project
- the
HBuilder-Integrate-AS
Copy to project folder; - Open Android Studio and create a new blank project and select No Activity.
- Turn off the firewall of each domain on your computer, otherwise you will not be able to download Gradle later, or manually download Gradle.
- Click Import Project in the upper right corner to Import what you just copied
HBuilder-Integrate-AS
; - Select the language when configuring the project
JAVA
The App offline SDK does not support Kotlin. Minimum API Level 21 or above - Waiting to download various dependency packages (process in the lower right corner);
- The upper left corner
Android
Switch to aProject
(Below);
3. Configure various files
Refer to the official documentation: nativesupport.dcloud.net.cn/AppDocs/use…
- Can put the
simpleDemo
Change to app, but change the names (global search);
- Put the resources packaged in step 1 into
\app\src\main\assets\apps
Within; - the
\app\src\main\assets\data
的dcloud_control.xml
Change your appID to your own; - the
\app\src\main\res\drawable
PNG and splash.9. PNG and splash. - the
\app\src\main\res\values\strings.xml
Change the app name to your own, which will be displayed on the phone desktop; Focus on
Modify the file\app\src\main\AndroidManifest.xml
Change the package attribute of the manifest node to the package name of your project. Change ${apk. ApplicationId} to the package name of your project; Search for dcloud_appkey and change the value of the next line to the appkey generated by the dcloud developer background;Copy the code
Add permission: before the application node, alongside the application node:
Such as: <uses-permission (manifest. Json) <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>Copy the code
If there is autonavi location, you need to configure autonavi key :(same as the node where dcloud_appkey is configured)
<meta-data android:name="com.amap.api.v2.apikey" android:value= android:name="com.amap.api.location.APSService" />Copy the code
At the same time, copy the SDK file related to map in the SDK directory into the project from the downloaded SDK:
- configuration
build.gradle
, in app(simpleDemo) directory:
DefaultConfig: applicationId Package name versionCode Version number Code versionName Version number signingConfigs: configures information about the certificateCopy the code
If you want to configure the name of the packaged package, you can search applicationaro.all for the latest configuration method.
4. Compile errors and other problems (handle these before compiling)
- Error compiling:
License for Package Android SDK build-tools 29.0.2 Not accepted
;
The reason is that the SDK version of HBuilder is not the same; Solution: Menu file= “setting=”, select, download SDK, application, confirm step by step;2. Compilation error:.android/repositories.cfg could not be loaded
; Solution: Go to the file directory,C:\Users\xxx\.android\
Run the command:touch ~/.android/repositories.cfg
Five, pack apK
- Click on the green hammer in the upper right to Make Project build package;
- After compiling successfully (make sure no errors are reported), click the upper left menu
Build => Generate Singed Bundle or APK
, select APK, next select the certificate and fill in the certificate information, tick “Remember password”, next select Release and wait for the packaging to complete; - The generated APK is in the app(simpleDemo) release directory.