Mui本地打包筆記(一)使用AndroidStudio運行項目 轉載 https://blog.csdn.net/baidu_32377671/article/details/79632411

轉載 http://www.javashuo.com/article/p-uzsfxuph-ey.htmlhtml

使用AndroidStudio運行HBuilder本地打包的Mui項目
Mui官網
5+SDK下載地址
官網的AndroidStudio打包說明
離線打包說明(包括引入aar包的圖文教程)
  我這裏使用SDK的是18年3月19日發佈的版本,因此配置上與官網上的說明有些出入。這裏我先建立Android原生項目,並配置好SDK和manifest再使用HBuilder建立移動App項目並將其打包到Android原生項目的assets文件夾中。android

一、使用AndroidStudio建立原生項目並導入SDK
  下載SDK後,將SDK/libs目錄中的lib.5plus.base-release.aar,導入到項目工程的libs目錄中,大體以下圖所示:json

  接下來就是導入aar包,這個比普通jar包的引入特殊一點,須要在build.gradle配置文件中加點料。添加的位置以下圖所示:app

  app包下的build.gradle完整配置代碼以下(配置完了別忘了Sync Now一下):gradle

apply plugin: 'com.android.application'ui

android {
compileSdkVersion 26
defaultConfig {
applicationId "com.lyan.apktest"
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:0.5'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2'
implementation(name: 'lib.5plus.base-release', ext: 'aar')
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
二、配置manifest配置文件
  這一步主要設置一下Application和啓動頁,這裏的配置主要參考官方的AS工程示例。我試着建立一個類繼承DCloudApplication,而後在manifest中配置這個DCloudApplication的子類,但發現這樣根本行不通。因此仍是老老實實的按照官方的配置說明進行設置,manifest的完整配置以下所示:.net

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.lyan.apktest">插件

<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:resizeable="true"
android:smallScreens="true" />
<!-- 使用的權限 -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />orm

<application
android:name="io.dcloud.application.DCloudApplication"
android:allowClearUserData="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"
android:roundIcon="@mipmap/ic_launcher_round">
<!-- 啓動頁 -->
<activity
android:name="io.dcloud.PandoraEntry"
android:configChanges="orientation|keyboardHidden|screenSize|mcc|mnc|fontScale"
android:hardwareAccelerated="true"
android:screenOrientation="user"
android:theme="@style/TranslucentTheme"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
三、使用HBuilder建立移動App項目並配置manifest.json
  建立項目(項目名隨意最好使用英文命名,中文我沒試過),這裏就往index.html中加了一個「Hello」字符串,省着項目運行後顯示個空白。項目建立完以下圖所示:xml

  接下來配置一下manifest.json這個文件,這裏我爲了方便就將appid設置成了我原生項目的包名(這裏記一下版本號和appid,以後會在設置dcloud_control.xml時用到)。效果圖以下:


四、使用HBuilder進行本地打包
  本地打包操做以下圖所示:

  選中以後會彈出一個彈窗,在這個彈窗中設置咱們項目要打包到的位置,這裏我就直接將項目打包到Android原生項目的assets/apps目錄下(※必定要放到apps目錄下)。目錄配置以下:

  打包完原生項目assets中的目錄結構以下圖所示:


五、配置dcloud_control.xml文件
  將下載的SDK中的data目錄複製到原生項目中的assets目錄中,操做以下所示:

  配置dcloud_control.xml文件中的appid和版本名稱。配置以下圖所示:


六、運行項目
  正常的運行項目,跟之前運行原生項目同樣。

  項目運行結果,以下圖所示:


#後續文章#

Mui本地打包筆記(二)集成第三方SDK(以百度地圖爲例)Mui本地打包筆記(三)Android動態申請權限的問題(以獲取地理位置信息爲例)Mui本地打包筆記(四)Android自定義插件的配置(以動態申請權限爲例)--------------------- 做者:lyanjun 來源:CSDN 原文:https://blog.csdn.net/baidu_32377671/article/details/79632411 版權聲明:本文爲博主原創文章,轉載請附上博文連接!

相關文章
相關標籤/搜索