'2024/06/05'에 해당되는 글 2건

반응형

AAR파일을 프로젝트에 추가 및 설정하는 방법에 대해 알아보도록 하겠습니다.

 

AAR 파일을 프로젝트에 추가

aar파일을 프로젝트의 libs 폴더에 복사합니다. 만약 폴더가 없다면 생성합니다.

your_project/
├── app/
│   ├── build.gradle.kts
│   ├── libs/
│   │   ├── MyTest-debug.aar
│   │   └── MyTest-release.aar
│   ├── src/
│   └── ...
├── build.gradle.kts
└── settings.gradle.kts

'

 

'settings.gradle.kts' 파일 수정

'settings.gradle.kts' 파일에서 'flatDir' repositories를 추가합니다:

pluginManagement {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        // 'libs' 폴더 설정  
        flatDir {
            dirs("libs")
        }
    }
}

rootProject.name = "your_project"
include(":app")

 

'build.gradle.kts' (Moduel :app) 파일 수정

... 생략 ...

dependencies {
    ... 생략 ...

    // AAR 파일 의존성 추가
    implementation(":MyTest-debug")
    releaseImplementation(":MyTest-release")
}

 

 

반응형
블로그 이미지

SKY STORY

,
반응형

개발중인 어플리케이션 프로젝트(.apk)를 라이브러리 모듈(.aar)로 변경해야 할 경우 설정방법을 알아보도록 하자.

프로젝트 이름은 'mytest'일 경우 다음과 같은 순서로 설정을 변경하도록 하자.

 

불필요한 소스 파일 제거

라이브러리 파일에 필요한 소스코드를 제외하고 나머지  파일들은 모두 제거하도록 한다.

 

AndroidManifest.xml 수정

application 요소와 앱 관련 설정을 제거하고, 라이브러리에서 필요한 설정만 남겨둡니다.

예를 들어, 권한이나 기본 설정 등을 유지할 수 있습니다.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.mytest">

    <!-- 필요한 권한 및 기타 설정을 여기에 추가 -->
    <!-- 예: INTERNET 권한 -->
    <uses-permission android:name="android.permission.INTERNET" />

    <!-- 필요하다면 다른 권한도 추가 가능 -->
    
    <!-- 라이브러리에서 제공하는 특정 기능을 위한 설정 -->
    <!-- 예: 서비스나 리시버 등 -->
    <!--
    <application>
        <service android:name=".MyService" />
        <receiver android:name=".MyReceiver">
            <intent-filter>
                <action android:name="com.example.mytest.SOME_ACTION" />
            </intent-filter>
        </receiver>
    </application>
    -->
</manifest>

 

'build.gradle.kts' (Project: MyTest)

// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    alias(libs.plugins.android.application) apply false

    // 라이브러리 플러그인 추가
    alias(libs.plugins.android.library) apply false

    alias(libs.plugins.jetbrains.kotlin.android) apply false
}

 

'build.gradle.kts' (Module: MyTest)

plugins {
    // 어플리케이션 플러그인 제거
    //alias(libs.plugins.android.application)

	// 라이브러리 플러그인 추가
    alias(libs.plugins.android.library)

    alias(libs.plugins.jetbrains.kotlin.android)
}

android {
    namespace = "com.sample.mytest"
    compileSdk = 34

    defaultConfig {
        // applicationId 제거
        //applicationId = "com.sample.mytest"

        minSdk = 28

        // 버전정보 제거
        //versionCode = 1
        //versionName = "1.0"

        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
    }
	
	... 생략 ...

    lint {
        targetSdk = 34
    }
	
	... 생략 ...
    
}

dependencies {
	... 생략 ...
}

 

'settings.gradle.kts' (Project Settings)

... 생략 ...

rootProject.name = "MyTest"	// 프로젝트 루트 이름
include(":MyTest")			// 모듈이름 정의

... 생략 ...

 

'libs.versions.toml' (Version Catalog)

[versions]
agp = "8.4.1"
kotlin = "1.9.0"
coreKtx = "1.13.1"
... 생략 ...

[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
junit = { group = "junit", name = "junit", version.ref = "junit" }
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
... 생략 ...

[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
# 라이브러리 플러그인 버전정보 추가
android-library = { id = "com.android.library", version.ref = "agp" }
jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }

 

라이브러리 빌드 및 테스트

콘솔창에서 아래와 같이 아리브러리 빌드를 한다. 

./gradlew assembleRelease

 

 

반응형
블로그 이미지

SKY STORY

,