将MUI放到原生Android中运行

【1】.在Android Studio中新建一个Android项目
【2】.下载安卓离线SDK包
网址:https://nativesupport.dcloud.net.cn/AppDocs/download/android
在这里插入图片描述
【3】.HBuilderX生成本地打包资源
注册HBuilder账号,登录后打开manifest.json,获取ID
在这里插入图片描述
然后点击 发行 —> 原生App-本地打包 —> 生成本地打包App资源
在这里插入图片描述
打包成功后如下图
在这里插入图片描述
【4】.配置调试Android运行环境
1.在之前下载好的SDK目录
[email protected]_20200528\SDK\libs)
下找到
lib.5plus.base-release.aar
[email protected]
miit_mdid_1.0.10.aar
三个文件并复制到app - libs目录下
在这里插入图片描述
2.在Android的main目录下新建assets文件夹,并在assets目录下新建apps和data两个目录

2.在目录
[email protected]_20200528\SDK\assets
下找到data文件夹
在这里插入图片描述
将文件粘贴到上一步建好的data目录下
在这里插入图片描述
3.在之前HBuilder打包好的目录下(unpackage\resources),将APPID下的所有文件复制到apps中
在这里插入图片描述
4.点击build.grade,下滑到底部
在这里插入图片描述
引用资源

implementation fileTree(dir: 'libs', include: ['*.aar', '*.jar'], exclude: [])
implementation 'com.github.bumptech.glide:glide:4.9.0' // 基座依赖
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.alibaba:fastjson:1.1.46.android'

在这里插入图片描述
点击左上角 Sync Now 进行资源同步

5.自此资源引入完成,进行下一步strings.xml操作。

在app→src→main→res→ values配置strings.xml文件,修改应用名称,与刚刚引入本地打包资源的里的manifest.json文件(assets>apps>“应用id名文件夹”>www下)修改一致

string.xml
在这里插入图片描述

manifest.json

在这里插入图片描述

6.在app→src→main下配置AndroidManifest.xml文件
在这里插入图片描述
注释掉原有的activity,输入如下内容

		<activity
            android:name="io.dcloud.PandoraEntry"
            android:configChanges="orientation|keyboardHidden|keyboard|navigation"
            android:hardwareAccelerated="true"
            android:label="@string/app_name"
            android:launchMode="singleTask"
            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>

        <activity
            android:name="io.dcloud.PandoraEntryActivity"
            android:configChanges="orientation|keyboardHidden|screenSize|mcc|mnc|fontScale|keyboard"
            android:hardwareAccelerated="true"
            android:launchMode="singleTask"
            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>

在这里插入图片描述
7.将assets下apps文件夹中的manifest.json文件和data文件夹中的dcloud_control.xml文件打开,确保manifest.json中的id和dcloud_control.xml中的appid一致。
在这里插入图片描述

在这里插入图片描述
至此,配置完成,可以运行

猜你喜欢

转载自blog.csdn.net/weixin_42547014/article/details/106473991