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

Building animal sniffer signatures directly from android corelib #5973

Merged
merged 8 commits into from
Nov 20, 2023

Conversation

LikeTheSalad
Copy link
Contributor

Android corelib or desugar_jdk lib is a jar containing missing JDK8 classes from Android OS versions below API 26. The idea is that apps targeting old Android devices, where said classes are missing, can add those into the app itself to avoid NoClassDefFoundException runtime errors in old devices. More info here.

However, the corelib doesn't have ALL the JDK8 missing classes, so we need to make sure we don't use those in order to avoid Android runtime exceptions. That's where Animal Sniffer helps, by checking our codebase against a signature that contains all the info about the classes available at runtime in old Android devices, both from the OS itself and from the corelib as well.

Since the corelib version of gummy-bears is not currently up-to-date with the latest corelib/desugar lib changes from Google, these changes aim to locally generate our android animal sniffer signature directly from the android lib, while also extending gummy-bears' existing plain (without the corelib parts, just the OS runtime classes) signature by following this guide on how to create/extend signatures for animal sniffer.


dependencies {
signature("com.toasttab.android:gummy-bears-api-21:0.6.1@signature")
signatureJar("com.android.tools:desugar_jdk_libs:2.0.4")
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 tested that it works by adding some code that uses java.util.Base64 and then running the task animalsnifferMain which completed without any issues (since Base64 was added in version 2.0.4). Then I changed this version to 2.0.3 and re-run the animal sniffer task which then failed.

@jack-berg
Copy link
Member

This is awesome! I'm on board with this approach. Gives us more control and centralizes the declaration of all the versions that comprise the android compatibility we ensure.

@trask
Copy link
Member

trask commented Nov 9, 2023

I agree, very nice to be explicit about the desugaring version requirement 👍

@LikeTheSalad
Copy link
Contributor Author

Cool! I'll address the CI issues and move it to ready for review then 👍

Copy link

codecov bot commented Nov 10, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (b03ec3a) 91.12% compared to head (a06a0ac) 91.18%.
Report is 13 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #5973      +/-   ##
============================================
+ Coverage     91.12%   91.18%   +0.05%     
- Complexity     5599     5613      +14     
============================================
  Files           615      616       +1     
  Lines         16519    16566      +47     
  Branches       1639     1642       +3     
============================================
+ Hits          15053    15105      +52     
+ Misses         1014     1013       -1     
+ Partials        452      448       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@LikeTheSalad LikeTheSalad marked this pull request as ready for review November 10, 2023 10:27
@LikeTheSalad LikeTheSalad requested a review from a team November 10, 2023 10:27
Copy link
Member

@jack-berg jack-berg left a comment

Choose a reason for hiding this comment

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

Just a couple of small comments. Thanks for doing this!

@@ -64,6 +64,7 @@ include(":sdk-extensions:autoconfigure-spi")
include(":sdk-extensions:incubator")
include(":sdk-extensions:jaeger-remote-sampler")
include(":testing-internal")
include(":animal-sniffer")
Copy link
Member

Choose a reason for hiding this comment

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

How about animal-sniffer-signature?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure no problem, I've made the changes.


repositories {
mavenCentral()
google()
Copy link
Member

Choose a reason for hiding this comment

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

Let's move google() to the repositories section of settings.gradle.kts, and delete mavenCentral() since its redundant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, it's updated now.


dependencies {
signature("com.toasttab.android:gummy-bears-api-21:0.6.1@signature")
signatureJar("com.android.tools:desugar_jdk_libs:2.0.4")
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to define these in dependencyManagement/build.gradle.kts and omit the versions here?

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 tried with both but it only worked for com.android.tools:desugar_jdk_libs so that's the only one I moved over to dependencyManagement. I'm guessing the @signature part of gummy-bears makes it difficult for Gradle to resolve the artifact when the version is defined elsewhere.

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