当前位置: 首页 > news >正文

(二)Flutter插件之Android插件开发

1、打开Android插件项目

在这里插入图片描述

2、Android插件报红处理

在build.gradle 中加入外在最外层即可

//获取local.properties配置文件
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {localPropertiesFile.withReader('UTF-8') { reader ->localProperties.load(reader)}
}
//获取flutter的sdk路径
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}dependencies {compileOnly files("$flutterRoot/bin/cache/artifacts/engine/android-arm/flutter.jar")testImplementation files("$flutterRoot/bin/cache/artifacts/engine/android-arm/flutter.jar")
}

在这里插入图片描述

3、Android插件 如何开发与验证(把Android插件改成独立的项目)

Android的单元测试是满足不了的
Flutter 插件(android/ 只是插件模块),现在希望让它变成 独立的 Android 应用,可以直接运行和调试。

将 apply plugin: ‘com.android.library’ 改成:apply plugin: ‘com.android.application’

    apply plugin: 'com.android.application'defaultConfig {applicationId = "com.example.my_plugin_app"minSdk = 24targetSdk = 34versionCode = 1versionName = "1.0"}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"package="com.example.plugin.my_flutter_plugin"><applicationandroid:label="MyPluginApp"android:icon="@mipmap/ic_launcher"><activity android:name=".MainActivity"android:exported="true"><intent-filter><action android:name="android.intent.action.MAIN"/><category android:name="android.intent.category.LAUNCHER"/></intent-filter></activity></application></manifest>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:gravity="center"android:layout_width="match_parent"android:layout_height="match_parent"><TextViewandroid:text="Hello from converted plugin!"android:layout_width="wrap_content"android:layout_height="wrap_content"/>
</LinearLayout>
package com.example.plugin.my_flutter_plugin
import android.app.Activity
import android.os.Bundle
import com.example.plugin.my_flutter_plugin.bean.JsMsgBean
import com.example.plugin.my_flutter_plugin.dispatcher.JsActionDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launchclass MainActivity : Activity() {override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.activity_main)CoroutineScope(Dispatchers.Default).launch {if (JsActionDispatcher.hasStrategy("canOpenUrl")) {JsActionDispatcher.dispatch(this@MainActivity, this,JsMsgBean("canOpenUrl", {})) {runOnUiThread {// 回调结果处理println("插件调用结果: $it")}}}}}
}

gradle.properties 支持androidx

android.useAndroidX=true
android.experimental.DEX_ALIGNMENT_16KB_PAGE=true

4、写插件中的主要方法

5、第四部无误之后,把对应代码复制到插件当中

http://www.dtcms.com/a/512611.html

相关文章:

  • 贵港seo关键词整站优化ps如何做psd模板下载网站
  • 雄安做网站优化的公司企业官方网站的作用
  • 中国建设行业峰会官方网站营销公司有哪些
  • 用wireshark进行手机app抓包教程-2025最新
  • 建设网站应注意什么河北提供网站建设公司电话
  • Ubuntu22.04-Cuda12.1 安装 Detectron2
  • STM32电池管理系统(BMS):电量统计原理与实现
  • 海外免费网站推广有哪些wordpress编辑器 插件
  • Java 黑马程序员学习笔记(进阶篇20)
  • Google 推荐 ViewBinding 作为 DataBinding 的轻量级替代
  • AI体测设备哪家口碑好
  • 阿里云 企业 网站城市介绍网站模板
  • 株洲网站建设团队萧山区建设工程质量监督站网站
  • 【CTF | 比赛篇】Newstar ctf web
  • MySQL decimal类型+IN查询异常:为何非目标数据被检出?
  • 浙江荣盛建设集团网站wordpress自动排版
  • 网站界面设计工具怎样申请电子邮箱
  • 构建AI智能体:七十、小树成林,聚沙成塔:随机森林与大模型的协同进化
  • 好用的外贸网站深圳网络推广培训学校
  • 第5章—STM32工程创建
  • 网站建设公司宣传标语用百度地图 做gis网站
  • c 还可以做网站微信推广是什么意思
  • 代码随想录 112.路径总和
  • 51单片机基础-定时器中断
  • xtuoj 两个数
  • Android Studio新手开发第二十六天
  • 中国平安网站建设成都网站建设易维达好
  • 继保:对于线路两侧的电流互感器型号系数选取
  • Redis分布式集群:从分区算法到扩容实战
  • AI大模型:(二)1.6 DeepSeek-OCR部署尝鲜