vanniktech / gradle-android-apk-size-plugin

Gradle plugin that generates CSV files with apk size per output and variant of an apk
http://vanniktech.com
Apache License 2.0
84 stars 14 forks source link

[Feature Request] Fail build on "maxApkSize" #48

Closed jaredsburrows closed 7 years ago

jaredsburrows commented 7 years ago

Question:

Can we add an integer such as "maxApkSize" in an extension in order to fail builds that go over a certain size?

Example:

apkSize {
  maxApkSize = 5800000
}

This will help developers that are developing on their local machines not only make better decisions on the code that they write but the libraries they use.

vanniktech commented 7 years ago

That seems like a really good idea. 👍

vanniktech commented 7 years ago

If so it should be splitted though usually debug apk is much bigger than release.

athkalia commented 7 years ago

@vanniktech I am trying to set a limit only for my release build, is this possible?

vanniktech commented 7 years ago

I don't think so. The release hasn't been made. You can try the snapshot though.

athkalia commented 7 years ago

Sorry for the confusion. I mean in the snapshot version 0.4-SNAPSHOT, is there a way to only fail my build (assembleRelease) if the size of the release apk is too large, but not have any rules around sizes for my debug APK?

vanniktech commented 7 years ago

Oh no. There's only one size unfortunately.

athkalia commented 7 years ago

would be cool if you could add that in. as, as you said, the release apk is usually smaller cause of proguard

vanniktech commented 7 years ago

Yeah. If you want you can create a PR for it. I don't have much time to work on this project at the moment.

athkalia commented 7 years ago

I may attempt it, but I've never touched a gradle plugin. Got any suggestions for how to solve this?

vanniktech commented 7 years ago

You can look at the PR that did the initial implementation.

jaredsburrows commented 7 years ago

@athkalia Use gradle:

gradle.taskGraph.afterTask { task ->
    if (gradle.taskGraph.hasTask("assembleRelease")) {
        dexcount {
            maxApkSize = 5800000
        }
    }
}
athkalia commented 7 years ago

the task graph is always going to have an assembleRelease task right? regardless of which task is currently executing, assembleDebug or assembleRelease

jaredsburrows commented 7 years ago

@athkalia No and I didn't mean to use afterTask.

Something like this:

gradle.taskGraph.whenReady { taskGraph ->
    if (taskGraph.hasTask(":app:assembleRelease")) {
        dexcount {
            maxApkSize = 5800000
        }
    }
}

To set dexcount.maxApkSize = 5800000, simply run:

gradlew :app:assembleRelease

Docs: https://docs.gradle.org/current/userguide/tutorial_using_tasks.html#configure-by-dag

athkalia commented 7 years ago

thanks pal, I'll give it a go

athkalia commented 7 years ago

cool pal, it works!! thanks a lot.

Btw it should be apkSize instead of dexcount

jaredsburrows commented 7 years ago

@vanniktech It looks like we need to fix the README.md: https://github.com/vanniktech/gradle-android-apk-size-plugin#configuration.

athkalia commented 7 years ago

I also noticed that in the console this appears btw

The current APK is 2853469 Kb, the current max is: 1 Kb. It should have been bytes not Kb

jaredsburrows commented 7 years ago

@athkalia @vanniktech Should we create an issue for this?

vanniktech commented 7 years ago

Sure.