Android studio问题、错误积累、错误解决方案集锦

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()))

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
解决Android Studio中的连接超时错误可以尝试以下方法: 1. 检查网络连接:确保你的网络连接正常,可以尝试使用其他网络或者重启网络设备。 2. 检查防火墙设置:防火墙可能会阻止Android Studio与Gradle服务器的连接。请确保防火墙允许Android Studio访问网络。 3. 更改Gradle版本:尝试更改项目中的Gradle版本。可以在项目的build.gradle文件中修改Gradle版本号,然后重新同步项目。 4. 使用代理服务器:如果你在使用代理服务器,请确保Android Studio的代理设置正确。可以在Android Studio的设置中找到代理设置,并根据你的代理服务器配置进行相应的设置。 5. 清除Gradle缓存:有时候Gradle缓存可能会导致连接超时错误。可以尝试清除Gradle缓存并重新同步项目。可以在Android Studio的设置中找到Gradle设置,然后点击"清除"按钮来清除缓存。 6. 更新Android Studio和Gradle:确保你使用的是最新版本的Android Studio和Gradle。可以在Android Studio的设置中检查更新,并按照提示进行更新。 7. 检查代理设置:如果你使用了代理服务器,请确保代理设置正确。可以在Android Studio的设置中找到代理设置,并根据你的代理服务器配置进行相应的设置。 8. 重启Android Studio:有时候重启Android Studio可以解决连接超时错误。尝试关闭Android Studio并重新打开。 希望以上方法能够帮助你解决连接超时错误。如果问题仍然存在,请提供更多详细信息以便进一步帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值