This article is aimed at uniAPP project which can carry out cloud packaging!

The preparatory work

  1. Uniapp projects;
  2. HBuilderX;
  3. Android Studio (android-studio 2020.3.1.24-windows.exe);
  4. SDK (version needs to be the same as HBuilderX version);
  5. 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

  1. theHBuilder-Integrate-ASCopy to project folder;
  2. Open Android Studio and create a new blank project and select No Activity.
  3. Turn off the firewall of each domain on your computer, otherwise you will not be able to download Gradle later, or manually download Gradle.
  4. Click Import Project in the upper right corner to Import what you just copiedHBuilder-Integrate-AS;
  5. Select the language when configuring the projectJAVAThe App offline SDK does not support Kotlin. Minimum API Level 21 or above
  6. Waiting to download various dependency packages (process in the lower right corner);
  7. The upper left cornerAndroidSwitch to aProject(Below);

3. Configure various files

Refer to the official documentation: nativesupport.dcloud.net.cn/AppDocs/use…

  1. Can put thesimpleDemoChange to app, but change the names (global search);

  1. Put the resources packaged in step 1 into\app\src\main\assets\appsWithin;
  2. the\app\src\main\assets\datadcloud_control.xmlChange your appID to your own;
  3. the\app\src\main\res\drawablePNG and splash.9. PNG and splash.
  4. the\app\src\main\res\values\strings.xmlChange the app name to your own, which will be displayed on the phone desktop;
  5. Focus onModify 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:

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

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

  1. Click on the green hammer in the upper right to Make Project build package;
  2. After compiling successfully (make sure no errors are reported), click the upper left menuBuild => 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;
  3. The generated APK is in the app(simpleDemo) release directory.