简体   繁体   English

在Android中修改外部库的最佳做法是什么?

[英]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 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. 我对该库所遇到的(几个)问题之一是,如果有这个问题,它将迫使手机使用FRONT相机。 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). 我的解决方案是在本地下载该库,然后将其编译为Gradle中的本地项目(我是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. 这样,您以后就可以将原始库中的更改合并到您的fork中。

GitHub has a great collaboration model, that allows you to fork any OSS project easily . GitHub具有出色的协作模型,可让您轻松分叉任何OSS项目 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). 一旦您准备好构建代码,就可以使用完全免费的连续集成/分发工具链,该工具链是从您选择的基于云的CI服务器( CodeshipDrone.ioTravis-CI等构建的 ,一个免费的Artifactory实例,用于您的SNAPSHOT(中间生成结果),以及Bintray作为发行平台( 内置在Android Studio中,供其他人重复使用)。

Here's a video demonstration of the full stack and here's the documentation of the Artifactory/Bintray part. 这是完整堆栈的视频演示 ,这是Artifactory / Bintray部分的文档

You can use reflection ( https://stackoverflow.com/a/11484158 ) but it isn't a good way. 您可以使用反射( https://stackoverflow.com/a/11484158 ),但这不是一个好方法。 I think in your case it will be better to compile module from source and not to update it. 我认为在您的情况下,最好从源代码编译模块而不是对其进行更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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