AAR 模块不适用于 gitlab CI

问题描述 投票:0回答:1

我有一个多模块项目,我需要为我的 aar 创建一个模块。

这是 gradle 文件:

configurations.maybeCreate("default")
artifacts.add("default", file('my-aar-1.0.0.aar'))

还有另一个模块可以实现这个工件。 当我直接从 android studio 运行

./gradlew build
时工作正常,但在我的 CI 脚本中我遇到了这个错误:

Install Android SDK Platform-Tools (revision: 34.0.5) finished.
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':features:app:buildProdBetaPreBundle'.
> Could not resolve all task dependencies for configuration 
':features:app:prodBetaRuntimeClasspath'.
> Could not resolve project :myaar.
 Required by:
     project :app > project :module:secondmodule
  > No matching configuration of project :myaar was found. The consumer was configured to find a runtime of a component, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'beta', attribute 'com.android.build.api.attributes.ProductFlavor:default' with value 'prod', attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '7.4.2', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but:
      - Configuration 'ktlintRuleset':
          - Other compatible attributes:
              - Doesn't say anything about com.android.build.api.attributes.AgpVersionAttr (required '7.4.2')
              - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'beta')
              - Doesn't say anything about com.android.build.api.attributes.ProductFlavor:default (required 'prod')
              - Doesn't say anything about its target Java environment (preferred optimized for Android)
              - Doesn't say anything about its usage (required a runtime)
              - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'androidJvm')

它是我需要从 aar 模块放入 gradle 文件的东西还是我的脚本?

image: public.ecr.aws/openjdk:11jdk-new

variables:
  ANDROID_COMPILE_SDK: "28"
  ANDROID_BUILD_TOOLS: "28.0.2"
  ANDROID_SDK_TOOLS:   "4333796"
  ENVIRONMENT: $CI_COMMIT_REF_NAME
  REGION: $AWS_DEFAULT_REGION

stages:
 - build

lintDebug:
 image: public.ecr.aws/android:latest
 stage: build
 artifacts:
 name: "$CI_JOB_NAME-$CI_COMMIT_REF_NAME"
 when: always
 paths:
  - ./builds/poc-pipeline-android/app/build/outputs/*
 before_script:
- |
  yes | sdkmanager --licenses && \
  yes | sdkmanager --update --channel=0 && \
  yes | sdkmanager \
  "platforms;android-30" \
  "platforms;android-29" \
  "platforms;android-28" \
  "platforms;android-27" \
  "platforms;android-26" \
  "platforms;android-25" \
  "platforms;android-24" \
  "platforms;android-23" \
  "platforms;android-22" \
  "build-tools;30.0.3" \
  "build-tools;30.0.2" \
  "build-tools;30.0.0" \
  "build-tools;29.0.3" \
  "build-tools;29.0.2" \
  "build-tools;29.0.1" \
  "build-tools;29.0.0" \
  "build-tools;28.0.3" \
  "build-tools;28.0.2" \
  "build-tools;28.0.1" \
  "build-tools;28.0.0" \
  "build-tools;27.0.3" \
  "build-tools;27.0.2" \
  "build-tools;27.0.1" \
  "build-tools;27.0.0" \
  "build-tools;26.0.2" \
  "build-tools;26.0.1" \
  "build-tools;25.0.3" \
  "build-tools;24.0.3" \
  "build-tools;23.0.3" \
  "build-tools;22.0.1" \
  "build-tools;21.1.2" \
  "build-tools;19.1.0" \
  "build-tools;17.0.0" \
  "system-images;android-30;google_apis;x86" \
  "system-images;android-29;google_apis;x86" \
  "system-images;android-28;google_apis;x86_64" \
  "system-images;android-26;google_apis;x86" \
  "system-images;android-25;google_apis;armeabi-v7a" \
  "system-images;android-24;default;armeabi-v7a" \
  "system-images;android-22;default;armeabi-v7a" \
  "extras;android;m2repository" \
  "extras;google;m2repository" \
  "extras;google;google_play_services" \
  "extras;m2repository;com;android;support;constraint;constraint-layout;1.0.2" \
  "extras;m2repository;com;android;support;constraint;constraint-layout;1.0.1" \
  "add-ons;addon-google_apis-google-23" \
  "add-ons;addon-google_apis-google-22" \
  "add-ons;addon-google_apis-google-21"
 script:
- ./gradlew build
android gradle gitlab continuous-integration aar
1个回答
0
投票

根据您的描述,在 CI 中运行构建时,您的多模块 Android 项目似乎遇到了 依赖关系解析问题 ,但直接在 Android Studio 中运行时却没有遇到。由于本地设置和 CI 环境之间的环境或配置差异,可能会出现此类问题。

问题:

错误信息表明您的项目

:features:app
依赖于
:myaar
,但
:myaar
的配置不满足
:features:app
指定的所需属性。具体来说,它正在
:myaar
中寻找与某些属性(如
BuildTypeAttr
ProductFlavor
AgpVersionAttr
org.jetbrains.kotlin.platform.type
)匹配的配置。

可能的解决方案:

  1. 确保环境设置的一致性:CI 环境可能是 与您的相比,使用不同版本的工具或依赖项 当地环境。确保Gradle版本和Android SDK 您的本地设置和 CI 之间的版本保持一致 环境。

  2. 正确配置 AAR 模块:在 :myaar 模块的 build.gradle 文件中,确保您已正确设置 配置发布 AAR。它应该包括必要的 诸如 buildType 和flavor 之类的属性。 例如

    android {
        // Your android config
    }
    
    configurations {
        aarConfig
    }
    
    artifacts {
        aarConfig file('path/to/your/aar/file.aar') }
    
  3. 应用程序模块中的依赖配置:在您的应用程序模块中,其中 您正在实施 AAR,请确保依赖关系正确 宣布。例如:

    dependencies {
        implementation project(path: ':myaar', configuration: 'aarConfig')
    }
    
  4. Gradle 和 Android Gradle 插件 (AGP) 版本:确保 Gradle 和 AGP 的版本彼此兼容并且是 两个环境都是一样的。

  5. GitLab CI 配置:检查您的 .gitlab-ci.yml 文件,以确保所有必需的 Android 工具和 SDK 版本都已配置 安装。这些与所需的版本相匹配至关重要 你的项目。

  6. GitLab CI 中的缓存: 有时,CI 中的缓存可能会出现问题。确保您的 CI 管道未使用过时的缓存。您可以尝试清除 在 GitLab CI 中缓存并查看是否可以解决问题。

  7. CI 中使用的 Docker 镜像: CI 管道中使用的 Docker 映像 (public.ecr.aws/openjdk:11jdk-new、public.ecr.aws/android:最新) 应该拥有适合您的所有必要的工具和环境设置 建造。确保该图像适合您的项目需求。

© www.soinside.com 2019 - 2024. All rights reserved.