聊聊 Apache 开源协议



对本文有任何问题,可加我的个人微信询问:kymjs666

事出有因

前些天有朋友提醒我,KJFrameForAndroid中的DB模块使用的是基于afinal的finalDB模块确没有在代码中给出声明。对此我很抱歉,已经立即加上了。其实在旧版本的时候我是保留了对finalDB的引用声明和作者信息,后来经过一次重构后却忘记补上了。

开源协议

现在开源社区常用的开源协议有MIT LicenseGPLApache License。但是想必大家都没有完整的看过开源协议内容吧,其实之前我自己也没有看过,毕竟全英文又不是什么技术文档,谁去看那东西。
不过没关系,花了一个多星期,我已经把Apache License翻译了一遍,大家可以看这里,其他的一些主流开源协议也将陆续翻译出来。

今天,咱们就来聊聊开源协议。

首先,作为程序员,我们肯定都知道,Android系统是开源的。但是是基于什么协议开源你知道吗?Android内核是Linux内核,使用了GPL代码,而GPL代码规定所有使用了GPL代码的代码,必须开源。
但是,你知道吗,Android中真正使用了GPL代码的部分非常少,仅仅是一个Linux Kernel,也就是只有一个内核(当然,这并不是说不重要)。

这就是说,与传统Linux发行版相比,只有系统的底层结构是一样的,其他东西在Android里都不一样,尤其是程序员的编程接口是完全不同的。因此,Android应用程序都必须重新写过,现存的Linux程序无法移植上去。

那么,Android只采用kernel、而不是完全采用GPL开源应用,到底是什么?
台湾的科技网志MMDays一语道破真相:

"Linux kernel 的版权是 GPL。 这下问题来了:如果你是硬件厂商,希望你的硬件能在 Linux kernel 下运作,那么就必须要有驱动程序。如果驱动程序的程序代码公开,等于硬件规格也公开的差不多了。许多厂商不愿意这么做,所以就提供编好的驱动程序,但不提供原始码。 Android 的重点就是商业应用,Google采用了一些手法来绕过这问题。他们把驱动程序移到 "userspace",也就是说,把驱动程序变成在 Linux kernel 上头跑,而不是一起跑的东西,这样就可以避过GPL。然后,在 kernel 这边开个小门,让本来不能直接控制到硬件的 "userspace" 程序也可以碰得到,这样只要把"开个小门"的程序代码公布就行啦。"

这就又说回了我们今天的问题:开源协议有什么不同。
关于这个问题,网上有一张很著名的图,相信大家都看过 Android, kotlin, 开源实验室

Apache License

再来说回Apache协议,上文可以看出Android选择了Apache协议开源,就是因为Apache协议允许使用了本协议开源的代码不必开源。这一点,我们可以看协议的第四条:

(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and

(b) You must cause any modified files to carry prominent notices stating that You changed the files; and

(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and

(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.

意思也就是说,如果你用了Apache协议的开源代码,必须保留协议文本。你可以修改源码,但必须声明你修改了哪些,并且保留原开源项目中原作者的信息。

以及第五条:

Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.

除非贡献提交者明确声明,否则任何被合并到项目中的代码,认为在无任何附加条款下符合本许可证的条款。尽管有上述规定,在遵循许可证颁发者的声明的前提下,你也可以添加附加条款。

一句话

最后,用一句话概括Apache License就是,你可以用这代码,但是如果开源你必须保留我写的声明;你可以改我的代码,但是如果开源你必须写清楚你改了哪些;你可以加新的协议要求,但不能与我所公布的协议要求产生冲突;你用这代码干什么我不管,但是你不能让我承担任何责任。 kymjs.com/qiniu