简体   繁体   中英

What is best practice to amend an external library in Android?

I'm using an external library to create a customized live streaming app.

Here is the library I'm using:

https://github.com/cine-io/cineio-broadcast-android/tree/master/cineio-broadcast-android-sdk

One of the (few) issues I have with this library is that it forces the phone to use the FRONT camera if there is one. I'd rather force to use the back camera (or have a choice, whatever).

As it is, the class that manages broadcasting in this library does have built-in public methods to choose the camera upon initialization, and its methods are private, so I can't extend it.

My solution has been to download the library locally, compile it as a local project in Gradle (I'm usnig Android Studio). Then I directly amend the library files in my project. It works.

However I'm worried this isn't a very good practice. One issue I can foresee is that the library will get upgraded - and since I'll have made changes locally it'll be very hard to take advantage of new versions of the library.

QUESTION: Is there a best practice when it comes to modifying external libraries? Is it what I am doing, or is there a better way?

Please feel free to provide feedback on the question so I can improve or clarify it as needed.

I would fork the library and push your commits to your fork. Like this you can later on merge changes in the original library to your fork as well.

GitHub has a great collaboration model, that allows you to fork any OSS project easily . You can modify it at will, optionally, push the changes back in a form of pull requests .

Once you have your code ready to build, you can use a full free continuous integration/distribution toolchain, that is built from a cloud-based CI server of your choice ( Codeship , Drone.io , Travis-CI to name a few), a free instance of Artifactory for your SNAPSHOTs (intermediate build results) and Bintray as a distribution platform ( built-in into Android Studio for other people reuse).

Here's a video demonstration of the full stack and here's the documentation of the Artifactory/Bintray part.

You can use reflection ( https://stackoverflow.com/a/11484158 ) but it isn't a good way. I think in your case it will be better to compile module from source and not to update it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM