TShopping

 找回密碼
 註冊
搜索
查看: 3277|回復: 0

[教學] Android Library打包成aar,提供給第三方引用

[複製鏈接]
發表於 2020-7-23 16:43:43 | 顯示全部樓層 |閱讀模式
 
Push to Facebook
影片

看了很多說明文件,始終不知道如何在Android直接建立一個新的Module模組,經過摸索後,發現建立模組前必須建立一個project專案才可以
建立專案後又要建立模組,這時會出現類似有兩個專案,但這樣是不對的,於是發現建立專案後,直接改CODE可以換成模組



1. Sart a new projects
1.jpg

2.隨便選一個activity
2.jpg


3.重要的來了,點選 gradle(Module:app)
3.jpg




把package換成library
找到代碼
  1. apply plugin: 'com.android.application'
複製代碼

修改
  1. apply plugin: 'com.android.library'
複製代碼


找到代碼
  1. compileSdkVersion 29
  2.     buildToolsVersion "29.0.3"

  3.     defaultConfig {
  4.         applicationId "com.chiunwu.myapplication"
  5.         minSdkVersion 17
  6.         targetSdkVersion 29
  7.         versionCode 1
  8.         versionName "1.0"
  9.         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
  10.     }
複製代碼
修改
  1. compileSdkVersion 23
  2.     buildToolsVersion "27.0.3"

  3.     defaultConfig {
  4.         minSdkVersion 17
  5.         targetSdkVersion 23
  6.         versionCode 1
  7.         versionName "1.0"
  8.         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
  9.     }
複製代碼
找到代碼
  1. implementation fileTree(dir: 'libs', include: ['*.jar'])

  2.     implementation 'androidx.appcompat:appcompat:1.1.0'
  3.     implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
  4.     testImplementation 'junit:junit:4.12'
  5.     androidTestImplementation 'androidx.test.ext:junit:1.1.1'
  6.     androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
複製代碼
修改
  1. compile fileTree(dir: 'libs', include: ['*.jar'])
  2.     androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
  3.         exclude group: 'com.android.support', module: 'support-annotations'
  4.     })

  5.     compile 'com.android.support:appcompat-v7:23.+'
  6.     testCompile 'junit:junit:4.12'
複製代碼
同步專案後(右上角會有小小的圖示SYNC)
這時已經發現圖示已經以之前不同

5.jpg


點選manifests.xml
找到代碼並刪除
  1. android:roundIcon="@mipmap/ic_launcher_round"
複製代碼
找到代碼並刪除
  1. <activity android:name=".MainActivity">
  2.             <intent-filter>
  3.                 <action android:name="android.intent.action.MAIN" />

  4.                 <category android:name="android.intent.category.LAUNCHER" />
  5.             </intent-filter>
  6.         </activity>
複製代碼

這時可加入你要的東西

最後rebuild project
4.jpg

完成

來源http://www.netyea.com#網頁設計 #網站架設 #關鍵字優化 #網頁優化 #App程式設計 #AIOT物聯網



 

臉書網友討論
*滑块验证:
您需要登錄後才可以回帖 登錄 | 註冊 |

本版積分規則



Archiver|手機版|小黑屋|免責聲明|TShopping

GMT+8, 2024-4-19 07:49 , Processed in 0.068537 second(s), 26 queries .

本論壇言論純屬發表者個人意見,與 TShopping綜合論壇 立場無關 如有意見侵犯了您的權益 請寫信聯絡我們。

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表