[uni-app][Android studio] Teach you step by step how to run the uniapp project into Android App

Run into Android App Dock

  • Select Run to Android App Dock
    Insert image description here
  • Select the running project
    1. Connect the mobile phone and choose to transfer files on the mobile phone.
    Insert image description here
    2. Open 设置-> 关于本机-> 版本信息-> Click 4-5 times in succession 版本号 , enter your phone password, and the system will enter developer mode.
    Insert image description here
    3. 设置> 其他设置> 开发者选项> Open 开发者选项> Open USB调试.
    4. Return to Hbuilder, click Refresh, select the device, and run the project.
    Insert image description here
  • Failed to run.
    请使用手机助手手动安装XXX.apk到手机上,并重新运行真机调试
    I don’t know why the files can’t be transferred to the phone. Even after downloading the file assistant, I can’t connect to the phone. So use the simplest method.
    This error is because Hbuilder cannot send and install the apk to the mobile phone. Open the directory it says C:\Users\[自己的目录]\Downloads\HBuilderX.3.7.11.20230427\HBuilderX\plugins\launcher\base\android_base.apk, directly send the apk to the mobile phone via WeChat, then manually change the name, click Install, and this icon will appear after installation.
    Insert image description here
    After installation, return to the computer Hbuilder and run it again.
    Error occurred:
    Failed to connect to localhost/127.0.0.1:8080
    Turn off HBuilder on mobile phone, recompile on computer, just try twice more.

Run into emulator

  • Download and install Android Studio. The official uni-app provides a download address and installation tutorial. I will talk about something the official does not explain in detail here. After downloading, just click down by default during installation. After installing studio.
    遇到的问题
    1. Click on SDK Manager and find that there is no SDK Platform. Follow this tutorial , it's really detailed.
    Insert image description here
    2. Modify the SDK directory, and then the installation fails. It does not report an error, it means that the package already exists, so the existing package is used. After seeing this comment, I modified the path and moved it one level up.
    Insert image description here
    3. Failed to download the package: Because I have "technology" support, the agent here chooses Auto-detect. You can try it Check connection. From the details downloaded later, you can see that https://dl.google.comthe installation package is downloaded from, so just use this URL to test. If this test is successful, it means that there is no problem with the subsequent installation network.
    Insert image description here
    The following log must appear to indicate that it has been installed 成功, otherwise you will not be able to select the sdk platform and sdk tools when you click finish.
    Insert image description here
    Just follow the detailed tutorial above and continue. God knows how long I tried before I finally succeeded. A handful of bitter tears.Insert image description here
  • Android native project configuration. You can refer to the uni-app tutorial , which is recommended as 方式二:导入工程the bread is already placed. I will mainly explain some details not mentioned here and the problems I encountered.
    1. This HBuilder-Integrate-AS project is in the downloaded App offline SDK. aaptOptions has been placed in build.gradle. Insert image description hereInsert image description here
    2. Androidmanifest.xmlUnder manifeststhe directory, labels have been placed meta-data. Just change the value.
    Insert image description here
    Insert image description here
  • Apply for a signed appkey
    1. Open the Developer Center , 应用管理> 我的应用> click Application to view application information. Click Android云端证书, if it has not been generated, click Generate Certificate. After the click is generated , the // information 证书详情is recorded . 2. Click , the original one has been migrated. Click to add platform information. Fill in the SHA and MD5 information recorded previously, and the package name is that of the Android studio project . 3. After adding it, move to the end of the table and you can see that the table has one column . If it has not been generated before, click Create and there will be a pop-up window. Anyway, just click Create. After it's done, this will turn into View. Click View to see the App Key, which is the offline key. Put this in AndroidManifest.xml in the project.MD5SHA1SHA256
    Insert image description here
    Insert image description here
    各平台信息离线打包Key管理新增applicationId
    Insert image description here
    Insert image description here
    离线打包Key
    Insert image description here

    Insert image description here
    Insert image description here

issued

Hbuilder select 发行> 原生App-云打包
The cloud certificate here is the one previously generated in Dcloud.
Insert image description here
There will be a pop-up prompt in the middle:
打包校验:[Warning] 为落实《网络安全法》《消费者权益保护法》的要求,有效治理App强制授权、过度索权、超范围收集个人信息等现象,保障个人信息安全国内各大应用市场都加强了应用审核,要求应用必须符合相关政策才能上架查看如何解决。不上架国内应用市场无需处理
Insert image description here
If this is just to verify the effect of the apk, you can continue to package it first, but if you want to put it on the domestic application market, you have to go to the provided (link) [https://uniapp.dcloud.net.cn/tutorial/ Configure the relevant privacy statements in app-privacy-android.html#].

After packaging, there will be a prompt. Just transfer the apk file to your phone and run it to see the effect.
Insert image description here

Error: java.net.SocketTimeoutException: Connect timed out

Android studio proxy settings, check connection as long as you can connect to https://dl.google.com.

The following is my program:

Reference:
Common errors reported when running on official real machines

Guess you like

Origin blog.csdn.net/jjs15259655776/article/details/132072816