android错误笔记

Sunflower

Photo by Maurits Verschoren on Unsplash

Android studio 模拟器访问本机测试网站,资源

网络地址 说明
10.0.2.1 路由器/网关地址
10.0.2.2 主机回环接口的特殊别名(即,开发计算机上的 127.0.0.1)
10.0.2.3 第一个 DNS 服务器
10.0.2.4 / 10.0.2.5 / 10.0.2.6 可选的第二个、第三个和第四个 DNS 服务器(如果有)
10.0.2.15 模拟设备网络/以太网接口
127.0.0.1 模拟设备回环接口

————————————————
参考链接:https://developer.android.com/studio/run/emulator-networking?hl=zh-cn

打包安卓报错error: resource android:attr/fontStyle not found.

1
2
3
4
5
6
7
8
原因是
compileSdkVersion 25
低于
implementation 'com.android.support:appcompat-v7:27.0.0'

解决办法,要么升sdk版本,要么降support版本
————————————————
参考链接:https://blog.csdn.net/u011407338/article/details/91039651

AS中导入framework/android包的技巧

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
首先,将android包放在lib目录下,并在项目的build.gradle目录的dependence下添加以下代码:

gradle 3.0以上
compileOnly files('libs/android.jar')

gradle 3.0以下
provide files('libs/android.jar')

这里是为了在编译和打包时只编译/打包进使用过得二次编码包。
因为使用compile或者implementation会将整个android.jar包打入apk包中,还会造成dex打包错误。
同时注释以下依赖:

// implementation fileTree(include: ['*.jar'], dir: 'libs')

最后,在项目根目录build.gradle目录下,需要使用全局配置路径的方式来引入jar包。
//添加以下代码,使android.jar包编译先于系统下android.jar
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs.add("-Xbootclasspath/p:$rootDir${File.separator}app${File.separator}libs${File.separator}android.jar")
}
}
变量
rootDir 项目的路径
$ {File.separator}引用当前系统的分隔符,windows与mac不相同

编译运行通过。

————————————————
参考链接:https://github.com/jiaoery/JarDemo

各个 Android Gradle 插件版本所需的 Gradle 版本。要获得最佳性能,您应该使用 Gradle 和插件这两者的最新版本。

!!!一般文档以英文为准,1是更新比其他文档及时,2是翻译理解有所差异

Plugin version Required Gradle version
1.0.0 - 1.1.3 2.2.1 - 2.3
1.2.0 - 1.3.1 2.2.1 - 2.9
1.5.0 2.2.1 - 2.13
2.0.0 - 2.1.2 2.10 - 2.13
2.1.3 - 2.2.3 2.14.1+
2.3.0+ 3.3+
3.0.0+ 4.1+
3.1.0+ 4.4+
3.2.0 - 3.2.1 4.6+
3.3.0 - 3.3.3 4.10.1+
3.4.0 - 3.4.3 5.1.1+
3.5.0 - 3.5.4 5.4.1+
3.6.0 - 3.6.4 5.6.4+
4.0.0+ 6.1.1+

failed to read PNG signature: file does not start with PNG signature.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
原因:原图片可能jpg格式的图片,通过更改后缀的方式将jpg转为png后缀

修复方式,用p或是其他软件另存为png图片即可

Perhaps it's not actually a PNG, but a JPG renamed to PNG.
The problem could be because of the wrong extension of images.

In my case, the file was a JPEG image but it was saved as PNG not converted to.
In this situation change extension to the real one and convert to PNG then retry.

For instance, you have ic_logo.png but it's actually a JPG image.
You should rename it back to ic_logo.jpg and use something like Photoshop to
convert the image to PNG format.
————————————————
参考链接:https://stackoverflow.com/questions/46177560/failed-to-read-png-signature-file-
does-not-start-with-png-signature

Lint found fatal errors while assembling a release target.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Lint found fatal errors while assembling a release target. 
To proceed, either fix the issues identified by lint, or modify your build script as follows: ...
android {
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
}
修复:根据 项目目录下app/build/reports/lint-results-release-fatal.html 文件
这个文件就详细描述了release时lint检测到的比较严重的结果然后逐一进行修复即可
————————————————
参考链接:https://blog.csdn.net/aiynmimi/article/details/89401239

Duplicate class com.tencent.ijk.media.exo.BuildConfig found in modules

1
2
3
4
5
6
7
8
9
原因
依赖了重复的资源文件,例如:

lib中导入了A.aar文件,然后又在build.gradle中依赖了相同的A文件。
依赖两个不同的资源文件,但是,这两个资源文件里面包含了相同的内容。
解决方案
去除重复的资源文件即可。
————————————————
参考链接:https://blog.csdn.net/m0_46278918/article/details/107770473

Binary XML file line #20: Error inflating class ImageView RecyclerView

1
2
3
4
5
6
原因:应该是图片资源被放在drawable-v24 或是 mipmap-anydpi-v26夹中
解决:将文件移动到drawable或是mipmap文件夹中即可

I had the same problem. my problem has occurred because I just had used images (icons) in the "drawable-v24" folder. I solved it by copying them into "drawable" folder
————————————————
参考链接:https://stackoverflow.com/questions/16698313/error-inflating-class-imageview

android隐藏标题栏(Action Bar),全屏

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
在Manifest对应的Activity设置NoTitleBar风格
android:theme="@style/Theme.AppCompat.NoActionBar"

2.在代码中隐藏标题栏
if (getSupportActionBar() != null){
getSupportActionBar().hide();
}

3.去掉标题栏,需要注意的是,requestWindowFeature()方法必须在setContentView()调用前使用。
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);

4.Activity全屏的设置。
标题栏(Action Bar)是Activity的一部分,全屏只是会隐藏状态栏,对标题栏无影响
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

————————————————
日期:2020/08/10
参考链接:https://blog.csdn.net/daihuimaozideren/article/details/78224927