基于uni-app的andiord 离线打包
开发工具及所需要的夹包
首先说明本文打包只是一个简单示范并未涉及 用户权限以及第三方集成如 、微信等具体请参考官网uni-app 离线打包
1.确认HBuilderX版本 3.2.9

2.打开 andriod studio———创建空白页




3.将下载的SDK中的libs—-拷贝到项目中的libs


4.配置src —- main下的静态资源
1.创建 assets
2.在 assets — 创建data并导入 dcloud_control.xml — dcloud_error.html — dcloud_properties.xml
三个文件位置也是在我们下载的SDK中

导入结果

3.创建HBuilderX打包后资源并引入

将会生成我们需要的静态文件目录

然后拷贝放在创建的 apps文件夹中

5.配置data — dcloud_control.xml文件
dcloud_control.xml 中的 中的 appid 内容与 apps下的文件名保持一致

6.app下的 build.gradle配置,需要注意的和完整依赖包都将贴下

2.注意dependencies中的配置分为 AndroidX版本 和 support版本我们创建的是 AndroidX版本,官网下载的版本升级说明中说替换的的必须包为 support版本 列如:

完整代码如下:
plugins {
id 'com.android.application' } android {
compileSdk 30 buildToolsVersion '30.0.2' compileSdkVersion 30 defaultConfig {
applicationId "com.fosun.testapplication" minSdk 21 targetSdk 30 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes {
release {
minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } //使用uniapp时,需复制下面代码 /*代码开始*/ aaptOptions {
additionalParameters '--auto-add-overlay' //noCompress 'foo', 'bar' ignoreAssetsPattern "!.svn:!.git:.*:!CVS:!thumbs.db:!picasa.ini:!*.scc:*~" } lintOptions {
checkReleaseBuilds false abortOnError false } /*代码结束*/ compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } dependenciesInfo {
includeInApk true includeInBundle true } } dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs') implementation fileTree(include: ['*.aar'], dir: 'libs') implementation 'androidx.appcompat:appcompat:1.0.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.recyclerview:recyclerview:1.0.0' implementation 'com.facebook.fresco:fresco:2.5.0' implementation "com.facebook.fresco:animated-gif:2.5.0" implementation 'com.github.bumptech.glide:glide:4.9.0' implementation 'com.alibaba:fastjson:1.1.46.android' implementation 'com.google.android.material:material:1.3.0' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' testImplementation 'junit:junit:4.+' androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' implementation 'com.squareup.okhttp:okhttp:2.3.0' implementation 'com.squareup.okhttp:okhttp-ws:2.3.0' implementation 'com.alibaba:fastjson:1.1.46.android' implementation 'com.facebook.fresco:fresco:1.13.0' implementation "com.facebook.fresco:animated-gif:1.13.0" }
7.配置AndroidManifest.xml

剩下和官网配置一样,完整代码如下
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.fosun.testapplication"> <application android:name="io.dcloud.application.DCloudApplication" android:allowClearUserData="true" android:icon="@drawable/icon" android:label="@string/app_name" tools:replace="android:name" android:largeHeap="true" > <!-- <activity--> <!-- android:name=".MainActivity"--> <!-- android:exported="true">--> <!-- <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|smallestScreenSize|screenLayout|screenSize" 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.fosun.testapplication.dc.fileprovider" android:exported="false" android:grantUriPermissions="true"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/dcloud_file_provider" /> </provider> <meta-data android:name="dcloud_appkey" android:value="AppKey" /> </application> </manifest>
配置到这里上面可能爆红一片了,这里不要慌更新一下所需依赖配置

这里我们配置文件基本配置完成了,下面打包配置




打包完成我们将会在目录中多了一个 release文件夹,此时将会有一个安装包

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/216904.html原文链接:https://javaforall.net
