欢迎访问移动开发之家(rcyd.net),关注移动开发教程。移动开发之家  移动开发问答|  每日更新

安卓工程错误1,比如如果守护进程运行

来源: 开发者 投稿于  被查看 3673 次 评论:42

安卓工程错误1,比如如果守护进程运行


错误1

  • 错误信息
15:43	Gradle sync failed: Could not find com.android.tools.build:gradle:7.0.2.
			Searched in the following locations:
			- https://jcenter.bintray.com/com/android/tools/build/gradle/7.0.2/gradle-7.0.2.pom
			If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration.
			Required by:
			project :
			Add google Maven repository and sync project
			Open File (847 ms)
  • 解决

    bulid.gradle(项目根目录)文件的相应地方中添加google(),然后同步

错误2

  • 错误信息

    15:21 Project AndroidSerialPort is using the following JDK location when running Gradle:
    C:/Users/XXXX/.jdks/corretto-1.8.0_322
    Using different JDK locations on different processes might cause Gradle to
    spawn multiple daemons, for example, by executing Gradle tasks from a terminal
    while using Android Studio.
    More info...
    Select a JDK
    Do not show this warning again

  • 问题分析

    如果使用守护进程特性会有一个问题,就是可能会出现多个守护进程的场景,这是因为守护进程可能在某些方面无法满足请求构建环境。比如如果守护进程运行在Java 8运行时,但是请求的环境调用Java 10,那么守护进程是不兼容的,必须启动另一个。此外,Java运行时的某些属性在JVM启动后无法更改。这也可能导致出现多个守护进程。

    为了避免出现这种情况,一个最好的解决方式时我们每次使用gradle进行项目构建时,尽量使用相同的JDK配置。

  • 解决办法

    1. 打开项目结构设置窗口,点击Gradle Settings

    2. 选择与其他正常的工程运行的JDK版本路径一致的选项

    3. 同步一下

​ 该问题参考了这里

错误3

  • 错误信息

    Gradle sync failed: Could not find method compile() for arguments [directory 'libs'] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. (17 s 734 ms)

  • 问题分析

    Gradle版本不兼容

  • 解决办法

    将build.gradle里的compile(低)替换成implementation(高),如下:

    修改前

修改后

同步

错误4

  • 错误信息

    Lint infrastructure error
    
  • 问题分析

    收到了同事给的源码包,在打包APK时出现错误,但是我的其他工程是可以正常打包的,怀疑是Gradle相关配置问题。

  • 解决办法

    使用Ctrl+Alt+Shift+s打开项目结构设置

    然后点击同步,重新打包,就好啦~

错误5

  • 错误信息

    An exception occurred applying plugin request [id: 'com.android.application']
    > Failed to apply plugin 'com.android.internal.application'.
       > Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
         You can try some of the following options:
           - changing the IDE settings.
           - changing the JAVA_HOME environment variable.
           - changing `org.gradle.java.home` in `gradle.properties`.
    
    * Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
    
  • 解决办法

    1. 更改编译版本
    2. 更新JDK版本
      File->Project Structure->Gradle Settings,选择合适的jdk,如下11 version 2.或者升级android studio 到最新版本,ok

本文来自博客园,作者:耳东Sir,转载请注明原文链接:https://www.cnblogs.com/erdongsir/p/16900248.html

用户评论