Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use defaultPublishConfig if possible for android modules #29

Conversation

pavelreiter
Copy link

@pavelreiter pavelreiter commented Dec 1, 2020

Fixes #24

I have prepared fix for #24 by adding compileOnly dependency on android gradle plugin (com.android.tools.build:gradle:3.6.4) and using android project extension to fetch defaultPublishConfig as preferred source of compilationName match.

@qwwdfsad qwwdfsad self-requested a review December 3, 2020 17:13
Copy link
Collaborator

@qwwdfsad qwwdfsad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@@ -48,8 +49,10 @@ class BinaryCompatibilityValidatorPlugin : Plugin<Project> {
project.pluginManager.withPlugin("kotlin-android") {
if (project.name in project.rootProject.ignoredProjects()) return@withPlugin
val extension = project.extensions.getByName("kotlin") as KotlinAndroidProjectExtension
val androidBase = project.extensions.getByName("android") as AndroidBaseExtension
val defaultPublishName = androidBase.defaultPublishConfig ?: "release"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like defaultPublishConfig is obsolete and recommended way to publish an application with maven-publish plugin is not using it: https://developer.android.com/studio/build/maven-publish-plugin.

I see the alternative solution where the user explicitly states the publication name they want to verify, then, if it's missing, we can lookup defaultPublishConfig and then fallback to release. It would be nice to have a test for that.

The project doesn't have the infrastructure for tests yet (it is coming in #28), so the most valuable contribution would be to just put a bunch of sample Android projects into the resources: with legacy maven plugin, with maven-publish and with library flavours and I will take care of the rest.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for the comments.
I will try to look into it and since #28 is merged I will try to include some tests.

@kingargyle
Copy link

Is there any update on this PR on when it might be addressed. We are looking at using this for our android applications, but will need not only non-release support but flavor support as well. Ideally, the apiDump should support something like, apiDumpDebug, apiDumpFlavorDebug, apiDumpRelease, apiDumpFlavorRelease.

@pavelreiter pavelreiter marked this pull request as draft January 28, 2021 14:57
@pavelreiter pavelreiter force-pushed the pavelreiter/bugfix/fix_android_flavored_modules branch from 5e1d3dc to d32240e Compare January 29, 2021 11:23
@SumeraMartin
Copy link

@pavelreiter @qwwdfsad Hi, are you planning to finish this PR? Or do you have any workaround?

@pavelreiter
Copy link
Author

Hi, I am afraid that I have went with metalava for now. I will close the PR.

@pavelreiter pavelreiter closed this Dec 7, 2021
@SumeraMartin
Copy link

I found a hacky workaround. Since I'm using flavors only for changes directly in the code when (BuildConfig.FLAVOR) { ... } and I don't use flavor-specific resources or classes then I'm disabling flavors in build.gradle.kts in case that apiCheck or apiDump task is being executed and I'm adding buildConfigField for FLAVOR with some dummy value. The code will compile fine, the task will succeed and flavors are still in the use. As I said, it is more hack than the correct solution but it works so far.

fun Project.startArgsContains(vararg arguments: String): Boolean {
    val startArgs = project.gradle.startParameter.taskRequests.toString()
    return arguments.any { argument -> startArgs.contains(argument) }
}

android {
    val isKotlinBinaryValidatorTask = project.startArgsContains("apiCheck", "apiDump")

    buildTypes {
        getByName(ProjectSettings.BuildType.DEBUG) {
            ...

            if (isKotlinBinaryValidatorTask) {
                buildConfigField("String", "FLAVOR", "\"dummy\"")
            }
        }
        ...
    }
    
    if (!isKotlinBinaryValidatorTask) {
        flavorDimensions(ProjectSettings.Flavor.DIMENSION)
        productFlavors {
            ...
        }
    }
    ...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to apply plugin to flavored modules
4 participants