Android实例——AS问题记录
2024-01-02 19:45:07
AS导入项目
- 打开一个正常的项目
- 打开待导入的项目,一般都会报错
- 将正常项目的build.gradle(project)复制到新项目,目的是同步gradle plugin
- 将正常项目的gradle-wrapper.properties中的distributionUrl复制到新项目,目的是同步gradle
Gradle plugin和Gradle版本对应关系
随时可能更新,更具体的可看官网
Gradle plugin和Gradle版本可在File——Project Structure中查看,需要保证上面的最低版本对应
AS导入Jar
将Jar复制到libs,然后右键选择Add As Library
报错Could not create parent directory for lock file
检查gradle user home是否为默认目录
报错Could not find com.android.tools.build:gradle:8.0.0.
按照提示点击Add google Maven repository and sync project
报错Could not resolve all files for configuration ‘:classpath’.
A problem occurred configuring root project 'OTA'.
> Could not resolve all files for configuration ':classpath'.
> Could not resolve com.android.tools.build:gradle:8.0.0.
Required by:
project :
> No matching variant of com.android.tools.build:gradle:8.0.0 was found. The consumer was configured to find a library for use during runtime, compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '8.0' but:
- Variant 'apiElements' capability com.android.tools.build:gradle:8.0.0 declares a library, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares a component for use during compile-time, compatible with Java 11 and the consumer needed a component for use during runtime, compatible with Java 8
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '8.0')
- Variant 'javadocElements' capability com.android.tools.build:gradle:8.0.0 declares a component for use during runtime, and its dependencies declared externally:
- Incompatible because this component declares documentation and the consumer needed a library
- Other compatible attributes:
- Doesn't say anything about its target Java version (required compatibility with Java 8)
- Doesn't say anything about its elements (required them packaged as a jar)
- Doesn't say anything about org.gradle.plugin.api-version (required '8.0')
- Variant 'runtimeElements' capability com.android.tools.build:gradle:8.0.0 declares a library for use during runtime, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares a component, compatible with Java 11 and the consumer needed a component, compatible with Java 8
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '8.0')
- Variant 'sourcesElements' capability com.android.tools.build:gradle:8.0.0 declares a component for use during runtime, and its dependencies declared externally:
- Incompatible because this component declares documentation and the consumer needed a library
- Other compatible attributes:
- Doesn't say anything about its target Java version (required compatibility with Java 8)
- Doesn't say anything about its elements (required them packaged as a jar)
- Doesn't say anything about org.gradle.plugin.api-version (required '8.0')
上面报错关键为组件在JDK11编译,当前环境为Java8
Incompatible because this component declares a component for use during compile-time, compatible with Java 11 and the consumer needed a component for use during runtime, compatible with Java 8
点击File——Project Structure
点击Gradle Settings,选择大于11的SDK(我选择的是17)
报错Could not find method compile() for arguments
修改build.gralde(app),将dependencies中的compile改为implementation
报错Out of memory: Java heap space
help-Change Memory Settings修改堆的大小
在gradle-wrapper.properties设置和元空间大小
org.gradle.jvmargs=-Xmx8192m -XX:MaxPermSize=1024m
怎么改都无效,最后发现是导入的AOSP的Framework.jar参与了编译,将implementation改为compileOnly
compileOnly files('libs\\classes.jar')
文章来源:https://blog.csdn.net/qq_35258036/article/details/135343842
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!