-
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 3 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 | ||
|
@@ -44,7 +45,9 @@ 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,38 +74,67 @@ 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) | ||
val aabSizeAnalysisTask = createAabAnalysisTask(project, variant, generateArchivesListTask) | ||
val apkSizeAnalysisTask = createApkAnylysisTask(project, variant, generateArchivesListTask) | ||
|
||
registerAppSizeTaskDep(project, variant, this, listOf(aabSizeAnalysisTask, apkSizeAnalysisTask)) | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun createApkAnylysisTask( | ||
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 aabSizeAnalysisTask = AppSizeAnalysisTask.registerTask( | ||
name = "aab", | ||
project = project, | ||
variant = variant, | ||
pluginExtension = pluginExtension, | ||
apkDirectories = generateApkFromAabTask.map { it.outputDirectories }, | ||
generateArchivesListTask = generateArchivesListTask, | ||
) | ||
|
||
return aabSizeAnalysisTask | ||
} | ||
|
||
private fun registerAppSizeTaskDep( | ||
project: Project, | ||
variant: BaseVariant, | ||
appExtension: AppExtension, | ||
depTask: TaskProvider<out Task> | ||
depTasks: List<TaskProvider<out Task>> | ||
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. We could reduce the task dependencies graph by adding a dummy task that depends on other jar/aar generation tasks. And let the App size analysis & APK analysis tasks depend on that single task. 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 know about the improvement before. Could you please explain how it works? 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 think that generateArchivesListTask should be run after the assemble task, because it takes a lot of memory to run two tasks in parallel 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. My idea is something like:
Then let compileDependenciesTask depend on the module's compilation tasks. 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.
Do you face OOM error? Let treat it as a separated issue 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. yeah. ok, i will create another PR after this one |
||
) { | ||
val dependenciesComponent = DaggerDependenciesComponent.factory().create( | ||
project = project, | ||
|
@@ -112,46 +144,46 @@ internal class TaskManager( | |
enableMatchDebugVariant = pluginExtension.input.enableMatchDebugVariant | ||
) | ||
val markAsChecked = mutableSetOf<String>() | ||
dfs(project, markAsChecked, dependenciesComponent, depTask) | ||
dfs(project, markAsChecked, dependenciesComponent, depTasks) | ||
} | ||
|
||
private fun dfs( | ||
project: Project, | ||
markAsChecked: MutableSet<String>, | ||
dependenciesComponent: DependenciesComponent, | ||
depTask: TaskProvider<out Task> | ||
depTasks: List<TaskProvider<out Task>> | ||
) { | ||
if (markAsChecked.contains(project.path)) return | ||
markAsChecked.add(project.path) | ||
handleSubProject(project, depTask, dependenciesComponent.variantExtractor()) | ||
handleSubProject(project, depTasks, dependenciesComponent.variantExtractor()) | ||
dependenciesComponent.configurationExtractor() | ||
.runtimeConfigurations(project) | ||
.flatMap { configuration -> | ||
configuration.dependencies.withType(ProjectDependency::class.java) | ||
}.forEach { | ||
dfs(it.dependencyProject, markAsChecked, dependenciesComponent, depTask) | ||
dfs(it.dependencyProject, markAsChecked, dependenciesComponent, depTasks) | ||
} | ||
} | ||
|
||
private fun handleSubProject( | ||
project: Project, | ||
task: TaskProvider<out Task>, | ||
tasks: List<TaskProvider<out Task>>, | ||
variantExtractor: VariantExtractor | ||
) { | ||
when { | ||
project.isAndroidLibrary -> { | ||
val variant = variantExtractor.findMatchVariant(project) | ||
if (variant is AndroidAppSizeVariant) { | ||
task.dependsOn(variant.baseVariant.assembleProvider) | ||
tasks.forEach { it.dependsOn(variant.baseVariant.assembleProvider) } | ||
} | ||
} | ||
|
||
project.isKotlinJvm -> { | ||
task.dependsOn(project.tasks.named("jar")) | ||
tasks.forEach { it.dependsOn(project.tasks.named("jar")) } | ||
} | ||
|
||
project.isJava -> { | ||
task.dependsOn(project.tasks.named("jar")) | ||
tasks.forEach { it.dependsOn(project.tasks.named("jar")) } | ||
} | ||
} | ||
|
||
|
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