
Android 疑难杂症
文章平均质量分 78
yechaoa
优快云博客专家、掘金签约作者、infoQ 专家博主、阿里云专家博主、51CTO专家博主、华为云云享专家;现就职于阿里巴巴,研究方向包括但不限于大前端、端基础架构与中间件、性能优化等。
展开
-
Android 11适配指南之Toast解析
起源在targetSdkVersion为30的情况下,在Android 11的小米10的手机上运行,调用ToastUtil的时候闪退报错:null cannot be cast to non-null type android.widget.LinearLayout为什么说的这么详细呢,因为这些条件都是必须的:targetSdkVersion 30Android 11小米10同样的targetSdkVersion,在Android 11的华为P30 Pro上运行确实正常的,为什么呢,根据原创 2021-01-26 20:05:37 · 6181 阅读 · 3 评论 -
【解决问题的思路】its super classes have no public methods with the @Subscribe annotation
在打release包的时候遇到了这个问题,算是比较常见,记一下解决思路。本文介绍了出现这个问题的原因,以及出现问题时我的建议和我的思路,着急的可以直接看解决方案。异常Subscriber class xxx and its super classes have no public methods with the @Subscribe annotation遇到异常不要慌,其实已经提示的很明显了,指定了具体的class,且明确告诉你这个类没有@Subscribe注解。原因但其实知道了问题后,可能原创 2021-01-16 14:09:47 · 6120 阅读 · 2 评论 -
Android 阿里云镜像整理
在android开发中,因为各种原因,时常编译速度缓慢甚至卡住不动,切换到阿里云maven仓库之后,则可以提升编译速度。googlehttps://maven.aliyun.com/repository/googlejcenterhttps://maven.aliyun.com/repository/publicpublic(central仓和jcenter仓的聚合仓)https://maven.aliyun.com/repository/publicgradle-plugin原创 2020-12-18 14:30:17 · 2273 阅读 · 2 评论 -
Installation did not succeed。apk安装失败的一些解决办法
其实有挺多原因会导致安装失败的,所以解决办法也不尽相同,下面列举一些解决办法。一先查看手机环境,是否打开USB调试,是否允许安装应用,手机是否处于打开状态,黑屏状态下也是会安装失败的。二清除缓存并重启AS可以尝试同步重启手机。三重试安装,可能会在安装提示的时候点错了,导致安装失败。四删除.gradle文件夹、.idea文件夹,build文件夹。然后重新编译会自动生成,这个可能是因为升级了AS,或者改了某些配置导致的版本不对称,所以删除重新编译即可。五编译期间注意查看控制台中buil原创 2020-10-09 10:32:00 · 5509 阅读 · 7 评论 -
‘annotationProcessor‘ dependencies won‘t be recognized as kapt annotation processors. Please change
‘annotationProcessor’ dependencies won’t be recognized as kapt annotation processors. Please change the configuration name to ‘kapt’ for these artifacts: ‘com.airbnb:deeplinkdispatch-processor:4.1.0’.简而言之,需要把annotationProcessor切换为kapt就可以了。切换前: api .原创 2020-10-08 16:04:02 · 4823 阅读 · 1 评论 -
DSL element ‘android.dataBinding.enabled‘ is obsolete and has been replaced with ‘android.buildFeatu
DSL element ‘android.dataBinding.enabled’ is obsolete and has been replaced with ‘android.buildFeatures.dataBinding’.It will be removed in version 5.0 of the Android Gradle plugin.实际上就是换一种写法。原来: dataBinding { enabled true }现在: bu.原创 2020-10-08 15:29:38 · 2864 阅读 · 1 评论 -
Android识别模拟器,判断是模拟器还是真机
文章目录前言原理禁止模拟器安装apk代码识别验证最后前言对于android开发者来说,模拟器是开发工具,但是对用户来说,可能就是薅羊毛、找漏洞的赚钱工具。不管是活动风控还是内容保护等等其他的出发点,应要求可能会要识别Android模拟器,甚至禁止模拟器登录或后续操作。今天做个简单的探讨。原理识别模拟器的原理,其实就是找出模拟器和真机的差别,但是这些差别体现在哪呢,比如运营商、手机卡、蓝牙、各种传感器等等。但是现在的模拟器也是越来越厉害了,可以模拟不同品牌的不同型号的不同版本的手机,而且有蓝牙、原创 2020-09-25 17:28:36 · 14329 阅读 · 3 评论 -
Android 10 适配攻略
文章目录准备工作1.Scoped Storage(分区存储)说明适配补充2.权限变化1.在后台运行时访问设备位置信息需要权限2.一些电话、蓝牙和WLAN的API需要精确位置权限3.ACCESS_MEDIA_LOCATION4.PROCESS_OUTGOING_CALLS3.后台启动 Activity 的限制4.深色主题1.手动适配(资源替换)2.自动适配(Force Dark)手动切换主题监听深色...转载 2020-03-20 11:08:34 · 1334 阅读 · 0 评论 -
Android 模拟器不能连网?
前言Android 模拟器可以运行,但是不能连接网络,事实上这是第二次遇到这个情况了,第一次是在公司,Windows系统,当时的处理方式是直接禁用了IPV6,最近又遇到了,这次是mac系统,但是距离上次已经好久了,所有又耽搁了点时间解决,所以决定搞清楚并解决这个问题。出现异常首先最直接的就是会给你报异常:java.net.UnknownHostException: Unable to r...原创 2020-02-27 23:11:48 · 3366 阅读 · 0 评论 -
一个移动端开发者,对未来的思考
本文转载自微信订阅号:鸿洋,有启发,故转载。原作者:舒大飞,链接:https://juejin.im/post/5e0d85155188253a8b42e5ba平常都在写技术类文章,今天写篇作为一个移动端开发者对过去一年的总结和思考吧,既是对过去的回顾,也是对未来的思考。2019这一年对于我来说,当然最多的时间还是花在工作上。对于移动端开发来说,2019年依然是动荡的一年,各种跨平台技...转载 2020-01-19 11:12:37 · 981 阅读 · 0 评论 -
Android 现有项目迁移到androidx
前言我在全新项目中用过androidx,也做过老项目迁移到androidx,所以,我想表达的是androidx其实没那么神秘,也没那么多坑,时至今日也一年多过去了,基本趋于稳定,未来也是大势所趋,所以,迁移是迟早的事。何为androidxandroidx其实是对Support Library的一次整合升级,即我们常用的v4包、v7包等,这些包最开始是做向下兼容的,但是现如今向下兼容的版本(t...原创 2019-12-12 15:13:27 · 1332 阅读 · 2 评论 -
Android 企业微信登录 接入指南
其实也挺简单的,那为什么还写呢,还不是因为微信文档写的不清不楚。。1、创建应用管理员登录企业微信管理后台,选择企业应用。选择已有应用或添加应用,进入应用详情页面。选择“企业微信授权登录”,在设置界面填写Android的 App的签名&包名,设置完成后系统自动生成应用程序schema。这里要注意了,本地签名和线上签名可能会不一样,从而导致 没有此权限 调不起来企业微信授权,...原创 2019-12-05 15:50:22 · 3999 阅读 · 4 评论 -
Android 7.0及以上PopupWindow 适配问题
Android 7.0及以上PopupWindow的位置会显示不正常,背景阴影可能也会不正常,需要动态计算高度。 //popupWindow 适配7.0及以上系统显示问题 if (Build.VERSION.SDK_INT >= 24) { Rect rect = new Rect(); mTabLayout.g...原创 2019-10-12 16:51:24 · 1011 阅读 · 0 评论 -
Android ScrollView嵌套RecyclerView滑动卡顿
因为种种原因导致嵌套使用,这里只记录解决办法。1,xml中RecyclerView添加android:nestedScrollingEnabled="false"属性 <android.support.v7.widget.RecyclerView android:id="@+id/recyclerView" android:layout_width="ma...原创 2019-01-17 18:22:12 · 2126 阅读 · 0 评论 -
On SDK version 23 and up, your app data will be automatically backed up and restored on app install.
导致这样的问题是你的menifest文件中的application 中android:allowBackup=“true”;allowBackup安全风险描述:Android API Level 8及其以上Android系统提供了为应用程序数据的备份和恢复功能,此功能的开关决定于该应用程序中AndroidManif est.xml文件中的allowBackup属性值[1] ,其属性值默认是Tr...转载 2018-12-19 09:44:50 · 2418 阅读 · 0 评论 -
App is not indexable by Google Search; consider adding at least one Activity with an ACTION-VIEW in
AndroidManifest 中 application 提示:App is not indexable by Google Search; consider adding at least one Activity with an ACTION-VIEW intent filter. See issue explanation for more details. less… (Ctrl+F1...原创 2018-12-19 09:25:07 · 1415 阅读 · 0 评论 -
Android Studio 升级3.2之后找不到moudle中的类?
以友盟推送为例,PushAgent报错,找不到 com.umeng.message.PushAgent,在as3.0+的版本之后,引用的方式 compile 变为 implementation,但是在moudle中,需要用api的方式代替 implementation,重新编译即可,不然会找不到对外暴露的类或方法...原创 2018-12-18 19:14:14 · 1400 阅读 · 1 评论 -
The SourceSet ‘instrumentTest’ is not recognized by the Android Gradle Plugin. AS升级问题
The SourceSet ‘instrumentTest’ is not recognized by the Android Gradle Plugin. Perhaps you misspelled something?在android studio 升级3.2的过程中遇到这个问题,解决办法instrumentTest 已经废弃 ,在build.gradle文件中找到instrumen...原创 2018-12-18 19:04:54 · 725 阅读 · 0 评论 -
Android greenDAO 3.2.2简单使用
github : https://github.com/greenrobot/greenDAO集成// In your root build.gradle file:buildscript { repositories { jcenter() mavenCentral() // add repository } depende...原创 2018-10-30 15:40:55 · 2264 阅读 · 0 评论 -
Android开发版本和API等级对应关系
建议收藏Platform VersionAPI LevelVERSION_CODE9.028P8.127O_MR18.026O7.125N_MR17.024N6.023M5.122LOLLIPOP_MR15.021LOLLIPOP4.4w20KITKAT_WATCH4.419KI...原创 2018-10-11 14:24:10 · 4918 阅读 · 0 评论 -
ScrollView 初始化的时候不在最顶部?
日常开发中经常用到ScrollView嵌套控件,比如RecyclerView、自定义View、动态创建的View等等在初始化的时候可能会直接滑动到子View的位置,这是因为子view 主动请求并获取到了焦点所以呢,解决办法也很简单,在ScrollView或者更外层的根布局添加两个属性即可,即把焦点抢回来的意思android:focusable="true"android:foc...原创 2018-10-11 08:53:36 · 1842 阅读 · 1 评论 -
Warning! This package referenced a Flutter repository via the .packages file that is no longer avail
Warning! This package referenced a Flutter repository via the .packages file that is no longer available. The repository from which the 'flutter' tool is currently executing will be used instead. ...原创 2019-05-29 19:56:16 · 6542 阅读 · 0 评论 -
Android 8.0安装apk的正确姿势
在8.0的系统版本中,安装apk时有一层膜,现在就要捅了它,不然就是一闪而过,安装不上。这层膜就是允许安装未知应用在8.0中这个选项默认是false,只需要打开一次即可1、manifest中添加权限 &amp;lt;!-- 8.0安装未知应用来源 --&amp;gt; &amp;lt;uses-permission android:name=&quot;android.permission...原创 2018-09-07 14:05:53 · 5599 阅读 · 0 评论 -
AppBarLayout 折叠之后有阴影?
重写style属性 <android.support.design.widget.AppBarLayout android:id="@+id/app_bar" android:layout_width="match_parent" android:layout_height="240dp" android:fitsSys...原创 2019-01-17 18:27:22 · 1415 阅读 · 0 评论 -
AS项目一直Indexing paused due to batch updated
经过先更新了AS(3.0>3.2),然后更新了项目,一顿同步编译之后就出现了Indexing paused due to batch updated,过了一会还是没好,然后关掉项目重新打开关掉AS重新打开清除缓存重新打开删除idea文件夹及iml文件重新打开以上 都不行 !!!我的解决办法,仅供参考,因为你不一定是跟我一样的原因导致的。删除本地项目重新checkout...原创 2019-01-26 01:03:08 · 1470 阅读 · 0 评论 -
glide 设置圆角导致图片变形?
glide 设置圆角的时候会导致ImageView的scaleType属性无效?导致图片变形?原因:属性覆盖了。为什么呢,其实是因为重复调用了transform方法导致的,比如new CenterCrop(mContext)或者是new RequestOptions().centerCrop()public class CenterCrop extends BitmapTransforma...原创 2019-01-16 16:39:14 · 2211 阅读 · 0 评论 -
'getWidth()' is deprecated,'getHeight()' is deprecated
getWidth()和getHeight()在API 13(3.2)过时 代替写法 DisplayMetrics dm = new DisplayMetrics(); this.getWindowManager().getDefaultDisplay().getMetrics(dm); int width = dm.widthPixels; int原创 2017-05-27 15:20:17 · 2000 阅读 · 0 评论 -
Android Studio 3.5格式化布局错乱
解决办法:Settings > Editor > Code Style > XML > Set from… > Predefined Style > Android原创 2019-09-10 16:41:24 · 1408 阅读 · 0 评论 -
SwipeRefreshLayout嵌套banner滑动冲突
banner是一个第三方轮播库,到现在为止已经有8000+的star了,使用的人也很多。使用的人越多,业务场景就越多,相应的问题也会越多。比如SwipeRefreshLayout嵌套banner的时候,就会使banner手动滑动起来特别的费劲,经常滑不过去。https://github.com/youth5201314/banner思路:因为下拉刷新,只有纵向滑动的时候才有效,只需要判...原创 2019-07-08 14:01:29 · 1605 阅读 · 0 评论 -
SwipeRefreshLayout 嵌套 RecyclerView滑动冲突
原则上你使用的RecyclerView框架可能是自带刷新的,如果没有就可能会出现这种问题,滑动时会出现卡顿、触发刷新的时机也不对。思路:监听RecyclerView的滑动,当滑动到顶部的时候,再设置SwipeRefreshLayout刷新可用。代码 mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollL...原创 2019-07-08 13:46:32 · 3804 阅读 · 0 评论 -
VisibilityAwareImageButton.setVisibility can only be called from within the same library group (grou
VisibilityAwareImageButton.setVisibility can only be called from within the same library group (groupId=com.android.support) FloatingActionButton在setVisibility的时候会有以上异常fab.setVisibility(View.VISIB...原创 2019-06-10 12:01:12 · 3661 阅读 · 0 评论 -
Android Studio 升级3.4,Gradle升级5.1遇到的问题
Android Studio 现在都3.4的版本了,但其实用2.+版本的大有人在。原因就在于每次升级都会有各种问题,解决时间过长就会影响当前项目进度,所以很大一部分人都是选择忽略升级的。 但是最新的正式版本肯定是最好的,修复了以前的bug不说,还会有很多新的功能,包括流畅度、编译速度等方面的提升等等,还是尽量升级的好。其实AS提示我update有段时间了,但多数情况下我都是顺手点了cl...原创 2019-06-06 10:29:16 · 4505 阅读 · 0 评论 -
Flutter BottomNavigationBar不显示(显示白色)?
BottomNavigationBar 超过3个之后不显示(显示白色)?官网文档解释:The bottom navigation bar’s type changes how its items are displayed. If not specified it’s automatically set toBottomNavigationBarType.fixed when ther...原创 2019-05-05 17:49:50 · 2440 阅读 · 0 评论 -
java.net.UnknownServiceException: CLEARTEXT communication to * not permitted by network
在Android O 升 P (8.0升9.0)的时候,会报以下异常java.net.UnknownServiceException: CLEARTEXT communication to * not permitted by network因为 Android P 是默认禁止访问http的API的。解决办法:1,使用https2,暂时先绕过HTTP限制在res文件夹下创建xml...原创 2019-04-28 21:31:46 · 5489 阅读 · 0 评论 -
SwipeRefreshLayout 嵌套ScrollView 滑动冲突
冲突来源于 ScrollView 向下滑动的时候会触发 SwipeRefreshLayout 下拉刷新。解决思路:根据ScrollView 滑动距离动态处理SwipeRefreshLayout 刷新。 mScrollView.setScrollViewListener(new GradationScrollView.ScrollViewListener() { ...原创 2019-01-23 14:21:01 · 2898 阅读 · 0 评论 -
onGetLayoutInflater() cannot be executed until the Fragment is attached to the FragmentManager.
出现这个异常来自于在Fragment中动态添加一个布局,切换的时候崩溃写法如下:getLayoutInflater().inflate(R.layout.layout_footer...)调用的是Activity的getLayoutInflater 这句代码原本是没有什么问题的,但是在Fragment中使用就有问题了。解决办法:换一种写法LayoutInfla...原创 2018-07-12 16:07:31 · 6417 阅读 · 4 评论 -
解决CardView在5.0以下留白的问题
CardView在5.0以下显示会有一点留白,有点类似TextView默认的padding,这个时候即使设置contentPadding属性也是没有用的。解决办法在用的地方做一层判断,如果当前系统是5.0以下,padding设为负值,把留白撑掉。 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { ...原创 2018-07-04 16:08:42 · 2273 阅读 · 0 评论 -
Android EditText设置inputType之后minLines失效
EditText设置inputType之后minLines失效,会变成一行显示查阅了一圈也没有好的解决办法,总结一下三种解决方案: 1.去掉inputType属性2.设置inputType属性值为none3.给EditText设置高度...原创 2018-07-03 15:15:07 · 1480 阅读 · 0 评论 -
Failed resolution of: Lokhttp3/internal/Platform;
升级 logging-interceptor 版本compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'原创 2017-08-20 00:57:20 · 4710 阅读 · 0 评论 -
The APK file does not exist on disk
Android Studio 运行报错:The APK file does not exist on disk解决办法:点击右侧的Gradle,刷新之后再运行即可原创 2017-08-03 22:23:09 · 724 阅读 · 0 评论