美文网首页Android开发经验谈
Android Studio3.0升级后使用注意事项

Android Studio3.0升级后使用注意事项

作者: chasten08 | 来源:发表于2017-12-05 23:25 被阅读410次
  • Gradle plugin最高版本4.*

  • 老的项目在使用新版本时,可能会出现gradle plugin冲突的问题

    Error:Failed to open zip file. Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.) Re-download dependencies and sync project (requires network) Re-download dependencies and sync project (requires network)

    解决方法:去往gradle安装目录(File->Other Settings->Default Settings,然后可以搜索gradle,右侧有Service directory path可以看到你gradle目录),.gradle\wrapper\dists目录下找到和项目的gradle-wrapper.properties里版本号一致的文件(比如gradle-3.3-all)删除,重新编译即可

  • Cannot choose between the following configurations,产生这个问题的原因是项目用引用了其他项目,比如compileproject(:library)
    解决方法:Android Studio3.0以后需要使用如下方式:
    implementation project(path: ':library', configuration: 'default')

  • 伴随着 Android Gradle 插件 2.2 版本的发布,近期 android-apt 作者在官网发表声明证实了后续将不会继续维护 android-apt,并推荐大家使用 Android 官方插件提供的相同能力。也就是说,大约三年前推出的 android-apt 即将告别开发者,退出历史舞台,Android Gradle 插件提供了名为 annotationProcessor的功能来完全代替 android-apt,更换的步骤如下:

    • 移除 Modulebuild.gradle 文件中对 android-apt 的相关配置,也就是删除类似下面的配置:
        buildscript {
            repositories {
                jcenter()
            }
            dependencies {
                classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
            }
        }
        apply plugin: 'com.neenbedankt.android-apt'
  • 将 Module 的 build.gradle 文件中使用 apt 引入的依赖修改为使用 annotationProcessor 进行引入,修改前配置如下:
        dependencies {
          compile 'com.google.dagger:dagger:2.0'
          apt 'com.google.dagger:dagger-compiler:2.0'
        }
  • 修改后配置如下:
        dependencies {
            compile 'com.google.dagger:dagger:2.0'
            annotationProcessor 'com.google.dagger:dagger-compiler:2.0'
        }

目前就遇到了这几个问题,先做记录

相关文章

网友评论

    本文标题:Android Studio3.0升级后使用注意事项

    本文链接:https://www.haomeiwen.com/subject/lnvhixtx.html