-
Notifications
You must be signed in to change notification settings - Fork 8
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
add input type setting to support running analysis with apk files #15
base: master
Are you sure you want to change the base?
Changes from 7 commits
32fe9cb
f223727
4782652
aa20896
bcc4ea6
17fd6ec
01eb4e5
b49011f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,11 @@ appSizer { | |
To run the App Sizer analysis using the Gradle plugin: | ||
|
||
1. Open a terminal in the sample project directory. | ||
2. Execute the following command: | ||
2. Execute one of the following commands: | ||
``` | ||
./gradlew app:apkSizeAnalysisProRelease --no-configure-on-demand | ||
``` | ||
If you need to analyze apk files generated from the aab file according to device specs: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let keeps the appSizeAnalysis* as the default. I would propose to have
./gradlew app:appSizeAnalysisProRelease --no-configure-on-demand
./gradlew app:apkSizeAnalysisProRelease --no-configure-on-demand
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let update the https://github.com/grab/app-sizer/blob/master/docs/plugin.md file as well |
||
``` | ||
./gradlew app:appSizeAnalysisProRelease --no-configure-on-demand | ||
``` | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
package com.grab.plugin.sizer | ||
|
||
import com.android.build.gradle.AppExtension | ||
import com.android.build.gradle.api.ApplicationVariant | ||
import com.android.build.gradle.api.BaseVariant | ||
import com.android.build.gradle.internal.dsl.BuildType | ||
import com.android.build.gradle.internal.dsl.ProductFlavor | ||
|
@@ -37,14 +38,17 @@ import com.grab.plugin.sizer.dependencies.* | |
import com.grab.plugin.sizer.tasks.AppSizeAnalysisTask | ||
import com.grab.plugin.sizer.tasks.GenerateApkTask | ||
import com.grab.plugin.sizer.tasks.GenerateArchivesListTask | ||
import com.grab.plugin.sizer.tasks.capitalize | ||
import com.grab.plugin.sizer.utils.isAndroidApplication | ||
import com.grab.plugin.sizer.utils.isAndroidLibrary | ||
import com.grab.plugin.sizer.utils.isJava | ||
import com.grab.plugin.sizer.utils.isKotlinJvm | ||
import org.gradle.api.Project | ||
import org.gradle.api.Task | ||
import org.gradle.api.artifacts.ProjectDependency | ||
import org.gradle.api.file.Directory | ||
import org.gradle.api.tasks.TaskProvider | ||
import org.gradle.kotlin.dsl.listProperty | ||
import org.gradle.kotlin.dsl.the | ||
|
||
/* | ||
|
@@ -71,55 +75,95 @@ internal class TaskManager( | |
val variantFilter = DefaultVariantFilter(variant) | ||
pluginExtension.input.variantFilter?.execute(variantFilter) | ||
if (!variantFilter.ignored) { | ||
val generateApkTask = GenerateApkTask.registerTask( | ||
project, | ||
pluginExtension, | ||
variant | ||
) | ||
|
||
val generateArchivesListTask = GenerateArchivesListTask.registerTask( | ||
project, | ||
project = project, | ||
variant = variant, | ||
flavorMatchingFallbacks = getProductFlavor(variant)?.matchingFallbacks ?: emptyList(), | ||
buildTypeMatchingFallbacks = getOriginalBuildType(variant).matchingFallbacks, | ||
enableMatchDebugVariant = pluginExtension.input.enableMatchDebugVariant | ||
) | ||
|
||
val appSizeAnalysisTask = AppSizeAnalysisTask.registerTask( | ||
project, | ||
variant, | ||
pluginExtension, | ||
generateApkTask, | ||
generateArchivesListTask, | ||
) | ||
registerAppSizeTaskDep(project, variant, this, appSizeAnalysisTask) | ||
runCatching { | ||
registerCollectDependenciesTask(project, variant, this) | ||
}.onFailure { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we still crash Gradle to print a full stacktrace? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think the crash is very useful in this case. We have a few variants for which we can't create a task graph, but we also don't want to find them all and try to declare them in the variant filter. So we're better off just ignoring the log message |
||
project.logger.error("Can't create tasks for ${project.name} with variant ${variant.name}") | ||
}.onSuccess { collectAppDependenciesTask -> | ||
createAabAnalysisTask(project, variant, generateArchivesListTask).configure { | ||
dependsOn(collectAppDependenciesTask) | ||
} | ||
createApkAnalysisTask(project, variant, generateArchivesListTask).configure { | ||
dependsOn(collectAppDependenciesTask) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun registerAppSizeTaskDep( | ||
private fun createApkAnalysisTask( | ||
project: Project, | ||
variant: ApplicationVariant, | ||
generateArchivesListTask: TaskProvider<GenerateArchivesListTask> | ||
) = AppSizeAnalysisTask.registerTask( | ||
name = "apk", | ||
project = project, | ||
variant = variant, | ||
pluginExtension = pluginExtension, | ||
apkDirectories = variant.packageApplicationProvider.map { | ||
project.objects.listProperty<Directory>().value(listOf(it.outputDirectory.get())) | ||
}, | ||
generateArchivesListTask = generateArchivesListTask, | ||
) | ||
|
||
private fun createAabAnalysisTask( | ||
project: Project, | ||
variant: ApplicationVariant, | ||
generateArchivesListTask: TaskProvider<GenerateArchivesListTask> | ||
): TaskProvider<AppSizeAnalysisTask> { | ||
val generateApkFromAabTask = GenerateApkTask.registerTask( | ||
project, | ||
pluginExtension, | ||
variant | ||
) | ||
|
||
val appSizeAnalysisTask = AppSizeAnalysisTask.registerTask( | ||
name = "app", | ||
project = project, | ||
variant = variant, | ||
pluginExtension = pluginExtension, | ||
apkDirectories = generateApkFromAabTask.map { it.outputDirectories }, | ||
generateArchivesListTask = generateArchivesListTask, | ||
) | ||
|
||
return appSizeAnalysisTask | ||
} | ||
|
||
private fun registerCollectDependenciesTask( | ||
project: Project, | ||
variant: BaseVariant, | ||
appExtension: AppExtension, | ||
depTask: TaskProvider<out Task> | ||
) { | ||
): TaskProvider<Task> { | ||
val dependenciesComponent = DaggerDependenciesComponent.factory().create( | ||
project = project, | ||
variantInput = variant.toVariantInput(), | ||
flavorMatchingFallbacks = appExtension.getProductFlavor(variant)?.matchingFallbacks ?: emptyList(), | ||
buildTypeMatchingFallbacks = appExtension.getOriginalBuildType(variant).matchingFallbacks, | ||
enableMatchDebugVariant = pluginExtension.input.enableMatchDebugVariant | ||
) | ||
val collectDependenciesTask = project.tasks.register("collectAppDependencies${variant.name.capitalize()}") | ||
|
||
val markAsChecked = mutableSetOf<String>() | ||
dfs(project, markAsChecked, dependenciesComponent, depTask) | ||
dfs(project, markAsChecked, dependenciesComponent, collectDependenciesTask) | ||
|
||
return collectDependenciesTask | ||
} | ||
|
||
private fun dfs( | ||
project: Project, | ||
markAsChecked: MutableSet<String>, | ||
dependenciesComponent: DependenciesComponent, | ||
depTask: TaskProvider<out Task> | ||
depTask: TaskProvider<Task> | ||
) { | ||
if (markAsChecked.contains(project.path)) return | ||
markAsChecked.add(project.path) | ||
|
@@ -135,7 +179,7 @@ internal class TaskManager( | |
|
||
private fun handleSubProject( | ||
project: Project, | ||
task: TaskProvider<out Task>, | ||
task: TaskProvider<Task>, | ||
variantExtractor: VariantExtractor | ||
) { | ||
when { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the other comment, I mean, let's keep the "apk" extension as well