1.aar包是android studio下打包android工程中src、res、lib后生成的aar文件,aar包導(dǎo)入其他android studio 工程后,其他工程可以方便引用源碼和資源文件
2.生成aar包步驟:
①.用android studio打開一個(gè)工程,然后新建一個(gè)Module,新建Module時(shí)候選擇Android Library,后面按新建普通工程操作


②.新建Module 類型為android Library 后如下圖所示

③.在新建的Module中編寫完代碼后,接下來編譯整個(gè)工程后就會自動生成aar包,包的路徑在新建的Module ==》 build ===》outputs ==>aar目錄下。 如圖


3.其他androidstudio工程引用aar包
①.將aar包復(fù)制到lib目錄下
②.配置build.gradle文件:
加入
repositories { flatDir { dirs 'libs' }compile(name:'camerascan-1.0', ext:'aar')完整的配置文件:
apply plugin: 'com.android.application' android { compileSdkVersion 22 buildToolsVersion "22.0.1" defaultConfig { applicationId "com.geenk.testcamerascanarr" minSdkVersion 11 targetSdkVersion 22 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } repositories { flatDir { dirs 'libs' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile(name:'camerascan-1.0', ext:'aar') compile 'com.android.support:appcompat-v7:22.2.0' } ③.編譯一次工程
如圖復(fù)制aar包到lib下

圖復(fù)制到lib下后,點(diǎn)擊下圖按鈕讓aar包可以在在代碼中引用,或者編譯一次工程

以上操作成功后可以在擴(kuò)展包下看到被引用的aar包文件

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持VEVB武林網(wǎng)。
新聞熱點(diǎn)
疑難解答
圖片精選