Skip to content

Conversation

@pranayairan
Copy link
Contributor

Implementation Details
This PR adds support for Android App Bundle . Android App bundle is a new packaging format that helps in reducing app size and enabled new features like dynamic delivery for android apps.

I added a new build command appbundle to the flutter tool and introduced bulding app bundle as another option of building APK.

To test : follow all steps to modify your build.gradle file as listed here https://flutter.io/docs/deployment/android. To generate a android app bundle run following command flutter build appbundle

In my current testing this with my app, I have not found any improvements in app size, since flutter apk build only adding arm file. But as we add support to more architectures for flutter app and add more resources, android app bundle can help in optimizing the app size significantly.

Affected Areas
Flutter tool build section.

Issue Link
#17829

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

@pranayairan
Copy link
Contributor Author

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

bin/flutter Outdated
# FLUTTER_TOOL_ARGS="--checked $FLUTTER_TOOL_ARGS"
# FLUTTER_TOOL_ARGS="$FLUTTER_TOOL_ARGS --observe=65432"
#FLUTTER_TOOL_ARGS="--checked $FLUTTER_TOOL_ARGS"
#FLUTTER_TOOL_ARGS="$FLUTTER_TOOL_ARGS --observe=65432"
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: probably best to leave it as before to avoid churn

'The build process for Android has changed, and the current project configuration\n'
'is no longer valid. Please consult\n\n'
' https://github.com/flutter/flutter/wiki/Upgrading-Flutter-projects-to-build-with-gradle\n\n'
'for details on how to upgrade the project.'
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: indentation is off (each string should be the same indentation)

printError(message, wrap: false);
}
throwToolExit('Try re-installing or updating your Android SDK.');
}
Copy link
Contributor

Choose a reason for hiding this comment

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

can we factor out these checks so that all the commands that care can just call the one method that does all of this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do you think androidSdk is the place where I should add this check? it already has a method validateSdkWellFormed that is doing the major heavy lifting of checking. All this code is doing is printing it on the console and throwing an error.


if(isBuildingBundle){
assembleTask = project.bundleTaskFor(buildInfo);
}else{
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: please use the same format as other places in the file (e.g. argument goes on the next line, spaces after if and before { and around else, etc)

}
final Status status = logger.startProgress(
"Gradle task '$assembleTask'...",
"Gradle task'$assembleTask'...",
Copy link
Contributor

Choose a reason for hiding this comment

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

missing space

@Hixie
Copy link
Contributor

Hixie commented Nov 16, 2018

cc @jason-simmons for detailed review

Thanks so much for this contribution!

@jason-simmons
Copy link
Member

cc @matthew-carroll @sbaranov

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again. If the bot doesn't comment, it means it doesn't think anything has changed.

@pranayairan
Copy link
Contributor Author

I signed it!

@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of all the commit author(s), set the cla label to yes (if enabled on your project), and then merge this pull request when appropriate.

@Hixie Hixie added cla: yes and removed cla: no labels Nov 16, 2018
@googlebot
Copy link

A Googler has manually verified that the CLAs look good.

(Googler, please make sure the reason for overriding the CLA status is clearly documented in these comments.)

Copy link
Member

@jason-simmons jason-simmons left a comment

Choose a reason for hiding this comment

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

Overall approach LGTM

if (bundleFile.existsSync())
return bundleFile;
if (buildInfo.flavor != null) {
// Android Studio Gradle plugin v3 adds flavor to path. for bundle the folder name is flavorModename
Copy link
Member

Choose a reason for hiding this comment

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

nit: would write this as Android Studio Gradle plugin v3 adds the flavor to the path. For the bundle the folder name is the flavor plus the mode name.

return bundleFile;
if (buildInfo.flavor != null) {
// Android Studio Gradle plugin v3 adds flavor to path. for bundle the folder name is flavorModename
bundleFile = fs.file(fs.path.join(project.bundleDirectory.path, buildInfo.flavor+modeName, bundleFileName));
Copy link
Member

Choose a reason for hiding this comment

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

nit: use spaces around operators: flavor + modeName


class GradleProject {
GradleProject(this.buildTypes, this.productFlavors, this.apkDirectory);
GradleProject(this.buildTypes, this.productFlavors, this.apkDirectory,this.bundleDirectory);
Copy link
Member

Choose a reason for hiding this comment

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

nit: add a space after the comma: , this.bundleDirectory


@override
final String description = 'Build an Android App Bundle file from your app.\n\n'
'This command can build debug and release versions app bundle for your application. \'debug\' builds support '
Copy link
Member

Choose a reason for hiding this comment

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

nit: versions of an app bundle

appSize = ' (${getSizeAsMB(apkFile.lengthSync())})';
}
printStatus('Built ${fs.path.relative(apkFile.path)}$appSize.');
}else{
Copy link
Member

Choose a reason for hiding this comment

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

nit: add spaces before and after else

@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of all the commit author(s), set the cla label to yes (if enabled on your project), and then merge this pull request when appropriate.

@Hixie
Copy link
Contributor

Hixie commented Nov 20, 2018

This patch is fantastic, thanks so much for this.

Unfortunately as of today we're in a freeze because of the Flutter Live event, but we'll make sure to land it afterwards. Thanks again for your contribution!

@pranayairan
Copy link
Contributor Author

Awesome :) happy to help. Will circle back after Flutter live.

@zoechi zoechi added platform-android Android applications specifically tool Affects the "flutter" command-line tool. See also t: labels. t: gradle "flutter build" and "flutter run" on Android labels Nov 28, 2018
@ghost
Copy link

ghost commented Dec 1, 2018

@pranayairan Quick Question: Does this work with iOS as well or is it more towards the Android system?

@Taormina
Copy link

Taormina commented Dec 2, 2018

@yeshwanthvshenoy This should be an Android only thing for submission to the Google Play Store. You can read more about app bundles here: https://developer.android.com/guide/app-bundle/

@pranayairan
Copy link
Contributor Author

@Hixie is the restriction for merging lifted? If yes can we merge the changes?

@vandie
Copy link

vandie commented Dec 5, 2018

Just out of interest, is this likely to be merged in any time soon?

@pranayairan
Copy link
Contributor Author

@vandie hoping to get this merged in a day or 2, we were waiting for flutter live to be done.

updating the comment to re-run the test
@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of all the commit author(s), set the cla label to yes (if enabled on your project), and then merge this pull request when appropriate.

@pranayairan pranayairan merged commit 368cd7d into flutter:master Dec 21, 2018
@pranayairan pranayairan deleted the app_bundle branch December 21, 2018 06:18
kangwang1988 added a commit to XianyuTech/flutter that referenced this pull request Dec 26, 2018
* flt_master: (143 commits)
  Roll engine 215ca15..d8c5ec0 (12 commits) (flutter#25728)
  Provide some more locations for the FAB. (flutter#24736)
  Undeprecated BigInteger support, but document what it actually does. (flutter#24511)
  ClipPath.shape and related fixes (flutter#24816)
  Handle errors in `compute()` by propagating them to the Future. (flutter#24848)
  Fix merge conflict. (flutter#25718)
  Some minor tweaks to InputDecoration (mainly docs). (flutter#24643)
  Expose font fallback API in TextStyle, Roll engine 54a3577..215ca15 (8 commits) (flutter#25585)
  Updated Shrine demo (flutter#25674)
  Pin the goldens repo to a specific commit in the android_views test. (flutter#25678)
  Friendlier flags for Dart compilation training. (flutter#25645)
  Revert dependency upgrade to see if it helps with build times and APK size (flutter#25642)
  Depend on the goldens repo through git. (flutter#25479)
  no period after an alone link in see also section (flutter#25604)
  Update links for China help (flutter#25238)
  Roll engine 6a90418..54a3577 (23 commits) (flutter#25649)
  Roll engine e859296..6a90418 (4 commits) (flutter#25643)
  Adding support for android app bundle - Issue flutter#17829 (flutter#24440)
  Revert "[O] Remove many timeouts. (flutter#23531)" (flutter#25646)
  [O] Remove many timeouts. (flutter#23531)
  ...
@massivefermion
Copy link

So... What happened? Is this merged now? If yes, is there any documentation on how to use it?

@Hixie
Copy link
Contributor

Hixie commented Jan 15, 2019

flutter build bundle --help should describe how to use this command. Please file a bug if it's not clear. Thanks!

@alexandranb
Copy link

Hi,

Could you explain on how we could create the bundle and include both versions for 32-bit and 64-bit? For now, my bundle only has armeabi-v7a and I can't seem to figure it out how to include armeabi-v81.

Thanks

@pranayairan
Copy link
Contributor Author

Unfortunately, as of now, it will only include armeabi-v7a. I am not sure if there is armeabi-v81 altogether for flutter. There is an internal code that gets only the armeabi-v7a files for both bundle and APK. I will check if we can generate both.

@creativecreatorormaybenot
Copy link
Contributor

@Hixie Should be flutter build appbundle --help.

@rockwotj
Copy link

rockwotj commented Mar 4, 2019

@pranayairan if you could add an option to generate both 32 bit and 64 bit you would fix #23055

@xiabui
Copy link

xiabui commented Mar 22, 2019

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.

What to do if you already signed the CLA

Individual signers
Corporate signers

I signed it!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

platform-android Android applications specifically t: gradle "flutter build" and "flutter run" on Android tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.