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

Support packaging proto files into android archives(aar) #414

Merged
merged 3 commits into from
Aug 3, 2020
Merged

Support packaging proto files into android archives(aar) #414

merged 3 commits into from
Aug 3, 2020

Conversation

bennyhuo
Copy link
Contributor

Support packaging proto files into android archives(aar) and extracting included proto files from android libraries. Tested on android gradle plugin v3.6.3. (#56)

@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 with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@bennyhuo
Copy link
Contributor Author

@googlebot I signed it!

@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 then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

…ng included proto files from android libraries. Tested on android gradle plugin v3.6.3. (#56)
@voidzcy
Copy link
Collaborator

voidzcy commented Jun 29, 2020

Are you interested in adding tests for covering the usage of consuming an Android library project? (It might be non-trivial as we cannot reuse testProjectBase to construct an Android Library project, would need to write one with the same proto sources but a build_base.gradle for android build)

@voidzcy voidzcy self-assigned this Jun 29, 2020
@bennyhuo
Copy link
Contributor Author

bennyhuo commented Jun 29, 2020 via email

@google-cla
Copy link

google-cla bot commented Jul 28, 2020

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 then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@bennyhuo
Copy link
Contributor Author

I created a project testProjectAndroidLibrary and simply renamed the helloworld.proto to helloAar.proto with the package name to 'io.grpc.helloaarexample'. And add the library as a dependency to testProjectAndroidBase. Check HelloAarActivity.java.

BTW, there is no need to explicitly exclude proto files in packagingOptions. I have handled it in ProtobufPlugin.groovy:237.

@voidzcy
Copy link
Collaborator

voidzcy commented Jul 28, 2020

BTW, there is no need to explicitly exclude proto files in packagingOptions. I have handled it in ProtobufPlugin.groovy:237.

We want to only include proto files in packaging for android libraries, but not for applications. Applications are very sensitive to the apk size, including proto files in apk increases unnecessary bytes.

It looks the default packagingOption does not include **/*.proto. If that true, we don't need that line.

@bennyhuo
Copy link
Contributor Author

bennyhuo commented Jul 28, 2020

BTW, there is no need to explicitly exclude proto files in packagingOptions. I have handled it in ProtobufPlugin.groovy:237.

We want to only include proto files in packaging for android libraries, but not for applications. Applications are very sensitive to the apk size, including proto files in apk increases unnecessary bytes.

It looks the default packagingOption does not include **/*.proto. If that true, we don't need that line.

The default packaingOption does include proto files. So we should either config that in the project.android.packingOptions in every application project or just make it part of the plugin.

I add these lines to make it default when applied the ProtoBufPlugin, that is to say, if it is a library project, don't exclude **/*.proto, otherwise (it may be an application project or a feature plugin project) exclude all proto files:

        if (!project.android.hasProperty('libraryVariants')) {
          project.android.packagingOptions.exclude("**/*.proto")
        }

We should not include proto files for both apk size and security reasons.

Copy link
Collaborator

@voidzcy voidzcy left a comment

Choose a reason for hiding this comment

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

Mostly LGTM, with a couple of nits.

Thanks for your contribution.

testProjectAndroidLibrary/build.gradle Outdated Show resolved Hide resolved
testProjectAndroidLibrary/src/main/proto/helloAar.proto Outdated Show resolved Hide resolved
testProjectAndroidLibrary/src/main/proto/helloAar.proto Outdated Show resolved Hide resolved
testProjectAndroidLibrary/build.gradle Outdated Show resolved Hide resolved
@voidzcy
Copy link
Collaborator

voidzcy commented Aug 3, 2020

Merging. Thanks for contributing.

@voidzcy voidzcy changed the title Fix #56. Support packaging proto files into android archives(aar). Support packaging proto files into android archives(aar) Aug 3, 2020
@voidzcy voidzcy merged commit 15607b4 into google:master Aug 3, 2020
voidzcy added a commit that referenced this pull request Oct 2, 2020
voidzcy added a commit to voidzcy/protobuf-gradle-plugin that referenced this pull request Oct 2, 2020
voidzcy added a commit that referenced this pull request Oct 2, 2020
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.

3 participants