I have read some question's answer on stackoverflow about how to prevent an app from being shared after downloading it form Google Play Store. Such as:
Adding Google Play Licensing: How to secure an Android app against sharing apps like ShareIT & more?
Adding Google Play Licensing and In-app Billing: How to prevent android app being downloaded outside google play
In some places, I have also seen Google Play Licensing can be cracked with some third party softwares or rooting the device. Such a video's link of youtube: How To Remove License Verification From All Android Apps
However, the video was uploaded three years ago, so I don't know if it will work in 2020 or there might be other new ways of doing it.
So, is it a better option to publish an app with in-app billing/purchase to avoid piracy or it also have some drawbacks?