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.


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章