Created
March 14, 2020 11:03
-
-
Save pgreze/7d17de37cf5b2541be54302414900956 to your computer and use it in GitHub Desktop.
Android custom Plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.android.build.gradle | |
import com.android.build.gradle.api.ApplicationVariant | |
import com.android.build.gradle.api.BaseVariant | |
import com.android.build.gradle.api.BaseVariantOutput | |
import com.android.build.gradle.internal.ExtraModelInfo | |
import com.android.build.gradle.internal.dependency.SourceSetManager | |
import com.android.build.gradle.internal.dsl.BuildType | |
import com.android.build.gradle.internal.dsl.ProductFlavor | |
import com.android.build.gradle.internal.dsl.SigningConfig | |
import com.android.build.gradle.internal.scope.GlobalScope | |
import com.android.build.gradle.options.ProjectOptions | |
import org.gradle.api.NamedDomainObjectContainer | |
import org.gradle.api.Project | |
import org.gradle.api.internal.CollectionCallbackActionDecorator | |
import org.gradle.api.internal.DefaultDomainObjectSet | |
open class CustomExtension( | |
project: Project, | |
projectOptions: ProjectOptions, | |
globalScope: GlobalScope, | |
buildTypes: NamedDomainObjectContainer<BuildType>, | |
productFlavors: NamedDomainObjectContainer<ProductFlavor>, | |
signingConfigs: NamedDomainObjectContainer<SigningConfig>, | |
buildOutputs: NamedDomainObjectContainer<BaseVariantOutput>, | |
sourceSetManager: SourceSetManager, | |
extraModelInfo: ExtraModelInfo | |
) : BaseExtension( | |
project, | |
projectOptions, | |
globalScope, | |
buildTypes, | |
productFlavors, | |
signingConfigs, | |
buildOutputs, | |
sourceSetManager, | |
extraModelInfo, | |
false | |
), TestAndroidConfig { | |
private val applicationVariantList = DefaultDomainObjectSet( | |
ApplicationVariant::class.java, | |
CollectionCallbackActionDecorator.NOOP | |
) | |
private var _targetProjectPath: String? = null | |
/** @see TestExtension.getTestBuildType */ | |
override fun getTestBuildType(): String? = null | |
override fun addVariant(variant: BaseVariant?) { | |
applicationVariantList.add(variant as ApplicationVariant) | |
} | |
override fun getTargetProjectPath(): String? = _targetProjectPath | |
/** @see TestExtension.getTargetVariant */ | |
override fun getTargetVariant(): String = "" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.github.pgreze | |
import android.databinding.tool.DataBindingBuilder | |
import com.android.build.gradle.AndroidBlackBoxExtension | |
import com.android.build.gradle.BaseExtension | |
import com.android.build.gradle.BasePlugin | |
import com.android.build.gradle.api.BaseVariantOutput | |
import com.android.build.gradle.internal.ExtraModelInfo | |
import com.android.build.gradle.internal.TaskManager | |
import com.android.build.gradle.internal.dependency.SourceSetManager | |
import com.android.build.gradle.internal.dsl.BuildType | |
import com.android.build.gradle.internal.dsl.ProductFlavor | |
import com.android.build.gradle.internal.dsl.SigningConfig | |
import com.android.build.gradle.internal.scope.GlobalScope | |
import com.android.build.gradle.internal.variant.VariantFactory | |
import com.android.build.gradle.options.ProjectOptions | |
import com.android.builder.model.AndroidProject | |
import com.android.builder.profile.Recorder | |
import com.google.wireless.android.sdk.stats.GradleBuildProject | |
import org.gradle.api.NamedDomainObjectContainer | |
import org.gradle.api.Project | |
import org.gradle.api.component.SoftwareComponentFactory | |
import org.gradle.kotlin.dsl.apply | |
import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry | |
import com.android.build.gradle.internal.plugins.BasePlugin as InternalBasePlugin | |
open class CustomPlugin : BasePlugin() { | |
override fun apply(target: Project) { | |
target.apply<InternalCustomPlugin>() | |
} | |
} | |
open class InternalCustomPlugin( | |
registry: ToolingModelBuilderRegistry, | |
componentFactory: SoftwareComponentFactory | |
) : InternalBasePlugin(registry, componentFactory) { | |
override fun getProjectType(): Int = AndroidProject.PROJECT_TYPE_TEST | |
override fun createExtension( | |
project: Project, | |
projectOptions: ProjectOptions, | |
globalScope: GlobalScope, | |
buildTypeContainer: NamedDomainObjectContainer<BuildType>, | |
productFlavorContainer: NamedDomainObjectContainer<ProductFlavor>, | |
signingConfigContainer: NamedDomainObjectContainer<SigningConfig>, | |
buildOutputs: NamedDomainObjectContainer<BaseVariantOutput>, | |
sourceSetManager: SourceSetManager, | |
extraModelInfo: ExtraModelInfo | |
): BaseExtension = project.extensions.create( | |
"android", | |
CustomExtension::class.java, | |
project, | |
projectOptions, | |
globalScope, | |
buildTypeContainer, | |
productFlavorContainer, | |
signingConfigContainer, | |
buildOutputs, | |
sourceSetManager, | |
extraModelInfo | |
) | |
override fun getAnalyticsPluginType(): GradleBuildProject.PluginType = | |
GradleBuildProject.PluginType.UNKNOWN_PLUGIN_TYPE | |
override fun createVariantFactory(globalScope: GlobalScope?): VariantFactory { | |
TODO("not implemented") | |
} | |
override fun pluginSpecificApply(project: Project?) { | |
TODO("not implemented") | |
} | |
override fun createTaskManager( | |
globalScope: GlobalScope?, | |
project: Project?, | |
projectOptions: ProjectOptions?, | |
dataBindingBuilder: DataBindingBuilder?, | |
extension: BaseExtension?, | |
variantFactory: VariantFactory?, | |
toolingRegistry: ToolingModelBuilderRegistry?, | |
threadRecorder: Recorder? | |
): TaskManager { | |
TODO("not implemented") | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A problem occurred configuring project ':module-abb-test'. | |
> 'kotlin-android' expects one of the Android Gradle plugins to be applied to the project: | |
* android | |
* com.android.application | |
* android-library | |
* com.android.library | |
* com.android.test | |
* com.android.feature | |
* com.android.dynamic-feature | |
* com.android.instantapp | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment