ERROR: Failed to resolve: org.jetbrains.kotlin:kotlin-stdlib-jre7:1.3.21
问题原因:kotlin插件升级到1.2.41时提示kotlin-stdlib-jre7过时
解决办法:
org.jetbrains.kotlin:kotlin-stdlib-jre7:1.3.50 改成
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.50
原文:https://blog.csdn.net/u010117864/article/details/89416505
error: <item> inner element must either be a resource reference or empty./values/values.xml Daemon: AAPT2
debug\values\values.xml AAPT: error
如上错误原来是values.xm资源文件中,元素定义了id后,就不能在后面给值了
发现
<item name="split" type="id">false</item>
改为
<item name="split" type="id"/>
在依赖项目zxinglib中发现ids.xml资源文件,同样修改
<item name="split" type="id"></item>
Android Studio error: Unable to start the daemon process的解决方法
在 Android Studio 上新建项目,出现 Unable to start the daemon process. 错误,具体错误信息如下:
Error:Unable to start the daemon process.
This problem might be caused by incorrect configuration of the daemon.
For example, an unrecognized jvm option is used.
Please refer to the user guide chapter on the daemon at https://docs.gradle.org/4.1/userguide/gradle_daemon.html
Please read the following process output to find out more:
-----------------------
解决方法
方法一:删除 C:\Users\UserName\.gradle 目录,重新启动 Android Studio即可。重启动后,它会自动为你创建一个新的。
com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex 错误
build.gradle文件引入资源配置问题
包重复 分包处理
添加依赖compile com.android.support:multidex:1.0.1,
让application继承MultiDexApplication
删除重复的依赖
1.检查lib目录下是否有重复引用的jar包
2.删除或者注释主项目中的support依赖
dependencies {
//implementation 'com.android.support:appcompat-v7:26.1.0'
}
保留Lib库的依赖
dependencies {
implementation 'com.android.support:appcompat-v7:26.1.0'
}
处理guava-21.0不兼容Android错误:DexArchiveBuilderException: Failed to process guava-21.0.jar
在Android项目里使用guava-21.0报错:
Error:com.android.builder.dexing.DexArchiveBuilderException: Failed to process C:\Users\cc\.gradle\caches\modules-2\files-2.1\com.google.guava\guava\21.0\3a3d111be1be1b745edfa7d91678a12d7ed38709\guava-21.0.jar
Error:com.android.builder.dexing.DexArchiveBuilderException: Error while dexing.
Error:com.android.tools.r8.ApiLevelException: Default interface methods are only supported starting with Android N (--min-api 24): java.util.Collection com.google.common.collect.BiMap.values()
Error:Execution failed for task ':app:transformClassesWithDexBuilderForDebug'.
原因是guava 21使用的是Java 8,与Android不兼容。
可以把guava 21改为与Android兼容的版本23.3-android
dependencies {
compile 'com.google.guava:guava:23.3-android'
}
参考:https://majing.io/posts/10000003611166
android第三方库导致support版本冲突解决方案
问题:升级compileSdk版本到26,同时修改了support包的版本,报错
all com.android.support libraries must use the exact same version specification(mixing versions can lead to runtime crashes)
也就是说有引入的第三方库和目前编译版本有冲突。
解决:一般这种问题解决方案是,在指定的有冲突的库的依赖处,添加 exclude group: 'com.android.support'
,可以将冲突库不包含在编译,如
compile('xx.xxx.xxxxx:xxxxx:1.5.5') {
exclude group: 'com.android.support'
}
但是问题是我不知道哪个第三方库冲突,不可能一个个检查吧?
这时候只需要在gradle文件中添加如下代码,让所有的第三方包强制使用指定版本的support包:
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support') {
if (!requested.name.startsWith("multidex")) {
details.useVersion '26.1.0'
}
}
}
}
以及在自己写第三方库给别人用的时候,对于support包的依赖方式改成provided(或者compileOnly,gradle3.0),这样不会把support打包,方便使用的人。
implementation替换compile
gradle升级到3.0后,依赖的方式变得更多了,最显著的变化就是,之前一直用的compile
可以替换为implementation
, 如
implementation 'xx.xxx.xxxxx:xxxxx::1.5.5'
implementation
是指引入依赖,这个第三方包引入的东西,你在项目里无法使用,有点接口的味道,屏蔽内部实现。可以加快gradle编译的速度。
同样的对于 debugcompile
releasecompile
都有debug implementation
release implementation
与之对应。
com.android.support.test:runner:1.0.1报红的错误
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
错误:All com.android.support libraries must use the exact same version specification
原因:是由于依赖的第三方库中有依赖到support
库,但是版本不一致引起的
查找模板依赖关系:使用命令-gradlew :模块名称:dependencies
发现espresso库已经包含了runner库,导致了重复的依赖引入
+--- com.android.support.test:runner:1.0.1
| +--- com.android.support:support-annotations:25.4.0
| +--- junit:junit:4.12
| | \--- org.hamcrest:hamcrest-core:1.3
| \--- net.sf.kxml:kxml2:2.3.0
\--- com.android.support.test.espresso:espresso-core:3.0.1
+--- com.android.support.test:runner:1.0.1 (*)
+--- com.android.support.test:rules:1.0.1
| \--- com.android.support.test:runner:1.0.1 (*)
而且发现runner库中的support-annotations版本和整体项目support版本不一致
+--- com.android.support.test:runner:1.0.1
| +--- com.android.support:support-annotations:25.4.0 -> 27.1.1
| +--- junit:junit:4.12
| | \--- org.hamcrest:hamcrest-core:1.3
| \--- net.sf.kxml:kxml2:2.3.0
解决:注释runner库,espresso库是Implementation方式依赖,不会对外提供support库的依赖,不会引起support冲突
// androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
。。。
EasyPermissions报错Cannot execute method requestPermision because it is non-void method and/or has input parameters
//AfterPermissionGranted只能与不带参数的方法一起使用,否则会崩溃,
修改前
@AfterPermissionGranted(REQUEST_PERMISON_CODE)
protected void requestPermision(Context context) {
修改后
@AfterPermissionGranted(REQUEST_PERMISON_CODE)
protected void requestPermision() {
Canvas:Invalid Region.Op - only INTERSECT and DIFFERENCE are allowed
报错代码:canvas.clipRect(mClipBounds, Region.Op.UNION);
解决方案:
if (Build.VERSION.SDK_INT >= 26) {
canvas.clipRect(mClipBounds);
} else {
canvas.clipRect(mClipBounds, Region.Op.UNION);
}
Could not locate ResponseBody converter for
如果想直接接收对象,那要引入gson和converter。不然就只能接收字符串
修改前,是接受字符串类型
new Retrofit.Builder()
.addConverterFactory(ScalarsConverterFactory.create())
修改后,适配器接受gson类型
new Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create(new Gson()))
//升级版:统一gson的本地Date格式
//为了避免使用Gson时遇到locale影响Date格式的问题,使用GsonBuilder来创建Gson对象,
public Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").serializeNulls().create();
new Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create(new Gson()))