android studio產生aar包並在其他工程引用aar包

來源:互聯網
上載者:User

標籤:alt   class   scan   ack   roi   tle   source   編譯   uil   

1.aar包是android studio下打包android工程中src、res、lib後產生的aar檔案,aar包匯入其他android studio 工程後,其他工程可以方便引用源碼和資源檔

2.產生aar包步驟:

①.用android studio開啟一個工程,然後建立一個Module,建立Module時候選擇Android Library,後面按建立普通工程操作

 

②.建立Module 類型為android Library 後如所示

 

③.在建立的Module中編寫完代碼後,接下來編譯整個工程後就會自動產生aar包,包的路徑在建立的Module ==》 build ===》outputs ==>aar目錄下。

 

3.其他androidstudio工程引用aar包

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

②.配置build.gradle檔案:

加入

  repositories {
        flatDir {
        dirs ‘libs‘
    }

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

完整的設定檔:

 

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

③.編譯一次工程

 


複製aar包到lib下

 

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

 

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

android studio產生aar包並在其他工程引用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.