需求:一直都是使用HBuilder-Hello的模板进行离线打包,今天摸索了一下如何从0开始进行离线打包,并且实验成果。
记录一下过程。
第一步:使用android studio新建一个工程,删除java下面的内容
步骤二:新建assets文件夹如下图:新建apps文件夹和data文件夹
步骤三:拷贝androidsdk里面的Android-SDK@2.6.11.80110_20200410\SDK\assets 里面的文件到data里面
步骤四:修改manifests内容,如下图,直接拷贝
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.uniapppack">
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:resizeable="true"
android:smallScreens="true" />
<application
android:name="io.dcloud.application.DCloudApplication"
android:allowBackup="true"
android:allowClearUserData="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:largeHeap="true"
android:debuggable="true"
android:supportsRtl="true">
<!-- 应用入口 -->
<activity
android:name="io.dcloud.PandoraEntry"
android:theme="@style/TranslucentTheme"
android:configChanges="orientation|keyboardHidden|screenSize|mcc|mnc|fontScale"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<data android:scheme="hbuilder"/>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>
<intent-filter>
<data android:mimeType="image/*"/>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<meta-data android:name="dcloud_uninview_background"
android:value="true"/>
<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>
</application>
</manifest>
步骤五:修改build.gradel的内容,如下图
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "com.example.uniapppack"
minSdkVersion 16
targetSdkVersion 28
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:*~"
}
/*代码结束*/
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation fileTree(dir: 'libs', include: ['*.aar'])
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
implementation "com.android.support:support-v4:28.0.0"
implementation "com.android.support:appcompat-v7:28.0.0"
/*uniapp所需库-----------------------开始*/
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.facebook.fresco:fresco:1.13.0'
implementation "com.facebook.fresco:animated-gif:1.13.0"
/*uniapp所需库-----------------------结束*/
// 基座需要,必须添加
implementation 'com.github.bumptech.glide:glide:4.9.0'
implementation 'com.alibaba:fastjson:1.1.46.android'
}
步骤六:拷贝HBuilder X打包的文件,到assets---》apps下面
步骤七:修改 assets-->data-->dcloud_control.xml
第八步:还需要在libs文件夹下面拷贝3个动态库如下:
第九步:如果有插件,还需要配置插件以及把插件拷贝到libs下面
第十步:就成功了。这个就是从0开始 手把手搭建一个uniapp的混合编译环境