Android实例——AS问题记录

AS导入项目

  • 打开一个正常的项目
  • 打开待导入的项目,一般都会报错
  • 将正常项目的build.gradle(project)复制到新项目,目的是同步gradle plugin
  • 将正常项目的gradle-wrapper.properties中的distributionUrl复制到新项目,目的是同步gradle

Gradle plugin和Gradle版本对应关系

随时可能更新,更具体的可看官网

Android实例——AS问题记录_第1张图片

Gradle plugin和Gradle版本可在File——Project Structure中查看,需要保证上面的最低版本对应

Android实例——AS问题记录_第2张图片

AS导入Jar

将Jar复制到libs,然后右键选择Add As Library

Android实例——AS问题记录_第3张图片

报错Could not create parent directory for lock file

检查gradle user home是否为默认目录

Android实例——AS问题记录_第4张图片

报错Could not find com.android.tools.build:gradle:8.0.0.

Android实例——AS问题记录_第5张图片

按照提示点击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

Android实例——AS问题记录_第6张图片

点击Gradle Settings,选择大于11的SDK(我选择的是17)

Android实例——AS问题记录_第7张图片

报错Could not find method compile() for arguments

修改build.gralde(app),将dependencies中的compile改为implementation

报错Out of memory: Java heap space

help-Change Memory Settings修改堆的大小

Android实例——AS问题记录_第8张图片

在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

Android实例——AS问题记录_第9张图片

build.gradle添加如下设置

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

你可能感兴趣的:(#,Android实例,android,开发语言,android,studio)