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

石家庄网站建设推广服务郑州全网营销

石家庄网站建设推广服务,郑州全网营销,做海外市场什么网站推广,在哪个网站找水利工地做Android AGP8.1.0组件化初探 前言#xff1a; 前面两篇完成了从AGP4.2到 AGP8.1.0的升级#xff0c;本文是由于有哥们留言说在AGP8.0中使用ARouter组件化有问题#xff0c;于是趁休息时间尝试了一下#xff0c;写了几个demo#xff0c;发现都没有问题#xff0c;跳转和传…Android AGP8.1.0组件化初探 前言 前面两篇完成了从AGP4.2到 AGP8.1.0的升级本文是由于有哥们留言说在AGP8.0中使用ARouter组件化有问题于是趁休息时间尝试了一下写了几个demo发现都没有问题跳转和传值都是正常的这里我也是直接从groovy转换成version-catalogs的依赖方式由于之前升级过所以这次很顺利几分钟就完成了直接上代码 1.添加统一依赖: [versions] agp 8.1.0 androidx-espresso-core 3.4.0 androidx-junit 1.1.3 org-jetbrains-kotlin-android 1.8.0 core-ktx 1.10.1 junit 4.13.2 androidx-test-ext-junit 1.1.5 espresso-core 3.5.1 appcompat 1.6.1 material 1.9.0 constraintlayout 2.1.4 mmkv 1.3.1 utilcodex 1.31.1 arouter 1.5.2 arouter-compiler 1.5.2 org-jetbrains-kotlin-kapt 1.8.0[libraries] androidx-espresso-core-3_4_0 { module androidx.test.espresso:espresso-core, version.ref androidx-espresso-core } androidx-junit-1_1_3 { module androidx.test.ext:junit, version.ref androidx-junit } core-ktx { group androidx.core, name core-ktx, version.ref core-ktx } junit { group junit, name junit, version.ref junit } androidx-test-ext-junit { group androidx.test.ext, name junit, version.ref androidx-test-ext-junit } espresso-core { group androidx.test.espresso, name espresso-core, version.ref espresso-core } appcompat { group androidx.appcompat, name appcompat, version.ref appcompat } material { group com.google.android.material, name material, version.ref material } constraintlayout { group androidx.constraintlayout, name constraintlayout, version.ref constraintlayout } mmkv { group com.tencent, name mmkv, version.ref mmkv } utilcodex {group com.blankj,name utilcodex,version.ref utilcodex} arouter {group com.alibaba,name arouter-api,version.ref arouter} arouter-compiler {group com.alibaba,name arouter-compiler,version.ref arouter-compiler}[plugins] com-android-library { id com.android.library, version.ref agp } com-android-application { id com.android.application, version.ref agp } org-jetbrains-kotlin-android { id org.jetbrains.kotlin.android, version.ref org-jetbrains-kotlin-android } org-jetbrains-kotlin-kapt {id org.jetbrains.kotlin.kapt,version.ref org-jetbrains-kotlin-kapt}[bundles]2.添加lib-common组件配置: Suppress(DSL_SCOPE_VIOLATION) plugins {alias(libs.plugins.com.android.library)alias(libs.plugins.org.jetbrains.kotlin.android)alias(libs.plugins.org.jetbrains.kotlin.kapt) } dependencies {implementation(libs.core.ktx)implementation(libs.appcompat)implementation(libs.material)implementation(libs.arouter)kapt(libs.arouter.compiler)testImplementation(libs.junit)androidTestImplementation(libs.androidx.test.ext.junit)androidTestImplementation(libs.espresso.core) }kapt {arguments {arg(AROUTER_MODULE_NAME, project.name)} }完整配置 Suppress(DSL_SCOPE_VIOLATION) plugins {alias(libs.plugins.com.android.library)alias(libs.plugins.org.jetbrains.kotlin.android)alias(libs.plugins.org.jetbrains.kotlin.kapt) }android {namespace com.example.lib_cmmoncompileSdk 33defaultConfig {//applicationId com.example.lib_cmmonminSdk 23targetSdk 33// versionCode 1// versionName 1.0testInstrumentationRunner androidx.test.runner.AndroidJUnitRunner}buildTypes {release {isMinifyEnabled falseproguardFiles(getDefaultProguardFile(proguard-android-optimize.txt),proguard-rules.pro)}}compileOptions {sourceCompatibility JavaVersion.VERSION_17targetCompatibility JavaVersion.VERSION_17}kotlinOptions {jvmTarget 17} }dependencies {implementation(libs.core.ktx)implementation(libs.appcompat)implementation(libs.material)implementation(libs.arouter)kapt(libs.arouter.compiler)testImplementation(libs.junit)androidTestImplementation(libs.androidx.test.ext.junit)androidTestImplementation(libs.espresso.core) }kapt {arguments {arg(AROUTER_MODULE_NAME, project.name)} }3.lib-common添加ARouter初始化 /*** author: njb* date: 2023/8/26 22:21* desc:*/ public class BaseApp extends Application {Overridepublic void onCreate() {super.onCreate();initARouter();}private void initARouter() {ARouter.openDebug();ARouter.openLog();ARouter.init(this);} }4.添加lib-arouter组件配置 Suppress(DSL_SCOPE_VIOLATION) plugins {alias(libs.plugins.com.android.library)alias(libs.plugins.org.jetbrains.kotlin.android)alias(libs.plugins.org.jetbrains.kotlin.kapt) }android {namespace com.example.lib_aroutercompileSdk 33defaultConfig {// applicationId com.example.lib_arouterminSdk 23targetSdk 33//versionCode 1// versionName 1.0testInstrumentationRunner androidx.test.runner.AndroidJUnitRunner}buildTypes {release {isMinifyEnabled falseproguardFiles(getDefaultProguardFile(proguard-android-optimize.txt),proguard-rules.pro)}}compileOptions {sourceCompatibility JavaVersion.VERSION_17targetCompatibility JavaVersion.VERSION_17} }dependencies {implementation(libs.appcompat)implementation(libs.material)implementation(libs.constraintlayout)testImplementation(libs.junit)androidTestImplementation(libs.androidx.test.ext.junit)androidTestImplementation(libs.espresso.core)implementation(libs.arouter)kapt(libs.arouter.compiler)implementation(project(:lib-common)) }kapt {arguments {arg(AROUTER_MODULE_NAME, project.name)} }5.调用ARouter初始化: /*** author: njb* date: 2023/8/26 22:21* desc:*/ public class ARouterApp extends BaseApp {Overridepublic void onCreate() {super.onCreate();} }6.主模块依赖配置 Suppress(DSL_SCOPE_VIOLATION) plugins {alias(libs.plugins.com.android.application)alias(libs.plugins.org.jetbrains.kotlin.android)alias(libs.plugins.org.jetbrains.kotlin.kapt) }android {namespace com.example.writelogdemocompileSdk 33defaultConfig {applicationId com.example.writelogdemominSdk 23targetSdk 33versionCode 1versionName 1.0testInstrumentationRunner androidx.test.runner.AndroidJUnitRunner}buildTypes {release {isMinifyEnabled falseproguardFiles(getDefaultProguardFile(proguard-android-optimize.txt),proguard-rules.pro)}}compileOptions {sourceCompatibility JavaVersion.VERSION_17targetCompatibility JavaVersion.VERSION_17}kotlinOptions {jvmTarget 17} }dependencies {implementation(libs.core.ktx)implementation(libs.appcompat)implementation(libs.material)implementation(libs.constraintlayout)testImplementation(libs.junit)androidTestImplementation(libs.androidx.test.ext.junit)androidTestImplementation(libs.espresso.core)implementation(libs.utilcodex)implementation(libs.arouter)kapt(libs.arouter.compiler)implementation(project(:lib-arouter))implementation(project(:lib-common)) } 7.添加ARouter组件化配置: 7.1 引入ARouter依赖 这里我用的是catelog方式所以使用kapt方式 Suppress(DSL_SCOPE_VIOLATION) plugins {alias(libs.plugins.com.android.library)alias(libs.plugins.org.jetbrains.kotlin.android)alias(libs.plugins.org.jetbrains.kotlin.kapt) }implementation(libs.arouter) kapt(libs.arouter.compiler)7.2 添加模块名称配置 kapt {arguments {arg(AROUTER_MODULE_NAME, project.name)} }7.3 主模块ARouter初始化 /*** author: njb* date: 2023/8/25 22:36* desc:*/ public class LogApp extends BaseApp {private static LogApp mInstance;Overridepublic void onCreate() {super.onCreate();mInstance this;}public static LogApp getInstance() {return mInstance;} }7.4 在Activity中绑定Arouter ARouter.getInstance().inject(this)7.5 添加Arouter跳转和传值 userList arrayListOf(年龄18,John,身高180,体重60kg,性别female) tvText.setOnClickListener {ARouter.getInstance().build(/test/TestSplashActivity).withString(name,test张三).withSerializable(userList,userList).navigation()7.6 test模块添加跳转路径和数据接收: Route(path /test/TestSplashActivity) class TestSplashActivity : AppCompatActivity() {val TAG TestARouterAutowired(name name)JvmFieldvar name: String Autowired(name userList)JvmFieldvar mList:ArrayListString ? nulloverride fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.activity_test_splash)ARouter.getInstance().inject(this)initView()}private fun initView() {tvName.text 测试ARouter跳转$nametvTextView.text mList.toString()} }8.完整使用示例 package com.example.writelogdemoimport androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.widget.TextView import com.alibaba.android.arouter.launcher.ARouterclass MainActivity : AppCompatActivity() {private val tvText : TextView by lazy { findViewById(R.id.tvTest) }var userList:ArrayListString ? nulloverride fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.activity_main)ARouter.getInstance().inject(this)userList arrayListOf(年龄18,John,身高180,体重60kg,性别female)tvText.setOnClickListener {ARouter.getInstance().build(/test/TestSplashActivity).withString(name,test张三).withSerializable(userList,userList).navigation()}} }9.主模块布局 ?xml version1.0 encodingutf-8? androidx.constraintlayout.widget.ConstraintLayout xmlns:androidhttp://schemas.android.com/apk/res/androidxmlns:apphttp://schemas.android.com/apk/res-autoxmlns:toolshttp://schemas.android.com/toolsandroid:layout_widthmatch_parentandroid:layout_heightmatch_parenttools:context.MainActivityTextViewandroid:idid/tvTestandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:textHello World!app:layout_constraintBottom_toBottomOfparentapp:layout_constraintEnd_toEndOfparentapp:layout_constraintStart_toStartOfparentapp:layout_constraintTop_toTopOfparent //androidx.constraintlayout.widget.ConstraintLayout10.lib-arouter测试代码 package com.example.lib_arouterimport android.annotation.SuppressLint import android.os.Bundle import android.util.Log import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import com.alibaba.android.arouter.facade.annotation.Autowired import com.alibaba.android.arouter.facade.annotation.Route import com.alibaba.android.arouter.launcher.ARouterSuppressLint(CustomSplashScreen) Route(path /test/TestSplashActivity) class TestSplashActivity : AppCompatActivity() {val TAG TestARouterval tvName:TextView by lazy { findViewById(R.id.tv_name) }val tvTextView:TextView by lazy { findViewById(R.id.tv_test) }Autowired(name name)JvmFieldvar name: String Autowired(name userList)JvmFieldvar mList:ArrayListString ? nulloverride fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.activity_test_splash)ARouter.getInstance().inject(this)Log.d(TAG, 测试ARouter数据传递$name$mList)initView()}private fun initView() {tvName.text nametvTextView.text mList.toString()} }11.lib-arouter布局代码 ?xml version1.0 encodingutf-8? androidx.constraintlayout.widget.ConstraintLayout xmlns:androidhttp://schemas.android.com/apk/res/androidxmlns:apphttp://schemas.android.com/apk/res-autoxmlns:toolshttp://schemas.android.com/toolsandroid:layout_widthmatch_parentandroid:layout_heightmatch_parenttools:context.TestSplashActivityTextViewandroid:idid/tv_nameandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text这是Arouter测试app:layout_constraintBottom_toBottomOfparentapp:layout_constraintEnd_toEndOfparentapp:layout_constraintStart_toStartOfparentapp:layout_constraintTop_toTopOfparent /TextViewandroid:idid/tv_testandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_marginTop30dpandroid:text这是数组app:layout_constraintEnd_toEndOfparentapp:layout_constraintStart_toStartOfparentapp:layout_constraintTop_toBottomOfid/tv_name //androidx.constraintlayout.widget.ConstraintLayout12.日志打印如下 13.实现效果如下 14.遇到问题 14.1 测试模块配置不对 由于我是直接新建的模块所以当作完整项目配置的这里如果只是测试组件化需要修改配置 解决方法修改libs.plugins.com.android.application为libs.plugins.com.android.library 修改完成后可以正常运行 14.2 跳转时提示path找不到 解决方法 a.按照上面7中的步骤配置主模块和其他组件模块,一个都不能少。 ​b.同时在跳转时保证路径一致即可。 若配置完还有问题请仔细检查每一步直到正常跳转和数据传递本人是亲自尝试了多个项目基本上都没问题. 14.3 数据传递和接收问题 解决方法 a.在kotlin中使用ARouter接收数据时需要使用JvmField关键字 b.Autowired(name “name”)name一定要和传递时一致 c.传递数组时记得序列化接收也是一样 15.AGP8.1.0小技巧 15.1 在没有添加统一依赖时配置: implementation(androidx.appcompat:appcompat:1.6.1) implementation(com.google.android.material:material:1.9.0) implementation(androidx.constraintlayout:constraintlayout:2.1.4) testImplementation(junit:junit:4.13.2) androidTestImplementation(androidx.test.ext:junit:1.1.5) androidTestImplementation(androidx.test.espresso:espresso-core:3.5.1) implementation(com.alibaba:arouter-api:1.5.2) kapt(com.alibaba:arouter-compiler:1.5.2) implementation(project(:lib-common))15.2 添加统一依赖库配置后 如果添加了统一的catelog配置方式后导入依赖它会自动提示不需要开发者手动导入这点我感觉很爽一键一直替换用起来简直不要太安逸了感兴趣的同学可以自行尝试这里就简单举例。 16.总结 以上就是今天博客的内容在AGP8.1.0中使用组件化和遇到问题其实本文的目的不是在于如何使用ARouter这个很简单相信做过组件化的同学都会只是需要遇到问题时学会分析和调试要不然盲目猜测是不会有结果的。开发这条路任重而道远希望大家都能上下求索享受这个求索的过程痛并快乐着也很重要新技术出来可以尝试也可以根据自己需要调整不一样说非得更新用这个新技术只要能解决问题咋好用咋来。 17.demo地址如下: https://gitee.com/jackning_admin/write-log-demo
文章转载自:
http://www.morning.txgjx.cn.gov.cn.txgjx.cn
http://www.morning.wqsjx.cn.gov.cn.wqsjx.cn
http://www.morning.nmbbt.cn.gov.cn.nmbbt.cn
http://www.morning.jwlmm.cn.gov.cn.jwlmm.cn
http://www.morning.mjbkp.cn.gov.cn.mjbkp.cn
http://www.morning.lmhwm.cn.gov.cn.lmhwm.cn
http://www.morning.ltdrz.cn.gov.cn.ltdrz.cn
http://www.morning.pqqhl.cn.gov.cn.pqqhl.cn
http://www.morning.zdsqb.cn.gov.cn.zdsqb.cn
http://www.morning.pqwrg.cn.gov.cn.pqwrg.cn
http://www.morning.tmcmj.cn.gov.cn.tmcmj.cn
http://www.morning.zwpzy.cn.gov.cn.zwpzy.cn
http://www.morning.wpcfh.cn.gov.cn.wpcfh.cn
http://www.morning.mzydm.cn.gov.cn.mzydm.cn
http://www.morning.fxzw.cn.gov.cn.fxzw.cn
http://www.morning.ykmg.cn.gov.cn.ykmg.cn
http://www.morning.fdrwk.cn.gov.cn.fdrwk.cn
http://www.morning.yfzld.cn.gov.cn.yfzld.cn
http://www.morning.lbpqk.cn.gov.cn.lbpqk.cn
http://www.morning.zfyr.cn.gov.cn.zfyr.cn
http://www.morning.tqsmc.cn.gov.cn.tqsmc.cn
http://www.morning.wsgyq.cn.gov.cn.wsgyq.cn
http://www.morning.tbqdm.cn.gov.cn.tbqdm.cn
http://www.morning.tmsxn.cn.gov.cn.tmsxn.cn
http://www.morning.znknj.cn.gov.cn.znknj.cn
http://www.morning.bpwfr.cn.gov.cn.bpwfr.cn
http://www.morning.tldhq.cn.gov.cn.tldhq.cn
http://www.morning.flncd.cn.gov.cn.flncd.cn
http://www.morning.zqcdl.cn.gov.cn.zqcdl.cn
http://www.morning.kpfds.cn.gov.cn.kpfds.cn
http://www.morning.ktnmg.cn.gov.cn.ktnmg.cn
http://www.morning.ldhbs.cn.gov.cn.ldhbs.cn
http://www.morning.yfpnl.cn.gov.cn.yfpnl.cn
http://www.morning.krhkn.cn.gov.cn.krhkn.cn
http://www.morning.gkxyy.cn.gov.cn.gkxyy.cn
http://www.morning.zybdj.cn.gov.cn.zybdj.cn
http://www.morning.nrftd.cn.gov.cn.nrftd.cn
http://www.morning.tlbhq.cn.gov.cn.tlbhq.cn
http://www.morning.zffn.cn.gov.cn.zffn.cn
http://www.morning.gbjxj.cn.gov.cn.gbjxj.cn
http://www.morning.qzpw.cn.gov.cn.qzpw.cn
http://www.morning.qrqcr.cn.gov.cn.qrqcr.cn
http://www.morning.ymsdr.cn.gov.cn.ymsdr.cn
http://www.morning.gzgwn.cn.gov.cn.gzgwn.cn
http://www.morning.gmdtk.cn.gov.cn.gmdtk.cn
http://www.morning.rtryr.cn.gov.cn.rtryr.cn
http://www.morning.kzyr.cn.gov.cn.kzyr.cn
http://www.morning.hrzhg.cn.gov.cn.hrzhg.cn
http://www.morning.nfgbf.cn.gov.cn.nfgbf.cn
http://www.morning.chmcq.cn.gov.cn.chmcq.cn
http://www.morning.yfddl.cn.gov.cn.yfddl.cn
http://www.morning.rwls.cn.gov.cn.rwls.cn
http://www.morning.wtyqs.cn.gov.cn.wtyqs.cn
http://www.morning.qbccg.cn.gov.cn.qbccg.cn
http://www.morning.khxwp.cn.gov.cn.khxwp.cn
http://www.morning.dnqlba.cn.gov.cn.dnqlba.cn
http://www.morning.jllnh.cn.gov.cn.jllnh.cn
http://www.morning.qqnh.cn.gov.cn.qqnh.cn
http://www.morning.dgckn.cn.gov.cn.dgckn.cn
http://www.morning.ztmkg.cn.gov.cn.ztmkg.cn
http://www.morning.xhhzn.cn.gov.cn.xhhzn.cn
http://www.morning.qymqh.cn.gov.cn.qymqh.cn
http://www.morning.qhfdl.cn.gov.cn.qhfdl.cn
http://www.morning.ynwdk.cn.gov.cn.ynwdk.cn
http://www.morning.dnconr.cn.gov.cn.dnconr.cn
http://www.morning.gmplp.cn.gov.cn.gmplp.cn
http://www.morning.jlxqx.cn.gov.cn.jlxqx.cn
http://www.morning.lsjgh.cn.gov.cn.lsjgh.cn
http://www.morning.qstjr.cn.gov.cn.qstjr.cn
http://www.morning.rglp.cn.gov.cn.rglp.cn
http://www.morning.cjrmf.cn.gov.cn.cjrmf.cn
http://www.morning.zlcsz.cn.gov.cn.zlcsz.cn
http://www.morning.lwbhw.cn.gov.cn.lwbhw.cn
http://www.morning.btmwd.cn.gov.cn.btmwd.cn
http://www.morning.gfprf.cn.gov.cn.gfprf.cn
http://www.morning.kpxnz.cn.gov.cn.kpxnz.cn
http://www.morning.pqsys.cn.gov.cn.pqsys.cn
http://www.morning.rqhn.cn.gov.cn.rqhn.cn
http://www.morning.rhph.cn.gov.cn.rhph.cn
http://www.morning.lgwpm.cn.gov.cn.lgwpm.cn
http://www.tj-hxxt.cn/news/247907.html

相关文章:

  • 绍兴住房和城乡建设厅网站首页wordpress字体旋转
  • 万万州州微微网站网站建建设设网络域名
  • 网站设计和美工一样吗公司网站如何注册
  • 代做毕设的网站深圳市做网站
  • 视频网站直播怎么做建什么类型个人网站比较好
  • 单页面网站多少钱邓州网站优化
  • 做任务赚佣金的网站想做网站 优帮云
  • 装饰公司网站模板下载中国机械设备网官网
  • 中国建设银行官方网站诚聘英才频道贵州省建设厅的网站
  • 类似淘宝网站建设有哪些模板网站图片 优化
  • 贵阳网站优化广西网络优化seo
  • 自己做的网站能卖么重庆建工集团建设网站
  • 永康建设网站广告设计与制作包括哪些内容
  • 大连鑫农建设集团网站寮步仿做网站
  • 网站背景全屏广州安全教育平台账号是多少
  • 找人做的网站怎么看ftp网站栏目设置完整度建设
  • 网站如何留住客户网站开发协议书
  • 上海定制化网站开发公司丹阳做网站的
  • 2015帝国cms网站国际最好的摄影作品网站
  • 苏州做网站推广的免费行情软件app网站下载大全
  • 专业的企业网站优化公司网站空间免备案
  • 建设银行注册网站名咋设置wordpress批量读取excel
  • 伊春市建设局网站wordpress 字体 插件下载地址
  • 静态网站管理系统信主网站
  • 宜宾建设局网站热狗seo顾问
  • 网站备案 godaddy电子版个人简历
  • 电子商务网站建设行情网页设计大专工资一般多少
  • 滨州网站定制搬瓦工搭建wordpress
  • 做兼职在什么网站上找淄博桓台网站建设报价
  • 六安市网站制作吉林商城网站建设