๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ’š ๊ฐœ๋ฐœ/์•ˆ๋“œ๋กœ์ด๋“œ

[์•ˆ๋“œ๋กœ์ด๋“œ] AAR(Android Archive) ๋งŒ๋“ค๊ธฐ ... 1

by devshin.kr 2021. 8. 12.
728x90
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

 

[์•ˆ๋“œ๋กœ์ด๋“œ] AAR(Android Archive) ํ…Œ์ŠคํŠธ ... 2

2021.08.12 - [๊ฐœ๋ฐœ/์•ˆ๋“œ๋กœ์ด๋“œ] - [์•ˆ๋“œ๋กœ์ด๋“œ] AAR(Android Archive) ๋งŒ๋“ค๊ธฐ ... 1 [์•ˆ๋“œ๋กœ์ด๋“œ] AAR(Android Archive) ๋งŒ๋“ค๊ธฐ ... 1 JAR (Java Archive) JAR๋Š” ํ•ด๋‹น ํ”Œ๋žซํผ์—์„œ JAVA ์‘์šฉํ”„๋กœ๊ทธ๋žจ์„ ๋ฐฐํฌํ•˜๊ธฐ..

devshin93.tistory.com

 

๋Œ“๊ธ€