1、使用 Android Studio 創(chuàng)建一個(gè) 工程
createApplition1.png
createApplition2.png
createApplition3.png
2、刪除 原生工程中 JAVA 目錄下系統(tǒng)默認(rèn)創(chuàng)建的源代碼
deleteCode.png
3、復(fù)制SDK->libs->lib.5plus.base-release.aar文件到原生工程工程的app->libs目錄下
C1CD7CCB-9830-4db7-814A-613E15B87EB9.png
copyJarPackage.png
4、打開(kāi)工程的build.gradle文件
- 4.1 添加aar文件引用到dependenciesr如下代碼
compile(name: 'lib.5plus.base-release', ext: 'aar')
- 4.2 添加aar文件搜索路徑添到gradle文件呵恢,與dependencies同級(jí), 代碼如下
flatDir{
dirs 'libs'
}
build.gradle 文件
apply plugin: 'com.android.application'
android {
lintOptions {
checkReleaseBuilds false
abortOnError false
}
compileSdkVersion 26
defaultConfig {
applicationId "com.example.rh.test"
minSdkVersion 16
// targetSdkVersion 26
targetSdkVersion 21
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'])
compile(name: 'lib.5plus.base-release', ext: 'aar') // 添加的代碼
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
// 注釋掉 這三個(gè) 測(cè)試 的 包
//testImplementation 'junit:junit:4.12'
//androidTestImplementation 'com.android.support.test:runner:1.0.2'
//androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
B96523E9-0377-4c76-B889-86D88303E545.png
- 4.3 修改工程的
targetSdkVersion
為21
ee95ad142db4c9323e792fd42fff04e1.png
- 4.4
multiDexEnabled
設(shè)置成 false (我這里 創(chuàng)建的工程 默認(rèn)為 false)
3067AD98-F60F-4ab4-B571-BE0045468E11.png
5、打開(kāi)工程的Androidmanifest.xml
文件,復(fù)制以下內(nèi)容替換該文件中原有application
節(jié)點(diǎn)下的內(nèi)容
<application
android:name="io.dcloud.application.DCloudApplication"
android:allowClearUserData="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:largeHeap="true"
>
<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>
</application>
替換后的 Androidmanifest.xml
文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.rh.test">
<!--<application-->
<!--android:allowBackup="true"-->
<!--android:icon="@mipmap/ic_launcher"-->
<!--android:label="@string/app_name"-->
<!--android:roundIcon="@mipmap/ic_launcher_round"-->
<!--android:supportsRtl="true"-->
<!--android:theme="@style/AppTheme">-->
<!--<activity android:name=".MainActivity">-->
<!--<intent-filter>-->
<!--<action android:name="android.intent.action.MAIN" />-->
<!--<category android:name="android.intent.category.LAUNCHER" />-->
<!--</intent-filter>-->
<!--</activity>-->
<!--</application>-->
<application
android:name="io.dcloud.application.DCloudApplication"
android:allowClearUserData="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:largeHeap="true"
>
<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>
</application>
</manifest>
6 在app->src->res->drable目錄下放應(yīng)用的圖標(biāo)文件文件命名為 icon.png
c509a94c23fd573340e0ad1a8a30d78a.png
845291BA-064B-4e3e-8220-50B6385B63A9.png
7媚创、 復(fù)制SDK->assets->data目錄和目錄下的文件到工程的src->main->assets目錄下渗钉,新創(chuàng)建的工程默認(rèn)沒(méi)有assets目錄,可在與java同級(jí)目錄下創(chuàng)建assets目錄
7B3CA942-A8FD-4193-AD61-42BA00CE1790.png
B49E8D9A-D4CC-48cc-AB7F-2B147F8CFFED.png
8钞钙、 Assets目錄下創(chuàng)建apps目錄鳄橘,復(fù)制應(yīng)用資源到apps目錄下。 注意: 應(yīng)用資源的路徑為[appid]->www, appid為應(yīng)用資源manifest.json文件中id節(jié)點(diǎn)的值
- 8.1 HBuilder X 創(chuàng)建項(xiàng)目 生成本地打包資源
59BA30E0-CD82-4e9a-8BE7-530C1C7AA300.png
- 8.2 將生成的打包資源 拷貝到 工程的 assets/apps 目錄下
D433E987-7397-463b-95E8-A22530177E6D.png