導出aar
首先Android Library項目的gradle腳本只需要在開頭聲明
apply plugin: 'com.android.library'
之后就和導出apk文件一樣的方法,執行 ./gradlew assembleRelease,然后就可以在 build/outputs/aar 文件夾里生成aar文件
引用本地的aar
1: 確保你的 aar文件中沒有和現有工程重復的res,包括圖片名字,如ic-launcher, string , dimen等,一旦主工程引用了該重復的資源名稱,就會報錯。
2: in build.gradle
apply plugin: 'com.android.application' android { compileSdkVersion 22 buildToolsVersion "22.0.1" defaultConfig { applicationId "xxxxxxxxxxx" minSdkVersion 22 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(name:'app-release', ext:'aar') }