Android studio 導出,導入 arr包
arr包與jar包不同之處在于arr可以導入.class檔案與其資源檔案.因為是使用依賴完成導入是以不需要配置gradle。
導出arr包
- 建立module(子產品)
- 打開Flie–>New –>NewModule 選擇Android Libray
Android studio 導出,導入 arr包 Android studio 導出,導入 arr包 修改命名,然後finish
建立成功後
Android studio 導出,導入 arr包 建立成功後即可在module中編寫代碼
注:module中不能使用switch語句,因為Module中生成的R.java中的資源ID不是常數,ID沒有final修飾詞
導出arr包 -
導出arr包有兩種方法
方法一:
是Build–>Rebuild Project
Android studio 導出,導入 arr包 方法二:
使用Terminal
在Terminal中輸入 gradlew assembleRelease(windows)
./gradlew assembleRelease(linux)
編譯完成後arr包的位置在,你的module–>Build–>output–>arr檔案夾下Android studio 導出,導入 arr包 Android studio 導出,導入 arr包
導出arr包結束
導入arr包
- 建立module(子產品)
- 将準備導入的arr包放在app–>libs 檔案夾下 打開Flie–>New –>NewModule
Android studio 導出,導入 arr包 這次選擇Imoprt.JAR/.AAR PackageAndroid studio 導出,導入 arr包 檔案選擇在lib中的arr包Android studio 導出,導入 arr包 成功後會在項目裡建立一個moduleAndroid studio 導出,導入 arr包 Android studio 導出,導入 arr包 Rebuild 一下項目
Build–>Rebuild Project
成功後會多一個iml檔案Android studio 導出,導入 arr包 打開File–>Project Structure…Android studio 導出,導入 arr包 點選app,找到Dependencies,點選“+”選擇Module dependencyAndroid studio 導出,導入 arr包 選擇你的arr包生成的module,點選OKAndroid studio 導出,導入 arr包 當然如果不想使用Project Structure… 也可在你的build.gradle中配置,隻需一行代碼Android studio 導出,導入 arr包 Android studio 導出,導入 arr包
dependencies {
……
compile project(‘:你的arr包名’)
}
最後檢視project目錄–>External Libraries
如果有以上檔案說明導入成功,可以在project中直接引用了
注:build.gradle中一定要有
compile fileTree(include: [‘*.jar’], dir: ‘libs’)這句代碼