mui使用 android studio 编译器离线打包

需求:将HBulider中mui的代码通过android studio进行打包生成apk
(之前查看官方帖子没看太懂,搜索其他帖子也没有实现,最后通过帖子内容结合官方示例的程序解决)

下载5+ SDK(http://ask.dcloud.net.cn/article/103)

使用Android Studio新建项目在这里插入图片描述
在这里插入图片描述
新建项目后引入5+SDK
(在下载的sdk文件夹中,找到 “lib.5plus.base-release.aar” ,将其拷入libs文件夹下)
在这里插入图片描述
打开项目app目录下的build.gradle文件,将aar包添加引用,加入如下代码:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    
    implementation fileTree(dir: 'libs', include: ['*.aar'])
    
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

修改build.gradle文件中工程的targetSdkVersion大于等于21

defaultConfig {
   applicationId "com.example.qualityapp"
   minSdkVersion 21
   targetSdkVersion 29
   versionCode 1
   versionName "1.0"
   testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

打开工程的Androidmanifest.xml文件,复制以下内容替换该文件中原有application节点下的内容

<application
        android:name="io.dcloud.application.DCloudApplication"
        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/Theme.AppCompat.Light.NoActionBar">
        <!-- 启动页 -->
        <activity
            android:name="io.dcloud.PandoraEntry"
            android:configChanges="orientation|keyboardHidden|screenSize|mcc|mnc|fontScale"
            android:hardwareAccelerated="true"
            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: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="h533c3d68" />
            </intent-filter>
        </activity>
    </application>

若自定义application,可采取继承DCloudApplication,添加tools:replace="android:name"至application节点下,避免merge冲突。另中的 “h533c3d68” 要和下方所述注意事项中的appid变量一致

新创建的工程默认没有assets目录,可在与java同级目录下创建assets目录。复制SDK中项目目录下的assets->data目录和目录下的文件到工程的src->main->assets目录下
在这里插入图片描述
将HBuilder里的代码进行本地打包,将应用资源打包进入Android项目的assets->apps对应目录下,HBuilder点击发行->原生App-本地打包->生成本地打包App资源,将路径选择到assets->apps即可。
在这里插入图片描述

注 :apps 目录下,由HBulider打包生成的资源文件夹的名称,需要和data->dcloud_control.xml文件中的appid的变量以及mui项目manifest.json里的appid完全一致!

在这里插入图片描述
接下来运行或者进行打包即可。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值