上次我使用Android Studio时,它使用mavencentral()构建脚本存储库生成.gradle文件,而现在有jcenter()。

有人能解释一下与此相关的问题吗?还有其他的回购吗?我们什么时候换?它们对项目、模块、库有什么影响?Android开发者还有其他需要注意的问题吗?

谁负责维护这些回购?


当前回答

我也想知道,我没有明确的答案,但我想也许值得分享我学到的(一点点)。我发现在谷歌代码的一个问题中提到了从Maven中心到JCenter的移动,但没有发现具体发生的细节——在Android Studio的最近更改列表中没有找到提及。

From reading up on JCenter, it is the repository behind Bintray, from the company JFrog (who I've come across before, and I guess that's where the 'J' comes from). According to the Bintray blog, Bintray is a superset of Maven Central, so if that's true there shouldn't be issues with missing dependencies, but I guess it's going to depend on exactly what you're using in your projects - you could always directly check the repos as both have nice easily-searchable websites. So for who maintains these repos, as best I know, it's up to the producers of the dependencies to add their dependencies to each repo, and up to the repo owner just to maintain the service.

In terms of when to switch it is difficult to work out. AOSP is still using Maven Central I think (from looking in Templates for New Android Application), but then that template is also still using a very old Gradle version (0.4) as well. There's a couple of issues about others having issues with dependencies from jcenter, but not really a lot reported, and it is possible that Google will switch again to some other repo before releasing AS final. If Maven Central is still working fine for you for now you could hold off switching until then especially if you're building large commercial solutions.

其他回答

不管构建中的默认值是什么。gradle文件——在基于团队的开发工作中,你应该真正使用像Sonatype Nexus或JFrog Artifactory这样的存储库管理器,而不是直接引用那些上游存储库。

这将允许您节省大量带宽,将两者和许多其他存储库结合起来,并在您自己的网络中管理它们。

就Maven Central和JCenter而言。JCenter是JFrog致力于拥抱、扩展(和消灭?)Maven中央。Maven Central是Maven、SBT和其他工具的默认存储库,而Gradle已经切换到JCenter。考虑到JFrog和Gradleware作为公司一起工作,这并不奇怪。由于Android SDK现在使用Gradle作为构建系统,迁移到JCenter是顺理成例的下一步。

JCenter本身是Maven Central之上的一个薄板。它代理它(或多或少成功地)并添加额外的组件。两者都托管在CDN网络上,性能很高。Maven Central本身是所有Eclipse、Apache和大多数其他开源项目的目标,如果没有它,JCenter将基本上是空的。

使用它们中的任何一种都可以,但我建议直接访问您可以使用的源代码,并在此基础上使用存储库管理器来控制它。例如,Nexus开源是免费的,并且支持Maven、Gradle、SBT、Ivy等使用的Maven存储库以及NuGet、NPM和RubyGems支持。

免责声明:我是Nexus库管理的作者和Sonatype的Nexus培训师,免费中央存储库的发起人,Android Maven插件的项目负责人,并通过从AOSP重建一些Android库推到中央。

我刚刚在Bintray上重新写了一篇非常详细的博文,描述了谷歌做出这一改变的原因。以下是最重要的几点:

JCenter is a Java repository in Bintray, which is the largest repo in the world for Java and Android OSS libraries, packages and components. All the content in JCenter is served over a CDN, with a secure HTTPS connection. Back in the time of the migration (Android Studio 0.8) The central maven 2 repository was HTTP only and HTTPS wasn't supported. Reference: 51.6.2. Maven central repository. jcenter() is a superset of mavenCentral(), that encompasses many additional repositories and artifacts. In different scenarios and from different countries Bintray is faster than Maven Central (e.g. from Israel). In others it is very close. Since Maven Central and Bintray use different CDNs which adaptively favor regions, this might change to both ways. Bintray has a different approach to package identification than the legacy Maven Central. This is a big and serious security matter. It is important. If you really need to get your package to Maven Central (for supporting legacy tools) you can do it from Bintray as well, in a click of a button or even automatically.

关于性能改进,一些android开发人员已经面临/注意到maven central的巨大索引问题。

用托尔·诺拜的话来说:

I ran AndroidStudio with a brand new settings directory, so it went and connected maven central and downloaded an index of the available artifacts. Then I happened to look at the size of my directory. My ~/Library/Cache/AndroidStudioPreview is 1.5G, and 1.2G of those are taken by the “Maven” subdirectory. That’s ridiculous. We barely use the index at all. The primary use for it is the Dependency editor in the Project Structure Dialog, but we really don’t need to have a precomputed index for it. MavenCentral has a fast online JSON search we can use on demand when somebody searches for artifacts. In https://android-review.googlesource.com/#/c/94843/ we added a lint check which checks whether the dependencies are up to date, and the search for a handful of artifacts is near instant. In short, we really don’t need the cache; it may help with code completion in .gradle and maven .pom files, but that’s not a super important usecase, and certainly not something all users should have to sacrifice 1.5G of download speed and diskspace to have the possibility of one day doing. Read more on: The Maven index is huge!

此外,您可能会发现Hacker News上的这个非常简短的(1Q和1A)讨论很有趣。


我与JFrog,公司背后的bintray和artifactory,看到我的详细信息和链接的个人资料。

我也想知道,我没有明确的答案,但我想也许值得分享我学到的(一点点)。我发现在谷歌代码的一个问题中提到了从Maven中心到JCenter的移动,但没有发现具体发生的细节——在Android Studio的最近更改列表中没有找到提及。

From reading up on JCenter, it is the repository behind Bintray, from the company JFrog (who I've come across before, and I guess that's where the 'J' comes from). According to the Bintray blog, Bintray is a superset of Maven Central, so if that's true there shouldn't be issues with missing dependencies, but I guess it's going to depend on exactly what you're using in your projects - you could always directly check the repos as both have nice easily-searchable websites. So for who maintains these repos, as best I know, it's up to the producers of the dependencies to add their dependencies to each repo, and up to the repo owner just to maintain the service.

In terms of when to switch it is difficult to work out. AOSP is still using Maven Central I think (from looking in Templates for New Android Application), but then that template is also still using a very old Gradle version (0.4) as well. There's a couple of issues about others having issues with dependencies from jcenter, but not really a lot reported, and it is possible that Google will switch again to some other repo before releasing AS final. If Maven Central is still working fine for you for now you could hold off switching until then especially if you're building large commercial solutions.

http://inthecheesefactory.com/blog/how-to-upload-library-to-jcenter-maven-central-as-dependency/en

这篇文章可以回答你的问题。

At first, Android Studio chose Maven Central as a default repository. Once you create a new project from old version of Android Studio, mavenCentral() would be automatically defined in build.gradle. But the big problem of Maven Central is it is not developer-friendly. It is surprisingly hard to upload the library to. To be able to do so, developer has to be at some level of geeky. And with some more reason for example a security concern and etc, Android Studio team decided to switch the default repository to jcenter instead as you can see that once you create a new project from latest version of Android Studio, jcenter() would be automatically defined instead of mavenCentral().