如何在应用程序中添加比库更多的构建类型 [英] How to add more build types in app than library

查看:1217
本文介绍了如何在应用程序中添加比库更多的构建类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

就像这里的示例一样扩展我的构建类型以添加​​分段:

  android {
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
}
debug {
applicationIdSuffix'.debug'
}
staging {
initWith release
applicationIdSuffix'.staging'
}
}
}

但是我也有一个依赖项:
$ b $ pre $ implementation project(' :mylibrary')

编译失败,因为它不知道要配对:mylibrary

  *出了什么问题:
无法检查呃任务的依赖关系:app:compileStagingJavaWithJavac'。
>无法解析配置':app:stagingCompileClasspath'的所有任务依赖关系。
>无法解析项目:mylibrary。
要求:
项目:app
>无法找到项目的匹配配置:mylibrary:
- 配置'debugApiElements':
- 必需的com.android.build.api.attributes.BuildTypeAttr'staging'并找到不兼容的值'debug'。
- 必需的com.android.build.gradle.internal.dependency.AndroidTypeAttr'Aar'并找到兼容值'Aar'。
- 找到com.android.build.gradle.internal.dependency.VariantAttr'debug'但不是必需的。
- 必需的org.gradle.api.attributes.Usage'java-api'并找到兼容值'java-api'。
- 配置'debugRuntimeElements':
- 必需的com.android.build.api.attributes.BuildTypeAttr'staging'并找到不兼容的值'debug'。
- 必需的com.android.build.gradle.internal.dependency.AndroidTypeAttr'Aar'并找到兼容值'Aar'。
- 找到com.android.build.gradle.internal.dependency.VariantAttr'debug'但不是必需的。
- 必需的org.gradle.api.attributes.Usage'java-api'并找到不兼容的值'java-runtime'。
- 配置'releaseApiElements':
- 必需的com.android.build.api.attributes.BuildTypeAttr'暂存'并找到不兼容的值'release'。
- 必需的com.android.build.gradle.internal.dependency.AndroidTypeAttr'Aar'并找到兼容值'Aar'。
- 找到com.android.build.gradle.internal.dependency.VariantAttr'release',但不是必需的。
- 必需的org.gradle.api.attributes.Usage'java-api'并找到兼容值'java-api'。
- 配置'releaseRuntimeElements':
- 必需的com.android.build.api.attributes.BuildTypeAttr'暂存'并找到不兼容的值'release'。
- 必需的com.android.build.gradle.internal.dependency.AndroidTypeAttr'Aar'并找到兼容值'Aar'。
- 找到com.android.build.gradle.internal.dependency.VariantAttr'release',但不是必需的。
- 必需的org.gradle.api.attributes.Usage'java-api'并找到不兼容的值'java-runtime'。

这很公平,但我无法通过添加分段的所有库



我试过:

  debugImplementation项目(路径:':mylibrary',配置:'debug')
releaseImplementation项目(路径:':mylibrary',配置:'release')
stagingImplementation项目path:':mylibrary',configuration:'release')

但它失败:

  *出错:
无法确定任务':app:compileReleaseJavaWithJavac'的依赖关系。
>无法解析配置':app:releaseCompileClasspath'的所有任务依赖关系。
>无法解析项目:mylibrary。
要求:
项目:app
>项目:应用程序声明从配置'releaseImplementation'到配置'release'的一个依赖项,该项目没有在project:mylibrary的描述符中声明。

debugImplementation项目(路径:':mylibrary',配置:'default')
releaseImplementation项目(路径:':mylibrary',配置:'default')
stagingImplementation项目(路径:':mylibrary',配置:'default')

图书馆的建设。我不希望这样,我需要调试来调试库的版本。



我见过这个q ,但它是在执行前和 publishNonDefault true 没有效果,与上面相同的错误。


publishNonDefault已弃用且不再有效。所有变体现已发布。


Gradlew版本4.6

解决方案

Android Gradle Plugin 3.0.0让插件知道在使用应用程序代码编译时使用哪种库回退构建类型,以防库中未找到应用中定义的某种构建类型。

  buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules .pro'
}
debug {
applicationIdSuffix'.debug'
}
staging {
initWith release
applicationIdSuffix'.staging'
matchingFallbacks = ['release']
}
}

更多信息在这里:迁移到Android插件for Gradle 3.0.0


Just like the example here I am extending my build types to add staging:

android {
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            applicationIdSuffix '.debug'
        }
        staging {
            initWith release
            applicationIdSuffix '.staging'
        }
    }
}

But I also have a dependency:

implementation project(':mylibrary')

Compilation fails because it doesn't know what to pair staging to in :mylibrary:

* What went wrong:
Could not determine the dependencies of task ':app:compileStagingJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':app:stagingCompileClasspath'.
   > Could not resolve project :mylibrary.
     Required by:
         project :app
      > Unable to find a matching configuration of project :mylibrary:
          - Configuration 'debugApiElements':
              - Required com.android.build.api.attributes.BuildTypeAttr 'staging' and found incompatible value 'debug'.
              - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
              - Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.
              - Required org.gradle.api.attributes.Usage 'java-api' and found compatible value 'java-api'.
          - Configuration 'debugRuntimeElements':
              - Required com.android.build.api.attributes.BuildTypeAttr 'staging' and found incompatible value 'debug'.
              - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
              - Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.
              - Required org.gradle.api.attributes.Usage 'java-api' and found incompatible value 'java-runtime'.
          - Configuration 'releaseApiElements':
              - Required com.android.build.api.attributes.BuildTypeAttr 'staging' and found incompatible value 'release'.
              - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
              - Found com.android.build.gradle.internal.dependency.VariantAttr 'release' but wasn't required.
              - Required org.gradle.api.attributes.Usage 'java-api' and found compatible value 'java-api'.
          - Configuration 'releaseRuntimeElements':
              - Required com.android.build.api.attributes.BuildTypeAttr 'staging' and found incompatible value 'release'.
              - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
              - Found com.android.build.gradle.internal.dependency.VariantAttr 'release' but wasn't required.
              - Required org.gradle.api.attributes.Usage 'java-api' and found incompatible value 'java-runtime'.

That's fair enough, but I cannot go through all of my libraries adding staging just to get a different application suffix.

I tried:

debugImplementation project(path: ':mylibrary', configuration: 'debug')
releaseImplementation project(path: ':mylibrary', configuration: 'release')
stagingImplementation project(path: ':mylibrary', configuration: 'release')

But it fails:

* What went wrong:
Could not determine the dependencies of task ':app:compileReleaseJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':app:releaseCompileClasspath'.
   > Could not resolve project :mylibrary.
     Required by:
         project :app
      > Project :app declares a dependency from configuration 'releaseImplementation' to configuration 'release' which is not declared in the descriptor for project :mylibrary.

debugImplementation project(path: ':mylibrary', configuration: 'default')
releaseImplementation project(path: ':mylibrary', configuration: 'default')
stagingImplementation project(path: ':mylibrary', configuration: 'default')

This works but every build has release build of library. I don't want that, I need debug to have debug version of library.

I've seen this q, but it's pre "implementation" and publishNonDefault true had no effect, same error as above.

publishNonDefault is deprecated and has no effect anymore. All variants are now published.

Gradlew version 4.6

解决方案

Been here, done that :P

You'll need to specify matchingFallback with the Android Gradle Plugin 3.0.0 for the plugin to know which fallback build type of library to use when being compiled with app code in case a certain build type defined in your app is not found in library.

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    debug {
        applicationIdSuffix '.debug'
    }
    staging {
        initWith release
        applicationIdSuffix '.staging'
        matchingFallbacks = ['release']
    }
}

More info here: Migrate to Android Plugin for Gradle 3.0.0.

这篇关于如何在应用程序中添加比库更多的构建类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆