AndroidStudio常见问题

来源:互联网 发布:php导出excel表格乱码 编辑:程序博客网 时间:2024/05/21 06:32

AndroidStudio常见问题:

  1. Error:org.gradle.api.internal.tasks.DefaultTaskInputs$TaskInputUnionFileCollection cannot be cast to org.gradle.api.internal.file.collections.DefaultConfigurableFileCollection
    Possible causes for this unexpected error include:

    • Gradle’s dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
      Re-download dependencies and sync project (requires network)
    • The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
      Stop Gradle build processes (requires restart)
    • Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.
    In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

    这里写图片描述

    系统提示有两种解决问题的方式,我的情况下两种方法都是不可行的。后来发现是因为Gradle版本与当前AndroidStudio使用的版本不一致导致的。

  2. Error:The SDK Build Tools revision (24.0.0) is too low for project ‘:app’. Minimum required is 25.0.0
    Update Build Tools version and sync project
    Open File
    这里写图片描述
    Error:The SDK Build Tools revision (24.0.2) is too low for project ‘:photoedit’. Minimum required is 25.0.0
    Update Build Tools version and sync project
    Open File
    这里写图片描述

    这两种问题性质是一样的,都有两种解决方法。第一种:修改版本号为25.0.0;第二种:点击 Update Build Tools version and sync project直接更新

  3. 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)
    这里写图片描述
    这种问题也是比较常见的,而且点击下载时通常是解决不了问题的。
    解决方式:
    (1)在工程目录下找到gradle文件夹下的gradle-wrapper.properties文件
    这里写图片描述

    (2) 修改distributionUrl=https://services.gradle.org/distributions/gradle-3.3-all.zip的版本号(比如3.3),具体修改成什么版本,参照自己其他的项目
    这里写图片描述
  4. compile、implementation 、 api三者的区别:
    (1).之前在使用AndroidStudio引用外部库的时候,我们通常会使用compile fileTree(include: [‘.jar’], dir: ‘libs’),但是在AndroidStudio升级到3.0版本的时候,又新增了两个引用方式implementation fileTree(dir: ‘libs’, include: [‘.jar’])和api fileTree(include: [‘*.jar’], dir: ‘libs’),而compile 则变成了一个过时的方法。
    (2).其实implementation 和api是将引用的功能进行细化,比如A、B两个module,B是A的依赖库,B中使用implementation 方法依赖glide库,那么如果在A中使用glide库的话需要重新引用;如果B使用的是api方法引用glide库,那么A可以直接使用glide,
    (3).我感觉implementation 相当于类中的private;api相当于类中的public,和compile功能相同。
    这里写图片描述