Android Studio匯入第三方類庫的方法,androidstudio

來源:互聯網
上載者:User

Android Studio匯入第三方類庫的方法,androidstudio

一、匯入*.jar包

1.直接copy

①複製*.jar包,粘貼到主工程目錄的libs下邊

   

②右鍵,將此jar包設定成自己的library

③然後在工程右鍵的選擇項目單擊Open Module Settings,在Dependencies中選擇添加檔案

       

這樣,就表示jar包添加成功了。

開啟app目錄下的build.gradle

表示添加成功。

2.build.gradle裡邊添加一句:

compile fileTree(include: ['*.jar'], dir: 'libs')

 

寫下這句話後,再直接複製粘貼jab包到libs目錄下邊即可,自動add as library。

 

二、匯入第三方java類庫含源碼包

1.先把從github上下載下來的library解壓,把library的檔案夾所有複製到工程下邊(與主工程app同級,複製到檔案、工程都可)

  

 

2.項目根目錄下settigs.gradle添加:include ':App',':viewpagerindicatorlibrary'

3.app/build.gradle的dependencies裡邊添加:compile project(':viewpagerindicatorlibrary')

4.開啟open Module Settings看到viewpagerindicatorlibrary 已經加入進來

點擊Try again 還會有編譯報錯...

5.修改編譯報錯:還需在viewpagerindicatorlibrary目錄下添加一個build.gradle的檔案

apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "24.0.0"

defaultConfig {
minSdkVersion 14
targetSdkVersion 24
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile 'com.android.support:support-v4:18.+'
}

跟主的app/build.gradle差不多,就是defaultConfig只留兩個Version版本,依賴只加入自己依賴即可,麼有libs就

compile 'com.android.support:support-v4:18.+',有libs就
compile fileTree(include: ['*.jar'], dir: 'libs')。

編譯後,可能還有報錯,需要修改一下viewpagerindicatorlibrary目錄下的AndroidManifest.xml檔案有可能存在和你項目中檔案有衝突或版本跨度太大導致文法的錯誤修改一下

三、aar的引入

1.一個單獨的工程,有依賴相應的自己的library,可運行一下自己的工程,在自己工程目錄下找到.aar檔案

 

2.將.aar檔案粘貼到自己項目的libs目錄下

3.修改app/build.grdle設定檔

添加:repositories     flatDir {        dirs 'libs'    }}

這個是添加一個本地倉庫,並把libs目錄作為倉庫地址。

dependencies中添加一行:

compile(name:'pullrefreshlibrary', ext:'aar')

4.重新編譯項目:

從工具列依次選擇:"Build"-->"rebuild project"

5.編譯完成後,在app/build/intermediates/exploded-aar/ a就可以看見我們引用的aar包內容了,其中jar目錄下是jar檔案,res下是我們aar包裡的資源檔。

 

就可以用了


 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.