HbuilderX 發布 android


這里是官網教程:https://nativesupport.dcloud.net.cn/AppDocs/usesdk/android

總體來說是按照上面做,但是上面有一些問題。

下面我梳理一下整個步驟。

 

一,准備工具

  1. Android Studio 下載地址:Android Studio官網 OR Android Studio中文社區
  2. HBuilderX
  3. App離線SDK下載:最新android平台SDK下載



二,AS新建工程

打開Android studio新建一個空白項目

 

 

選擇 Empty Activity 點擊 Next。

 

 

Minimum API Level 建議選19及以上

Package name作為應用標志,涉及申請第三方平台賬號,一般情況下不建議修改,包名一般設置反向域名,如:io.dcloud.HBuilder

點擊 Finish 完成創建。

注意:App離線SDK不支持Kotlin

 

三,導入工程

① 步驟一中App離線SDK中文件

將lib.5plus.base-release.aar、android-gif-drawable-release@1.2.17.aar和miit_mdid_1.0.10.aar(HBuilderX2.8.1之后更新到msa_mdid_1.0.13.aar)拷貝到libs目錄下

 

 

② 在build.gradle文件如下

PS:修改自己的applicationId

 

apply plugin: 'com.android.application'

android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.tyler.myapplication"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}


dependencies {
implementation fileTree(dir: 'libs', include: ['*.aar', '*.jar'], exclude: [])
implementation 'com.github.bumptech.glide:glide:4.9.0' // 基座依賴
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.alibaba:fastjson:1.1.46.android'
implementation 'androidx.appcompat:appcompat:1.0.0-alpha1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
}

 


③ 配置應用名稱

打開app->res -> main -> values -> strings.xml文件,修改“app_name”字段值,該值為安裝到手機上桌面顯示的應用名稱,建議與manifest.json中name(基礎配置中的應用名稱)對應。

我是默認

<resources>
<string name="app_name">My Application</string>
</resources>

 


④ 配置應用啟動項

Androidmanifest.xml 文件如下

PS:android:appComponentFactory如果為"",會報錯:Empty class name in package 。。。。。。

tools:replace="android:appComponentFactory"也是必要的

<?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.example.tyler.myapplication">

<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"
android:appComponentFactory="ty"
tools:replace="android:appComponentFactory"
>
<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>
</application>

</manifest>

 


⑤ 配置應用圖標和啟動界面

PS:這一步,我跳過了。使用了創建項目后的自帶圖片

圖標名稱

icon.png為應用的圖標。

push.png為推送消息的圖標。

splash.png為應用啟動頁的圖標。

將icon.png、push.png、splash.png放置到drawable,drawalbe-ldpi,drawable-mdpi,drawable-hdpi,drawable-xhdpi,drawable-xxhdpi文件夾下,不同文件夾下對應不同圖片尺寸,可參考文檔

 

 

⑥ 修改Androidmanifest.xml中application節點的icon屬性為@drawable/icon。如下圖:

PS:這步,我同樣跳過了

 

 

⑦ 資源配置

將步驟一SDK中的assets 整個拷貝到main下

 

 

⑧ 創建apps文件夾並拷貝資源

將HBuilderX中的項目導出,將導出的資源復制到assets->apps下,如下圖所示:

 PS:這里分2步,

第一步,HBuilderX發行

第二步,將發行目錄復制到assets下

 

I HBuilderX發行

PS:如果報錯:該項目的AppID所有者不是當前登錄的賬號,請重新用正確的賬號登錄或者在該項目的manifest.json中重新獲取

那么:需要修改一下AppID(我是在原有的AppID后面,繼續添加了自己的英文名)

 

 發行:

 

 

完成后,顯示如下並點擊轉到文件夾

然后從resources,復制自己的文件夾(我的是xxxx.tyler,里面有一個www文件夾的)

 

II  將發行目錄復制到assets下

放到AS中的apps下(apps,自己新建即可)

 

 

修改dcloud_control.xml中的appid。與manifest.json的一樣。

並且hbuilder中添加屬性:debug="true" syncDebug="true"

PS:如果App啟動出現:當前應用運行在自定義調試基座。。。。。

則改為:debug="false" syncDebug="false"

 

 

三,修改配置

① gradle-wrapper.properties

PS:也可以自己下載,瀏覽器輸入https://services.gradle.org/distributions/gradle-4.6-all.zip

解壓后,修改AS的gradle路徑

 

修改 distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip

 

 

 ② 修改外層的build.gradle

 

 

dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'


// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}

 

四,運行

PS:如果報錯:INSTALL_FAILED_ABORTED: User rejected permissions

那么開啟USB調試模式,並且關閉監控ADB安裝應用

 

 

效果:




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM