天天看点

jcenter,maven和grandle

1.jcenter用来作什么?

JCenter is the place to find and share popular Apache Maven packages for use by Maven, Gradle, Ivy, SBT, etc. 

jcenter仓库网页地址:https://bintray.com/bintray/jcenter

jcenter仓库源码地址:http://jcenter.bintray.com 

可以在"网页地址"中查找到某个库需要的maven/Ivy/gradle依赖形式.

maven仓库网页地址:http://mvnrepository.com/   (maven上能找到的库,在jcenter上都能找到)

maven中央仓库源码地址:http://repo1.maven.org/maven2/

2.android studio 使用国内jcenter和maven镜像地址

由于国内GFW的原因,经常导致Android studio 莫名其妙的编译不了,多数原因是由于不能下载依赖库

Gradle支持三种不同的仓库,分别是:Maven和Ivy以及文件夹。依赖包会在你执行build构建的时候从这些远程仓库下载,当然Gradle会为你在本地保留缓存,所以一个特定版本的依赖包只需要下载一次。

repositories {

       mavenCentral()

       jcenter()           //默认的jcenter中央仓库http://jcenter.bintray.com 

       mavenLocal()

   }

为了避免由于被墙,我们使用国内mave库,这里使用的是开源中国的maven库开源中国maven网页、链接镜像地址:http://maven.oschina.net/home.html

我们在studio中只需替换项目根目录下build.gradle中的jCenter或者maven就好

allprojects {

    repositories {

        maven{ url 'http://maven.oschina.net/content/groups/public/'}  //以下的库具有优先级

        mavenCentral()

        jcenter()           //默认的jcenter中央仓库http://jcenter.bintray.com 

        mavenLocal()

    }

}

3.gradle依赖

    dependencies {

        classpath 'com.android.tools.build:gradle:2.1.0'  //表示android使用的gradle的的插件,需要与studio的版本匹配

dependencies {

    compile fileTree(include: ['*.jar'], dir: 'libs')     //表示依赖的包 :libs,目录下所有的.jar包

    compile 'com.android.support:recyclerview-v7:23.3.0'  //这是一个本地sdk中的包

    compile 'com.google.android.gms:play-services-appindexing:8.4.0' //这是一个本地sdk中的包

    compile 'com.github.lecho:hellocharts-library:1.5.8@aar' //这是一个jcenter中的包,可以在jcenter或mavenCentral中查到

    compile 'org.greenrobot:eventbus:3.0.0' //这是一个jcenter中的包,可以在jcenter或mavenCentral中查到

Error:Error converting bytecode to dex:

Cause: Dex cannot parse version 52 byte code.

This is caused by library dependencies that have been compiled using Java 8 or above.

If you are using the 'java' gradle plugin in a library submodule add 

targetCompatibility = '1.7'

sourceCompatibility = '1.7'

to that submodule's build.gradle file.

本文转自 a_liujin 51CTO博客,原文链接:http://blog.51cto.com/a1liujin/1794695,如需转载请自行联系原作者

继续阅读