使用Fabric插件为具有groovy插件DSL的Crashlytics建立版本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用Fabric插件为具有groovy插件DSL的Crashlytics建立版本相关的知识,希望对你有一定的参考价值。

我使用Crashlytics和Crashlytics gradle文档中记录的标准Gradle设置,完美构建了一个android应用程序。我正在使用Android Studio 3.2.1,Gradle 4.6 Android插件版本3.2.1,

作为稍后将构建脚本转换为Kotlin的准备工作的一部分,我删除了buildscript并应用了plugin子句,并用gradle support和Kotlin要求的plugins子句替换了它们。我已经看到纯Kotlin项目成功地做到了这一点,但是无法使用Groovy来完成这个中间/准备步骤。 plugins子句出现此错误:

Crashlytics was applied to a project without an Android plugin. Please make sure the Crashlytics plugin is applied after the appropriate Android plugin for your project.

由于Fabric插件在gradle插件门户中不存在(尚未?),因此我正在使用settings.gradle,这部分工作正常。它发现Fabric东西没问题:

pluginManagement {
    repositories {
        jcenter()
        google()
        maven { url "https://maven.google.com" }
        gradlePluginPortal()
        maven { url "https://maven.fabric.io/public" }
    }
    resolutionStrategy {
        eachPlugin {
            switch (requested.id.id) {
                case "com.android.application":
                    useModule("com.android.tools.build:gradle:${requested.version}")
                    break
                case "io.fabric":
                    useModule("io.fabric.tools:gradle:${requested.version}")
                    break
            }
        }
    }
}
include ':app'

开关中是否存在com.android.application情况似乎并不重要,两种方式的行为都相同。

应用程序的build.gradle中的相应插件子句如下:

plugins {
    id "com.android.application"
    id "signing"
    id "io.fabric" version "1.27.0"
}

如果有用,则来自构建中同步尝试的完整异常堆栈如下所示:

Caused by: org.gradle.internal.exceptions.LocationAwareException: Build file 'D:WorkingMonay	runkappuild.gradle' line: 5
An exception occurred applying plugin request [id: 'io.fabric', version: '1.27.0', artifact: 'io.fabric.tools:gradle:1.27.0']
    at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.applyPlugin(DefaultPluginRequestApplicator.java:232)
    at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.applyPlugins(DefaultPluginRequestApplicator.java:148)
    at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:184)
    at org.gradle.configuration.BuildOperationScriptPlugin$1.run(BuildOperationScriptPlugin.java:61)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
    at org.gradle.configuration.BuildOperationScriptPlugin.apply(BuildOperationScriptPlugin.java:58)
    at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:41)
    at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:26)
    at org.gradle.configuration.project.ConfigureActionsProjectEvaluator.evaluate(ConfigureActionsProjectEvaluator.java:34)
    at org.gradle.configuration.project.LifecycleProjectEvaluator.doConfigure(LifecycleProjectEvaluator.java:64)
    ... 84 more
Caused by: org.gradle.api.plugins.InvalidPluginException: An exception occurred applying plugin request [id: 'io.fabric', version: '1.27.0', artifact: 'io.fabric.tools:gradle:1.27.0']
    at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.exceptionOccurred(DefaultPluginRequestApplicator.java:247)
    at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.applyPlugin(DefaultPluginRequestApplicator.java:229)
    ... 96 more
Caused by: org.gradle.api.internal.plugins.PluginApplicationException: Failed to apply plugin [id 'io.fabric']
    at org.gradle.api.internal.plugins.DefaultPluginManager.doApply(DefaultPluginManager.java:150)
    at org.gradle.api.internal.plugins.DefaultPluginManager.apply(DefaultPluginManager.java:125)
    at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator$3.run(DefaultPluginRequestApplicator.java:151)
    at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.applyPlugin(DefaultPluginRequestApplicator.java:225)
    ... 96 more
Caused by: org.gradle.api.GradleException: Crashlytics was applied to a project without an Android plugin. Please make sure the Crashlytics plugin is applied after the appropriate Android plugin for your project.
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83)
    at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:105)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:247)
    at com.crashlytics.tools.gradle.ExternalPluginsState.deriveFrom(ExternalPluginsState.groovy:23)
    at com.crashlytics.tools.gradle.ExternalPluginsState$deriveFrom.call(Unknown Source)
    at com.crashlytics.tools.gradle.CrashlyticsPlugin.apply(CrashlyticsPlugin.groovy:50)
    at com.crashlytics.tools.gradle.CrashlyticsPlugin.apply(CrashlyticsPlugin.groovy)
    at org.gradle.api.internal.plugins.ImperativeOnlyPluginTarget.applyImperative(ImperativeOnlyPluginTarget.java:42)
    at org.gradle.api.internal.plugins.RuleBasedPluginTarget.applyImperative(RuleBasedPluginTarget.java:50)
    at org.gradle.api.internal.plugins.DefaultPluginManager.addPlugin(DefaultPluginManager.java:164)
    at org.gradle.api.internal.plugins.DefaultPluginManager.access$200(DefaultPluginManager.java:47)
    at org.gradle.api.internal.plugins.DefaultPluginManager$AddPluginBuildOperation.run(DefaultPluginManager.java:252)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
    at org.gradle.api.internal.plugins.DefaultPluginManager.doApply(DefaultPluginManager.java:144)
    ... 99 more

由于某种原因,Crashlytics插件无法以这种方式看到android应用程序插件。有人知道我在做什么错吗,或者对plugins子句的这种使用是否可以与Fabric插件一起使用?预先感谢您的任何帮助

答案

对于其他遇到此问题的人,简单的解决方法是跳过在plugins{}块中应用该插件,而是稍后在构建脚本中应用它(即使紧随plugins{}块之后也可以):

plugins {
    id("com.android.application")
    id("io.fabric") version("1.27.0") apply(false)
}
apply plugin: 'io.fabric'

以上是关于使用Fabric插件为具有groovy插件DSL的Crashlytics建立版本的主要内容,如果未能解决你的问题,请参考以下文章

Android Gradle 插件Gradle 构建机制 ② ( Groovy 语言 DSL 特性 | settings.gradle 配置文件解析 | 配置子模块工程目录 | 顶层配置 )

Android插件的Gradle基础

传递变量 beetwen groovy 文件

Android Gradle开发指南

如何使用 Jenkins job dsl 为 gitlab 插件设置秘密令牌?

Jenkins Pipeline 插件十大最佳实践!