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

Specify minimum Android API level (+ add Animal Sniffer to verify this) #2429

Closed
Marcono1234 opened this issue Jul 2, 2023 · 4 comments · Fixed by #2431
Closed

Specify minimum Android API level (+ add Animal Sniffer to verify this) #2429

Marcono1234 opened this issue Jul 2, 2023 · 4 comments · Fixed by #2431

Comments

@Marcono1234
Copy link
Collaborator

Marcono1234 commented Jul 2, 2023

Problem solved by the feature

The README only specifies that Java 7 is the minimum version for the latest Gson versions. However, for Android developers this information is not that helpful because Java 7 API was added in multiple different Android API levels. For example java.lang.ReflectiveOperationException added in Java 7 was only added for Android API level 19 (Android 4.4), see also #2310 (comment).

Feature description

Alternatives / workarounds

none

@Marcono1234
Copy link
Collaborator Author

In 2018 usage of Android devices with API level < 19 was apparently already only at ~5% (in later years this statistic was not published on that webpage anymore). Now at the time of writing the API Version Distribution shown in Android Studio says API level < 21 is ~0,5%.
Google Play services are not updated anymore for versions < 19 either.

So maybe choosing either 19 or 21 as minimum API level might be reasonable (though note that I am not very familiar with Android development, so maybe my judgement is wrong here).
Here are some minimum API levels in other projects:

  • Retrofit: 21
  • OkHttp: 21
  • Picasso: 21
  • Protobuf: 14, respectively 19
  • jsoup: 10
  • JeroMQ: 28
  • Λrrow: 21
  • RxJava: 21
  • Apollo Kotlin: 21
  • Stripe Android SDK: 21

@Marcono1234
Copy link
Collaborator Author

Regarding those net.sf.androidscents.signature Animal Sniffer signature artifacts: Given that multiple of the projects listed above use them, I assume they are safe. The main problem is that this cannot be easily verified because those signature files use Java Serialization (see also mojohaus/animal-sniffer#252), so you cannot that easily verify their content and in the worst case they could allow a remote code execution attack during build.

@eamonnmcmanus
Copy link
Member

Thanks for doing all that detailed research!

According to apilevels.com, API level 21 dates to 2014 and 99.3% of devices are at that level or greater. I think we could be pretty comfortable declaring that future Gson versions will only support that version. People who still need to support older devices can use an older version of Gson.

The Animal Sniffer serialization thing is a bit unsettling. It's probably OK, but if we really wanted to be careful I suppose we could have the check be a separate CI step that does nothing else. So in particular it couldn't modify the compiled binaries, which I would see as the main risk if the signature files were compromised.

@Marcono1234
Copy link
Collaborator Author

Marcono1234 commented Jul 6, 2023

I have done a bit more testing; using the API level 18 signatures showed these unsupported usages:

  • java.util.Objects.equals(Object, Object)
  • java.util.Objects.requireNonNull(Object, String)
  • java.lang.ReflectiveOperationException
  • java.lang.AssertionError.<init>(String, Throwable)

Not sure if for some of them there is desugaring support. But I think either way supporting API level < 19 might be rather inconvenient.

For the API level 19 signatures no unsupported usage was found, so I assume we could also use that as minimum version at first, but at least personally I don't mind if we directly chose 21 as minimum API level instead (even if we might actually support API level 19).

It's probably OK, but if we really wanted to be careful I suppose we could have the check be a separate CI step that does nothing else. So in particular it couldn't modify the compiled binaries, which I would see as the main risk if the signature files were compromised.

That sounds like a good solution for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants