uniapp打包安卓App的兩種方式(云打包、本地打包)方法詳解
在HBuilder上對APP提供了兩種打包方式,云打包和本地打包,下面主要對這兩種打包方式做個介紹
兩者的區(qū)別:云打包相對簡單,但是每天最多只能打包五次,而且在高峰期打包時間可能會很長,本地打包相對比較復雜,但是不限制次數,打包時間也短
一. uniapp云打包安卓App:
只需要設置相應參數即可。比較復雜的地方可能就是證書,如果你是測試包,Android的話直接選擇共用證書即可,ios則需要申請相應證書,申請證書的具體方法官方也介紹的很清楚了,就不贅述了。

二. uniapp本地打包安卓App:
本地打包相對比較麻煩,官網也做了詳細介紹,但是感覺不太精簡,設置一大堆,看起來也不清晰,所以我在這邊大致整理了一下(uni-app安卓打包方式),大致分為底下幾個步驟。
需要用到的軟件:
Android Studio 下載地址:Android Studio官網 OR Android Studio中文社區(qū)
App離線SDK下載:最新android平臺SDK下載
打包步驟
在 HBuilder 上選擇發(fā)行 -> 原生App-本地打包 -> 生成本地App打包資源,會在項目里生成一個unpackage的文件夾

打開Android studio新建一個空白項目

因為會自己生成默認屬性,Minimum API Level也會選擇最新的,所以一路next,Finish就行了
將lib.5plus.base-release.aar、android-gif-drawable-release@1.2.17.aar、uniapp-v8-release.aar和miit_mdid_1.0.13.aar拷貝到libs目錄下(這幾個包的地址:你下載的App離線SDK -> SDK -> libs)
注意:HBuilderX2.8.0以前需要將uniapp-v8-release.aar替換為uniapp-release.aar

配置build.gradle


配置應用名稱
打開app->src -> main -> values -> strings.xml文件,修改“app_name”字段值,該值為安裝到手機上桌面顯示的應用名稱,建議與manifest.json中name(基礎配置中的應用名稱)對應。

配置應用啟動頁以及provider節(jié)點
將下面的代碼添加到Androidmanifest.xml的application節(jié)點中(如果存在MainActivity的節(jié)點,必須刪掉?。?/p>
將icon.png(圖標)、ic_launcher.png(應用啟動頁圖片)放置到drawable,drawalbe-ldpi,drawable-mdpi,drawable-hdpi,drawable-xhdpi,drawable-xxhdpi文件夾下,不同文件夾下對應不同圖片尺寸,(這兩個圖片名字隨意起,與配置處對應即可)
<activity
android:name="io.dcloud.PandoraEntryActivity"
android:launchMode="singleTask"
android:configChanges="orientation|keyboardHidden|screenSize|mcc|mnc|fontScale|keyboard"
android:hardwareAccelerated="true"
android:permission="com.miui.securitycenter.permission.AppPermissionsEditor"
android:screenOrientation="user"
android:theme="@style/DCloudTheme"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<action android:name="android.intent.action.VIEW" />
<data android:scheme="h56131bcf" />
</intent-filter>
</activity>
<!--provider節(jié)點必須添加-->
<provider
android:name="io.dcloud.common.util.DCloud_FileProvider"
android:authorities="com.example.myapplication.dc.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/dcloud_file_provider" />
</provider>
配置后的圖片以及屬性內容

我這邊完整的AndroidManifest.xml文件(僅供參考)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapplication">
<application
android:allowBackup="true"
android:icon="@mipmap/icon"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MyApplication">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="io.dcloud.PandoraEntry"
android:configChanges="orientation|keyboardHidden|keyboard|navigation"
android:label="@string/app_name"
android:launchMode="singleTask"
android:hardwareAccelerated="true"
android:theme="@style/TranslucentTheme"
android:screenOrientation="user"
android:windowSoftInputMode="adjustResize" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="io.dcloud.PandoraEntryActivity"
android:launchMode="singleTask"
android:configChanges="orientation|keyboardHidden|screenSize|mcc|mnc|fontScale|keyboard"
android:hardwareAccelerated="true"
android:permission="com.miui.securitycenter.permission.AppPermissionsEditor"
android:screenOrientation="user"
android:theme="@style/DCloudTheme"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<action android:name="android.intent.action.VIEW" />
<data android:scheme="h56131bcf" />
</intent-filter>
</activity>
<!--provider節(jié)點必須添加-->
<provider
android:name="io.dcloud.common.util.DCloud_FileProvider"
android:authorities="com.example.myapplication.dc.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/dcloud_file_provider" />
</provider>
</application>
</manifest>
資源配置
在main底下創(chuàng)建文件夾,main -> assets -> apps,將打包的文件放入apps文件夾下,將下載的SDK -> assets -> data文件夾拷貝到 main -> assets文件夾下

修改dcloud_control.xml文件


最后連接手機,點擊運行按鈕即可

如果你想打一個APK的包出來,點擊Build -> Build Bundle(s)/APK()s -> Build APK(s)即可

控制臺會打印以下內容,看到successfully表示打包成功,點擊locate可直接跳轉打包好的APK存儲的位置

以上就是uniapp打包安卓App的兩種方式(云打包、本地打包)方法詳解的詳細內容,更多關于uniapp打包安卓App的兩種方式方法詳解的資料請關注腳本之家其它相關文章!
相關文章
uniApp微信小程序使用騰訊地圖定位功能及getLocation需要在app.json中聲明permission字段問
這篇文章主要介紹了uniApp微信小程序使用騰訊地圖定位功能及getLocation需要在app.json中聲明permission字段問題解決,需要的朋友可以參考下2022-12-12

