1
Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
is also present at [androidx.core:core:1.2.0] AndroidManifest.xml:24:18-86 value=(androidx.core.app.CoreComponentFactory).
Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:23:5-63:19 to override.
解决方法:
AndroidManifest.xml文件里的application里做如下添加:
android:appComponentFactory=""
tools:replace="android:appComponentFactory"
2
Program type already present: com.google.android.material.internal.package-info
解决方法:
有两个包都引入了这个,删掉一个包,重新构建
3
More than one file was found with OS independent path 'META-INF/proguard/androidx-annotations.pro'
解决方法:
在app的build.gradle加入如下报错提示的缺失代码:
packagingOptions {
exclude 'META-INF/proguard/androidx-annotations.pro'
}
位置:
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
buildTypes {
release {
lintOptions {
checkReleaseBuilds false
abortOnError false
}
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets.main {
jniLibs.srcDir 'src/main/libs'
}
packagingOptions {
exclude 'META-INF/proguard/androidx-annotations.pro'
}
}
4.RecyclerView不调用onCreateViewHolder和onBindViewHolder
getItemCount()返回值<=0
5.RecyclerView中getItemCount函数返回的数与实际生成的Item数量不一致
原因:item的layout的最外层布局的layout_width和layout_height不能是match_parent。如果recyclerView是横向排列的,item的width不能是match_parent,如果item是纵向排列的,item的height不能是match_parent。否则第一个item就会把其他的item挤出recyclerLayout
6.RecyclerView 滑动之后显示数据错乱(点击状态也错乱)
解决方法:重写Adapter的getItemViewType方法
/**
* 解决RecyclerView 滑动之后显示数据错乱
* 由于RecyclerView的onBindViewHolder()方法,
* 只有在getItemViewType()返回类型不同时才会调用,
* 这点是跟ListView的getView()方法不同的地方,
* 所以如果想要每次都调用onBindViewHolder()刷新item数据,
* 就要重写getItemViewType(),让其返回position,否则很容易产生数据错乱的现象
*/
override fun getItemViewType(position: Int): Int {
return position
}
解决前:
解决后:
7.FrameLayout布局 点击事件无反应
解决方法:想点击的控件的层级被遮挡
1.在XML文件中,可以使用FramLayout或RelativeLayout来布局,每个控件都是覆盖显示的,后加进来的控件覆盖前面的控件。可以把控件写在最后,从而实现显示在最上层的效果。
2.view.bringToFront() 可以将布局在下层的控件放到上层,不被其他控件挡住。