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 and extracting protos in Android aar (take 2) #443

Merged
merged 10 commits into from
Nov 18, 2020

Conversation

voidzcy
Copy link
Collaborator

@voidzcy voidzcy commented Nov 3, 2020

Something was messed up in #440, which changed to have an ExtractIncludeProto task for each source set in Android build. However, ExtractIncludeProto tasks need to match dependency variants before pulling them in (this is configured by configurations created by the Android plugin, so the problem doesn't exist in protobuf dependencies and ExtractProto tasks). So it does not work if ExtractIncludeProto tasks are per source set basis, the build will not be able to determine the right variant of dependencies.

The original approach works. That is, getting dependencies from variant.compileClasspath for each variant. So this makes the way of extracting included protos different for Java projects and Android projects:

  • Java projects extract included protos from each source set's compileProtoPath configuration (which inherits from implementation and compileOnly) as SourceSets are compilation units for Java projects.
  • Android projects extract included proto from each variant's compileClasspath as variants are compilation units for Android projects.

So we will not create compileProtoPath configurations for Android source sets.

We could change Java projects to extract included protos from each SourceSet's compileClasspath with a similar approach to filter dependencies with a RESOURCES ArtifactView. With that, we can get rid of the compileProtoPath configuration, and we would no longer need the extra operation to put main sourceSet's proto into test sourceSet:

inputFiles.from getSourceSets()[sourceSetOrVariantName].compileClasspath


Majority changes in this PR is for adding test coverage for consuming protos defined in Android library dependencies.
testProjectAndroidLibrary is a standalone Android library project that provides some proto definition.
testProjectAndroidDependentBase is similar to testProjectAndroidBase but depends on testProjectAndroidLibrary and its proto definitions imports protos defined in testProjectAndroidLibrary. It covers that for all of application/unitTest/androidTest variants (#447 is created to do the same coverage for existing tests that covers Android applications consuming protos from Java projects, it's important to be covered that test variants can still import protos from dependencies of the variant-under-test).

Dependencies pulled from variant's compileClasspath has a view with "jar" attributes, so they include packaged protos.

@voidzcy voidzcy marked this pull request as draft November 3, 2020 10:22
@voidzcy voidzcy changed the title Add android library proto dependency test Support packaging and extracting protos in Android aar (take 2) Nov 16, 2020
@voidzcy voidzcy marked this pull request as ready for review November 16, 2020 00:27
@voidzcy voidzcy merged commit a06c7ad into google:master Nov 18, 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.

2 participants