0. https://android.googlesource.com/platform/development/+/refs/tags/android-8.1.0_r63/samples/
Android官方控件使用示例代码
1. 导入的zxing等第三方类在布局里可以识别,但运行时无法解析,not found。
答:请把Android studio中project struct里的JDK配置为Android studio默认的jdk。
2. 编译ids.xml报错
<item type="id" name="about_version_code">false</item>
<item type="id" name="split">false</item>
答:因为新版GRADLE不支持,需要把false去掉
3. JPUSH集成经验
答:直接下载 对应包名的DEMO集成,如果manifest.xml找不到自定义类,那么就写全名:包名+路径+类,或者移动到其它目录。
4. 百度SDK
应用退出之前,一定要调用uninit函数,否则定位服务一直开着,即使不再获取经纬度了。
5. 编译问题,出现如下错误:
Attribute meta-data#android.support.FILE_PROVIDER_PATHS@resource value=(@xml/file_paths_twogao) from AndroidManifest.xml:506:22-63 is also present at [com.jph.takephoto:takephoto_library:4.0.3] AndroidManifest.xml:24:17-51 value=(@xml/file_paths).
Suggestion: add 'tools:replace="android:resource"' to <meta-data> element at AndroidManifest.xml:504:18-506:66 to override.
答:工程中各module的support库的版本号不统一,解决方法,在全局工程中的build.gradle中配置如下:
subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.android.support'
&& !details.requested.name.contains('multidex') ) {
//统一版本号
details.useVersion "27.0.2"
}
}
}
}
将support版本统一为27.0.2,然后再次编译,根据错误提示修改AndroidManifest.xml,比如我根据错误信息,在provider元素里增加了属性tools:replace="android.authorities", 在<meta-data>里添加了 tools:replace="android:resource"
<provider
android:authorities="com.anyikang.fallalarm.aek"
android:name="android.support.v4.content.FileProvider"
android:exported="false"
tools:replace="android:authorities"
android:grantUriPermissions="true">
<meta-data
tools:replace="android:resource"
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths_twogao" />
</provider>
6. 编译运行问题,报错:values-v28.xml:7: error: resource android:attr/dialogCornerRadius not found
答:将编译版本号修改统一。要么都是28,要么都是26.
7. protocol family unavailable
android studio编译项目突然报错:protocol family unavailable。
解决方法: 在控制面板里关闭防火墙。
8. JPush设置别名后,收不到推送
在排除网络和APP保活的基础上,查询这个别名绑定的手机个数,目前不能超过10个手机。
查询别名绑定的手机个数,在命令提示符下输入以下命令,其中130729xx248是我的别名,大家可以替换成自己的,其中22f403b566bbb94dx1eaeaba:d22df9d623f5f920dc437709是app在jpush控制台中的appKey:masterSecret.
curl --insecure -X GET -v https://device.jpush.cn/v3/aliases/{18392086025} -H "Content-Type: application/json" -u "22f403b566bbb94df1eaeaba:d22df9d623f5f920dc437709"
9.导入别人的工程gradle插件工具报错:
Caused by: org.gradle.internal.resolve.ModuleVersionNotFoundException:
Could not find com.android.tools.build:gradle:3.2.0.
解决方法:
在根目录下的build.gradle 添加google()
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
10. 安装失败
Installation did not succeed.
The application could not be installed: INSTALL_FAILED_TEST_ONLY
Installation failed due to: 'null'
解决方法:在gradle.properties 文件里添加
android.injected.testOnly=false
11 switch改变样式
<Switch android:id="@+id/switchScoreInput" android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="true" android:splitTrack="false" android:switchPadding="4dp" android:theme="@style/Color1SwitchStyle" android:text="@string/define_myself" android:typeface="monospace" android:visibility="visible" tools:ignore="UseSwitchCompatOrMaterialXml" />
Color1SwitchStyle在value/styles里定义:
<style name="Color1SwitchStyle"> <item name="colorControlActivated">@color/colorPrimary</item> <!-- 关闭时的拇指按钮的颜色 --> <item name="colorSwitchThumbNormal">@color/gray</item> <!-- witch关闭时的轨迹的颜色 30%这个颜色 --> <item name="android:colorForeground">@color/gray</item> </style>
12. Could not find method leftShift() for arguments
找到 gradle脚本中的<< , 替换为doLast
例如
task helloword << { println 'Hello gradle qick start' }
应修改为
task helloword { doLast{ println 'Hello gradle qick start' } }
13. android studio打包时,提示jks要迁移到行业标准pkcs12
执行类似于如下名字,注意目标文件改为aa2,总之不要重名。
keytool -importkeystore -srckeystore C:\aa.jks -destkeystore aa2.jks -deststoretype pkcs12
14.设置BottomNavigationView的选中,未选中时图片和文字的颜色
用以下这两个设置选中、未选中图片,文字颜色
app:itemIconTint="@drawable/nav_tab_color"
app:itemTextColor="@drawable/nav_tab_color"
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/main_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:itemIconTint="@drawable/nav_tab_color"
app:itemTextColor="@drawable/nav_tab_color"
android:background="?android:attr/windowBackground"
app:menu="@menu/navigation" />
mOnNavigationItemSelectedListener中的
onNavigationItemSelected里可以重新设定选中icon: item.setIcon(R.drawable.op_list_sel);
如果,设定了icon后,icon被主题色渲染成纯色了,那么可以这么解决,先去掉BottomNavigationView的默认着色:
mMainNavigation.setItemIconTintList(null); //删除默认的选中效果,否则的话icon会被着色成主题色
15. mkdirs创建目录失败
使用如下getExternalStorageDirectory方式获得的路径,然后mkdir创建就会失败
videoFilepath = Environment.getExternalStorageDirectory().path + File.separator + "AVideoRecorder"
if (videoFilepath == null) {
return false;
}
val dir = File(videoFilepath)
if (!dir.exists()) {
dir.mkdir()
}
应该换成 getExternalFilesDir(); 还有就是创建多级目录时使用mkdirs()