JAR (Java Archive) JAR๋ ํด๋น ํ๋ซํผ์์ JAVA ์์ฉํ๋ก๊ทธ๋จ์ ๋ฐฐํฌํ๊ธฐ ์ํด ๊ณ ์๋ ํจํค์ง ํ์ผ ํ์์ด๋ค. ์ปดํ์ผ๋ Javaํด๋์ค ํ์ผ๊ณผ, MANIFEST ๊ฐ์ ํ์ผ๋ค์ด ํฌํจ๋๋ค. ๊ธฐ๋ณธ์ ์ผ๋ก ZIP ์์นด์ด๋ธ ํํ์ด๋ค. AAR (Android Archive) Android ๋ผ์ด๋ธ๋ฌ๋ฆฌ ํ๋ก์ ํธ์ ๋ฐ์ด๋๋ฆฌ ๋ฐฐํฌํ์ด๋ค. ์ฃผ๋ก Javaํด๋์ค ํ์ผ๋ค๋ง ํฌํจํ๋ JAR์ ๋ฌ๋ฆฌ, ๋ฆฌ์์ค ํ์ผ๋ค๋ ํฌํจํ๊ณ ์๋ค. ํน์ ํ๋ก์ ํธ์ ์ข ์๋์ง ์๊ณ , stand alone ๋น๋ํ ์ ์์ผ๋ฉฐ, ๋ผ์ด๋ธ๋ฌ๋ฆฌ ๋ด์ฉ์ด ์์ ๋ ๋๋ง๋ค ๋งค๋ฒ aar ํ์ผ์ ๋ณต๋ถํ ํ์๊ฐ ์๋ ๋ฐฉ์์ผ๋ก aar ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ๋ง๋ค ์ ์๋ค. DEX (Dalvik Excutable) DVM(Dalvik Virtual Machine)์ ์ํ ์คํ ํ์ผ์ด๋ค. JVM์ ์ํ .class ํ์ผ๋๋ก๊ฐ ๊ฐ์ ์ญํ ์ ํ๋ค. Android SDK์ Dex์ปดํ์ผ๋ฌ์ ์ํด JVM๋ฐ์ดํธ์ฝ๋๋ฅผ DVM๋ฐ์ดํธ์ฝ๋๋ก ๋ณํํ๊ณ , ๋ชจ๋ ํด๋์คํ์ผ๋ค์ Dexํ์ผ์ ๋ฃ๋๋ค. DEX๋ ๋ฐ์ด๋๋ฆฌ ํ์ผ ํ์์ผ๋ก ์ปดํ์ผ ๋๋ค. APK (Android Application Package) APK๋ Android ํ๋ซํผ์ ๋ฐฐํฌํ ์ ์๋๋ก ์ค๊ณ๋ ํ์ผ ํ์์ด๋ค. ์ปดํ์ผ๋ ํด๋์ค๋ฅผ Dexํ์ผ ํํ๋ก ํฌํจ์ํค๊ณ , AndroidManifest.xml ๋ฑ ๋ฆฌ์์ค ํ์ผ๋ค๋ ํฌํจํ๋ค. |
1. ํ๋ก์ ํธ ์์ฑ
No Activity ๋ก ์์ฑํ๋ค.
2. build.gradle ํ์ผ์ ํ๋๋ก ํตํฉ
์ฑ ๋ ๋ฒจ์ build.gradle (:app) ๊ณผ ํ ๋ ๋ฒจ์ build.gradle (ARRLib) ์ด ์๋๋ฐ,
์ฑ ๋ ๋ฒจ์ build.gradle (:app) ์ชฝ์ผ๋ก ํตํฉํ๋ ๊ฒ์ผ๋ก ํ์.
(๋์ค์ ํด๋น ํ์ผ์ ํ ๋ ๋ฒจ๋ก ์ด๋์ํฌ ๊ฑฐ๊ธด ํ๋ฐ.. ์ด์ชฝ์ ์ฝ๋๊ฐ ๋ ๋ง์ผ๋.. ์ผ๋จ ๋ง์ ์ชฝ์ผ๋ก ํตํฉํ๋ ๊ฑธ๋ก...)
๊ธฐ์กด build.gradle (:app) - APP Level
plugins {
id 'com.android.application'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.devshin93.aarlib"
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
๊ธฐ์กด build.gradle (AARLib) - Top Level
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.1"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
ํตํฉ ํ build.gradle - ์ต์ข ์ ์ผ๋ก ์ด์ ๋น์ทํ๊ฒ ํตํฉ๋์ด์ผ ํ๋ค
// ํ ๋ ๋ฒจ
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.1"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
// ์ฑ ๋ ๋ฒจ
// 'com.android.application;' -> 'com.android.library' ๋ณ๊ฒฝ
apply plugin: 'com.android.library'
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
// sourceSets ์ถ๊ฐ
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src/main/java']
res.srcDirs = ['res']
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
// repositories ์ถ๊ฐ
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
}
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
3. ํ๋ก์ ํธํด๋/appํด๋ ์๋์ lib, src, build.gradle ์ ํ๋ก์ ํธ ํด๋๋ก ์ด๋
ํ๋ก์ ํธ ํด๋์ build.gradle๊ณผ ๋์ผํ ์ด๋ฆ์ ํ์ผ์ด ์๋ค๊ณ ํ๋ฉด ๋ฎ์ด์ฐ๊ธฐ (100ํผ ๋์ผํ ์ด๋ฆ์ ํ์ผ์ด ์๋ค๊ณ ํ ๊ฒ์.. ํตํฉ๋ build.gradle ์ด ๋จ์์ผ ํจ)
4. ํ๋ก์ ํธํด๋/src/mainํด๋ ์๋์ res, AndroidManifest.xml ์ ํ๋ก์ ํธ ํด๋๋ก ์ด๋
5. ์ต์ข ํด๋ ๊ตฌ์ฑ. app ํด๋๋ ์ญ์ ํ์.
6. setting.gradle ํธ์ง
์์ ์
rootProject.name = "AARLib"
include ':app'
์์ ํ - include ':app' ์ญ์
rootProject.name = "AARLib"
7. Sync Now
8. ํ ์คํธ ํด๋์ค ์์ฑ
Calculate.java
package com.devshin93.aarlib;
public class Calculate {
public int add (int a, int b) {
return a + b;
}
}
9. ์ฐ์ธก์ gradle ์์ assembleRelease ๊ฒ์ ํ ์คํ
10. ์์ฑ๋ AAR ํ์ผ์ build/outputs/aar ์์ ์ฐพ์ ์ ์๋ค.
+) ์ฌ๊ธฐ๊น์ง ์๋๋ฐ, ์ด๋ฐ ์ค๋ฅ๋ฅผ ๋ง์ฃผํ๋ค๋ฉด,
com.android.builder.errors.EvalIssueException: Library projects cannot set applicationId.
build.gradle ์์, android { defaultConfig { applicationId ๋ฅผ ์ง์ด๋ค. }}
ํ ์คํธ๋ ๋ค์ ์ฅ์์ ๊ณ์...
2021.08.12 - [๊ฐ๋ฐ/์๋๋ก์ด๋] - [์๋๋ก์ด๋] AAR(Android Archive) ํ ์คํธ ... 2
๋๊ธ