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

二.本地打包:本地打包相對比較麻煩,官網也做了詳細介紹,但是感覺不太精簡,設定一大堆,看起來也不清晰,所以我在這邊大致整理了一下(uni-app安卓打包方式),大致分為底下幾個步驟,
- 需要用到的軟體:
Android Studio 下載地址:Android Studio官網 OR Android Studio中文社區
App離線SDK下載:最新android平臺SDK下載 - 打包步驟
-
在 HBuilder 上選擇發行 -> 原生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節點
將下面的代碼添加到Androidmanifest.xml的application節點中(如果存在MainActivity的節點,必須刪掉!) -
將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節點必須添加-->
<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節點必須添加-->
<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底下創建檔案夾,main -> assets -> apps,將打包的檔案放入apps檔案夾下,將下載的SDK -> assets -> data檔案夾拷貝到 main -> assets檔案夾下

- 修改dcloud_control.xml檔案


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

轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/229894.html
標籤:其他
