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

add input type setting to support running analysis with apk files #15

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

0xera
Copy link
Contributor

@0xera 0xera commented Jan 14, 2025

No description provided.

@0xera 0xera changed the title Draft: add input type setting to support running analysis with apk files add input type setting to support running analysis with apk files Jan 14, 2025
@MinhNguyen-nvm
Copy link
Contributor

Hi @0xera,

Thank you for your contribution and interest in improving App Sizer!

While analyzing APK files directly is an interesting approach, App Sizer is designed to work with Android App Bundles (AAB) for several important reasons:

  1. Android App Bundle is Google's recommended publishing format as it generates optimized APKs for each device configuration, resulting in smaller download sizes for end users. One of the first or most straightforward ways to reduce the app download size is to publish the Android app using the App Bundle format. (most apps should have done it)

  2. By analyzing the generated APKs from App Bundles, App Sizer provides more accurate size metrics that reflect what users actually download from the Play Store.

  3. The plugin follows a specific task dependency chain:

appSizeAnalytics → Generate APK → Generate App Bundle

If you're still interested in APK analysis, you could create a separate Gradle task that depends on assembleRelease/assembleDebug. However, this might not give you the most accurate picture of real-world app sizes since it wouldn't account for the optimizations that App Bundles provide.

@0xera
Copy link
Contributor Author

0xera commented Jan 17, 2025

Hi. Thanks for the great plugin.

We understand the basic idea behind AAB analysis, but some other stores don't support it, so it would be more convenient for us to focus on the APK size alone. Additionally, we want to analyze not just the download size, as we have an internal updater within the app that allows us to download only the APK file. I will keep these changes in my fork, and you can close the pull requests if they are not convenient for your plugin

@MinhNguyen-nvm
Copy link
Contributor

MinhNguyen-nvm commented Jan 25, 2025

Hi @0xera, again, thank you for the input and contribution to the tool.

It would be nice if we could also cover APK analytics. However, I suggest integrating APK analytics through a dedicated task rather than different input types. We can create a new task (based on AppSizeAnalysisTask) called apkSizeAnalytics[VariantName].

Task dependency:

apkSizeAnalytics[VariantName] -> assemble[VariantName] 
apkSizeAnalytics[VariantName] -> all module AAR/Jar compilation task

(similar to appSizeAnalytics)

Usage:

./gradlew apkSizeAnalytics[VariantName]

This single command will handle both APK building and analytics execution.

@0xera
Copy link
Contributor Author

0xera commented Jan 25, 2025

done

Copy link
Contributor

@MinhNguyen-nvm MinhNguyen-nvm left a comment

Choose a reason for hiding this comment

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

Happy Lunar New Year - Thank you for your contribution

private fun registerAppSizeTaskDep(
project: Project,
variant: BaseVariant,
appExtension: AppExtension,
depTask: TaskProvider<out Task>
depTasks: List<TaskProvider<out Task>>
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

Copy link
Contributor

Choose a reason for hiding this comment

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

My idea is something like:

val compileDependenciesTask = project.tasks.register("compileDepe${variant.name}")
 aabSizeAnalysisTask.dependsOn(compileDependenciesTask)
 apkSizeAnalysisTask.dependsOn(compileDependenciesTask)

Then let compileDependenciesTask depend on the module's compilation tasks.

Copy link
Contributor

Choose a reason for hiding this comment

The 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

Do you face OOM error? Let treat it as a separated issue

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah. ok, i will create another PR after this one

0xera added 4 commits February 5, 2025 19:31
Copy link
Contributor

@MinhNguyen-nvm MinhNguyen-nvm left a comment

Choose a reason for hiding this comment

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

Thank you 🙇

apk {
// APK Generation
aab {
// APK Generation from aab
}
Copy link
Contributor

@MinhNguyen-nvm MinhNguyen-nvm Feb 6, 2025

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

registerAppSizeTaskDep(project, variant, this, appSizeAnalysisTask)
runCatching {
registerCollectDependenciesTask(project, variant, this)
}.onFailure {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we still crash Gradle to print a full stacktrace?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

sample/README.md Outdated
```
./gradlew app:apkSizeAnalysisProRelease --no-configure-on-demand
```
If you need to analyze apk files generated from the aab file according to device specs:
Copy link
Contributor

Choose a reason for hiding this comment

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

Let keeps the appSizeAnalysis* as the default. I would propose to have

2. Execute the following command to analyze the apks generated from the aab file according to device specs:

./gradlew app:appSizeAnalysisProRelease --no-configure-on-demand

Or if you need to analyze apk file only, you can execute the following command:

./gradlew app:apkSizeAnalysisProRelease --no-configure-on-demand

Copy link
Contributor

Choose a reason for hiding this comment

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

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.

None yet

2 participants