1. 程式人生 > >Android Studio 如何匯入aar包

Android Studio 如何匯入aar包

androidstudio工程引用aar包

①.將aar包複製到lib目錄下 

②.配置build.gradle檔案:

加入

  repositories {
        flatDir {
        dirs 'libs'
    }

compile(name:'camerascan-1.0', ext:'aar')

完整的配置檔案:

  1. apply plugin: 'com.android.application'
  2. android {  
  3.     compileSdkVersion 22
  4.     buildToolsVersion "22.0.1"
  5.     defaultConfig {  
  6.         applicationId "com.geenk.testcamerascanarr"
  7.         minSdkVersion 11
  8.         targetSdkVersion 22
  9.         versionCode 1
  10.         versionName "1.0"
  11.     }  
  12.     buildTypes {  
  13.         release {  
  14.             minifyEnabled false
  15.             proguardFiles getDefaultProguardFile('proguard-android.txt'
    ), 'proguard-rules.pro'
  16.         }  
  17.     }  
  18.     repositories {  
  19.         flatDir {  
  20.         dirs 'libs'
  21.     }  
  22. }  
  23. }  
  24. dependencies {  
  25.     compile fileTree(dir: 'libs', include: ['*.jar'])  
  26.     compile(name:'camerascan-1.0', ext:'aar')  
  27.     compile 'com.android.support:appcompat-v7:22.2.0'
  28. }  
③.編譯一次工程


如圖複製aar包到lib下


圖複製到lib下後,點選下圖按鈕讓aar包可以在在程式碼中引用,或者編譯一次工程


以上操作成功後可以在擴充套件包下看到被引用的aar包檔案