Android实例——AS问题记录

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中的java文件参与了运行,将implementation改为compileOnly

compileOnly files('libs\\classes.jar')

报错Google Play requires that apps target API level XX or higher.

谷歌商店上架应用API不小于XX,可在build.gralde(app)的andoird配置里添加lintOptions取消检查

android {
    ......
    lintOptions{
        checkReleaseBuilds false
        abortOnError false
    }
    ......
}

报错-source 1.7 中不支持 lambda 表达式

确保File-Project Structure中的JDK大于1.8

在这里插入图片描述

build.gradle添加如下设置

android {
    ......
    compileOptions{
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

import或open选择目录时显示Loading或点击刷新加载不出新文件夹

点击File-Repair IDE按照步骤修复IDE

你的主机中的软件中止了一个已建立的连接

下载Gradle失败,需要切换到可以下载的网络

Namespace not specified. Specify a namespace in the module’s build file

setting.gradle中include指定的每一个模块的build.gradle都要添加namespace

android {
    namespace "包名"
    ......
 }

No cached version available for offline mode

Settings-Builds, Execution, Deployment-Gradle下面将Offline work取消

在这里插入图片描述

如果上面没有,则可能是Compiler参数添加了offline

在这里插入图片描述

  • 14
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值