我如何在每次构建时,从构建*所有*库模块的构建类型中停止Android的Gradle ?(复制)

时间:2023-01-22 08:41:53

This question already has an answer here:

这个问题已经有了答案:

I'm sure that this has been asked before, but I'm just not finding the right keywords to ferret out answers, so...

我确信之前有人问过这个问题,但我只是找不到合适的关键词来找出答案,所以……

How do I stop Gradle for Android (inside or outside of Android Studio) from building all build types of a library module when I request to build one build type? IOW, if I am building debug, how do I prevent Gradle for Android from also building release?

当我请求构建一个构建类型时,我如何从构建所有构建类型的库模块中停止Android (Android Studio内部或外部)的Gradle ?如果我正在进行调试,那么如何防止Android的Gradle构建版本呢?


The back-story, for those with alternative ideas:

对于那些有其他想法的人来说:

Suppose that I have two Android Studio projects, A and B. Each has two modules: an Android library module and a demo app that depends upon that library. So, I have a total of four modules:

假设我有两个Android Studio项目,分别是A和b,每个都有两个模块:一个是Android库模块,一个是依赖于那个库的演示应用程序。我总共有四个模块

  • AL: project A's library
  • 艾尔:项目的库
  • AD: project A's demo app
  • AD:项目A的演示应用。
  • BL: project B's library
  • 提单:项目B的图书馆
  • BD: project B's demo app
  • BD:项目B的演示应用程序。

So long as A and B are not related, life is good.

只要A和B不相关,生活就好。

But what if I want BL to depend upon AL?

但是如果我想让BL依赖于AL呢?

For release, if I want those libraries to go in a Maven-style artifact repository, I need the release variant of BL to depend upon the published artifact of AL. That way, my BL POM has the right dependency info.

为了释放,如果我想让这些库进入maven风格的工件存储库,我需要BL的版本变体来依赖于已发布的AL.这样,我的BL POM有正确的依赖信息。

For debug, it would be ideal if BL could depend upon the working copy of AL. While setting that up is a bit hacky, I can make it work.

对于调试来说,如果BL可以依赖于AL的工作副本,那将是非常理想的。

But then if I add stuff to AL, such as a new Java class, and I try using it from BL, I can't build. My debug build is perfectly fine AFAICT. However, even though I really really really don't want to do a release build now, Gradle for Android insists upon doing a release build anyway:

但是如果我向AL添加一些东西,比如一个新的Java类,我尝试从BL中使用它,我就不能构建。我的调试构建是完美的AFAICT。然而,即使我真的真的不想做一个发布版本,Android的Gradle仍然坚持做一个发布版本:

$ gradle assembleDebug
:demo:preBuild UP-TO-DATE
:demo:preDebugBuild UP-TO-DATE
:demo:compileDebugNdk UP-TO-DATE
:demo:checkDebugManifest
:demo:preReleaseBuild UP-TO-DATE
:richedit:compileLint
:richedit:copyReleaseLint UP-TO-DATE
:richedit:mergeReleaseProguardFiles UP-TO-DATE
:richedit:preBuild UP-TO-DATE
:richedit:preReleaseBuild UP-TO-DATE
:richedit:checkReleaseManifest
:richedit:prepareReleaseDependencies
:richedit:compileReleaseAidl UP-TO-DATE
:richedit:compileReleaseRenderscript UP-TO-DATE
:richedit:generateReleaseBuildConfig UP-TO-DATE
:richedit:generateReleaseAssets UP-TO-DATE
:richedit:mergeReleaseAssets UP-TO-DATE
:richedit:generateReleaseResValues UP-TO-DATE
:richedit:generateReleaseResources UP-TO-DATE
:richedit:packageReleaseResources
:richedit:processReleaseManifest UP-TO-DATE
:richedit:processReleaseResources
:richedit:generateReleaseSources
:richedit:compileReleaseJava

(where richedit is BL and demo is BD in my nomenclature above)

(在我的术语中,richedit是BL和demo是BD)

I am asking to assemble the debug build, but it still compiles the release build. And the release build cannot compile, because I am trying to have BL use new unreleased stuff from AL.

我要求组装调试构建,但它仍然编译版本构建。发布版本不能编译,因为我想让BL使用新的未发布的东西。

I am reasonably confident, though not 100% certain, that if Gradle for Android would just blithely ignore release when I am trying to build debug, that I would be in OK shape.

我有相当的信心,虽然不是百分百确定,如果Android的Gradle在我尝试构建调试的时候会轻松地忽略发布,那么我将会处于良好的状态。

Of course, there are possible workarounds:

当然,也有可能的变通方法:

  • I could abandon the idea that these are separate libraries and consolidate them into one. I may yet do that. But it sure feels like what I'm trying to do should be possible.

    我可以放弃这样的想法,即它们是独立的库,并将它们合并为一个库。我可能会这样做。但这确实让我觉得我想做的事情应该是可能的。

  • I could not try using the AL changes until I publish a release AL, in which case BL can depend upon the published artifact for both debug and release. However, that seems like it will cause a lot of patchlevel churn in the A project, as my primary consumer "use case" of this new A functionality is B. Just because I have changes in A that pass instrumentation tests does not mean that they'll be what B needs, and I won't know that until I can build B with the changes in A.

    在发布AL之前,我不能尝试使用AL的更改,在这种情况下,BL可以依赖于已发布的工件进行调试和发布。然而,似乎会导致很多patchlevel生产的一个项目,作为我的主要消费者的“用例”这个新功能B .只是因为我有变化,通过仪器测试并不意味着他们将B需要什么,我不会知道,直到我可以构建B的变化。

  • A variation on the above workaround may be SNAPSHOT releases, where I would somehow enable checking for SNAPSHOT releases for debug but not for release or something. However, the mix of Maven, Gradle, Android, and SNAPSHOT all seems rather under-documented, and I have no idea if it's something that I should be pursuing. And, as with the preceding bullet, this still would result in release being built unnecessarily; the build would just succeed in my case.

    上述工作的一个变体可能是快照版本,在这里,我可以通过某种方式检查快照版本的调试,而不是为了发布或其他什么。然而,Maven、Gradle、Android和快照的混合似乎都没有得到充分的证明,我也不知道这是不是我应该追求的东西。和前面的子弹一样,这仍然会造成不必要的释放;在我的案例中,构建将会成功。

Is there some Gradle for Android setting somewhere that I am missing that says debug means just debug?

在Android设置的某个地方是否有某个级别的设置,我想说调试意味着调试?

2 个解决方案

#1


3  

https://*.com/a/27278352/535762 If you fix your problem, I would be interested to know how, because it sure isn't fully functional yet to use gradle builds with only debug in mind.

如果你解决了你的问题,我很有兴趣知道怎么做,因为它还没有完全的功能,只是在考虑调试的时候使用gradle构建。

Here the essential parts:

这里的基本部分:

In the "Build Variants" panel window on the left, you should see both of your modules, and next to them the current "active" variants. For instance

在左边的“Build变体”面板窗口中,您应该看到两个模块,在它们旁边是当前的“活动”变体。例如

app debug 
custom_lib debug

Build > Make Project

Is building every module in the project in their current variant

在项目中构建每个模块的当前版本吗?

https://code.google.com/p/android/issues/detail?id=52962 will require building the release variant of custom_lib, and so you end up building both.

https://code.google.com/p/android/issues/detail?id=52962将需要构建custom_lib的版本变体,所以最终会构建这两个版本。

Use the option that says Make Module app. This option will change from app to lib based on the current selection in the Project panel or based on the current editor, and will always do only what's needed to build the current module.

这个选项将根据项目面板当前的选择或基于当前编辑器的选择,从应用程序切换到lib,并且总是只做构建当前模块所需的内容。

#2


2  

There is a bug here : https://code.google.com/p/android/issues/detail?id=52962

这里有一个bug: https://code.google.com/p/android/addrees/detail? id=52962。

Does Comment #35 i.e.

并评论# 35即。

Try setting this in the dependency project

尝试在依赖项项目中设置这个。

android {
    publishNonDefault true
    ...
}

and this in the project that uses it

在项目中使用它。

dependencies {
    releaseCompile project(path: ':theotherproject', configuration: 'release')
    debugCompile project(path: ':theotherproject', configuration: 'debug')
}

Taken from here: https://code.google.com/p/android/issues/detail?id=66805

来自:https://code.google.com/p/android/issues/detail?id=66805

work for you? Seems to be the one that most people think work, I haven't tried it personally yet.

为你工作?似乎是大多数人认为的工作,我还没有亲自尝试过。

#1


3  

https://*.com/a/27278352/535762 If you fix your problem, I would be interested to know how, because it sure isn't fully functional yet to use gradle builds with only debug in mind.

如果你解决了你的问题,我很有兴趣知道怎么做,因为它还没有完全的功能,只是在考虑调试的时候使用gradle构建。

Here the essential parts:

这里的基本部分:

In the "Build Variants" panel window on the left, you should see both of your modules, and next to them the current "active" variants. For instance

在左边的“Build变体”面板窗口中,您应该看到两个模块,在它们旁边是当前的“活动”变体。例如

app debug 
custom_lib debug

Build > Make Project

Is building every module in the project in their current variant

在项目中构建每个模块的当前版本吗?

https://code.google.com/p/android/issues/detail?id=52962 will require building the release variant of custom_lib, and so you end up building both.

https://code.google.com/p/android/issues/detail?id=52962将需要构建custom_lib的版本变体,所以最终会构建这两个版本。

Use the option that says Make Module app. This option will change from app to lib based on the current selection in the Project panel or based on the current editor, and will always do only what's needed to build the current module.

这个选项将根据项目面板当前的选择或基于当前编辑器的选择,从应用程序切换到lib,并且总是只做构建当前模块所需的内容。

#2


2  

There is a bug here : https://code.google.com/p/android/issues/detail?id=52962

这里有一个bug: https://code.google.com/p/android/addrees/detail? id=52962。

Does Comment #35 i.e.

并评论# 35即。

Try setting this in the dependency project

尝试在依赖项项目中设置这个。

android {
    publishNonDefault true
    ...
}

and this in the project that uses it

在项目中使用它。

dependencies {
    releaseCompile project(path: ':theotherproject', configuration: 'release')
    debugCompile project(path: ':theotherproject', configuration: 'debug')
}

Taken from here: https://code.google.com/p/android/issues/detail?id=66805

来自:https://code.google.com/p/android/issues/detail?id=66805

work for you? Seems to be the one that most people think work, I haven't tried it personally yet.

为你工作?似乎是大多数人认为的工作,我还没有亲自尝试过。