前提条件
Android Studio(最新版)的 mPaaS 插件版本升级到 3.0.230524 及以上。
Android Studio 打开 Flutter 工程中的 android 目录作为 gradle 项目,并使用 mPaaS 插件进行接入。
设置环境
在 Flutter 项目中使用 mPaaS 插件,请参考 将 mPaaS 添加到您的项目中。
设置 project 的
build.gradle
文件。apply plugin: 'com.alipay.apollo.optimize' buildscript { ext.mpaas_artifact = "mpaas-baseline" ext.mpaas_baseline = "10.2.3-21" ext.kotlin_version = '1.6.10' repositories { google() mavenCentral() maven { url 'https://mvn.cloud.alipay.com/nexus/content/repositories/releases/' name 'alipay' credentials { username 'mvn_read_ws' password 'mrk8929' } } } dependencies { classpath 'com.android.tools.build:gradle:7.1.3' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath 'com.android.boost.easyconfig:easyconfig:2.8.0' } } allprojects { repositories { google() mavenCentral() maven { url 'https://mvn.cloud.alipay.com/nexus/content/repositories/releases/' name 'alipay' credentials { username 'mvn_read_ws' password 'mrk8929' } } } }
设置 module 的
build.gradle
文件。dependencies { implementation platform("com.mpaas.android:$mpaas_artifact:$mpaas_baseline") implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation 'androidx.constraintlayout:constraintlayout:2.0.4' implementation 'com.mpaas.android:cdp' implementation 'com.mpaas.android:push' implementation 'com.mpaas.android:logging' implementation 'com.mpaas.android:lbs' implementation 'com.mpaas.android:media' //uc内核 implementation 'com.mpaas.android:uccore' //容器 implementation 'com.mpaas.android:nebula' //小程序 implementation 'com.mpaas.android:tinyapp' implementation("androidx.multidex:multidex:2.0.1") }
在
AndroidManifest.xml
添加如下配置。<meta-data android:name="com.mpaas.cdp.autoInit" android:value="true" />
初始化 mPaaS
package com.example.mpaas_demo
import android.content.Context
import android.util.Log
import androidx.multidex.MultiDex
import com.alipay.mobile.framework.quinoxless.QuinoxlessFramework
import com.alipay.mobile.nebula.provider.H5AppCenterPresetProvider
import com.alipay.mobile.nebula.util.H5Utils
import com.mpaas.mas.adapter.api.MPLogger
import com.mpaas.nebula.adapter.api.MPTinyHelper
import com.mpaas.tinyappcommonres.TinyAppCenterPresetProvider
import io.flutter.app.FlutterApplication
class MyApplication : FlutterApplication() {
override fun attachBaseContext(base: Context) {
super.attachBaseContext(base)
Log.i("Android", "MyApplication attachBaseContext")
MultiDex.install(this)
QuinoxlessFramework.setup(this) {
// 初始化小程序公共资源包
H5Utils.setProvider(
H5AppCenterPresetProvider::class.java.name,
TinyAppCenterPresetProvider()
)
//设置虚拟域名
val tinyHelper = MPTinyHelper.getInstance()
tinyHelper.setTinyAppVHost("mpaas.com")
//设置白名单
MPLogger.setUserId("mPaaSTest")
}
}
override fun onCreate() {
super.onCreate()
Log.i("Android", "MyApplication onCreate")
QuinoxlessFramework.init()
}
}