IT박스

Android Studio에서 AAR 파일 만들기

itboxs 2020. 6. 6. 08:56
반응형

Android Studio에서 AAR 파일 만들기


Android Studio에서 내 라이브러리에 대한 aar 파일을 만들고 싶습니다 .jar 옵션을 사용했지만 라이브러리에 리소스가 있습니다.

라이브러리에서 aar 파일을 만드는 방법에 대한 아이디어가 있습니까?


라이브러리가 Android 라이브러리로 설정된 경우 (예 : apply plugin: 'com.android.library'build.gradle 파일 명령문을 사용하는 경우) 빌드시 .aar가 출력됩니다. 모듈 디렉토리 build / outputs / aar / 디렉토리에 표시됩니다.

파일> 새 모듈에서 "Android 라이브러리"유형을 선택하여 새 Android 라이브러리를 만들 수 있습니다.


로컬 빌드에서 내 보낸 .aar 파일 검색

Android 라이브러리 프로젝트로 정의 된 모듈이있는 경우 build/outputs/aar/해당 프로젝트 디렉토리에 모든 빌드 특징 (기본적으로 디버그 및 릴리스)에 대한 .aar 파일이 제공 됩니다.

your-library-project
    |- build
        |- outputs
            |- aar
                |- appframework-debug.aar
                 - appframework-release.aar

이러한 파일이 존재하지 않으면

gradlew assemble

도서관 프로젝트 세부 사항

라이브러리 프로젝트에는 build.gradle파일이 포함되어 apply plugin: com.android.library있습니다. .aar파일 로 패키지 된이 라이브러리를 참조 하려면 패키지 및 버전과 같은 일부 속성을 정의해야합니다.

build.gradle라이브러리의 예제 파일 (이 예제에는 릴리스에서 난독 화가 포함됨) :

apply plugin: 'com.android.library'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.0"

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 21
        versionCode 1
        versionName "0.1.0"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

프로젝트의 참조 .aar 파일

앱 프로젝트에서이 .aar파일을 libs폴더에 build.gradle놓고 아래 예제를 사용하여이 라이브러리를 참조 하도록 파일을 업데이트 할 수 있습니다 .

apply plugin: 'com.android.application'

repositories {
    mavenCentral()
    flatDir {
        dirs 'libs' //this way we can find the .aar file in libs folder
    }
}

android {
    compileSdkVersion 21
    buildToolsVersion "21.0.0"

    defaultConfig {

        minSdkVersion 14
        targetSdkVersion 20
        versionCode 4
        versionName "0.4.0"

        applicationId "yourdomain.yourpackage"
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            minifyEnabled false
        }
    }
}

dependencies {
    compile 'be.hcpl.android.appframework:appframework:0.1.0@aar'
}

gradle에서 로컬 종속성 파일을 참조하기위한 대체 옵션은 http://kevinpelgrims.com/blog/2014/05/18/reference-a-local-aar-in-your-android-project 에서 찾을 수 있습니다.

Maven을 사용하여 종속성 공유

If you need to share these .aar files within your organization check out maven. A nice write up on this topic can be found at: https://web.archive.org/web/20141002122437/http://blog.glassdiary.com/post/67134169807/how-to-share-android-archive-library-aar-across

About the .aar file format

An aar file is just a .zip with an alternative extension and specific content. For details check this link about the aar format.


just like user hcpl said but if you want to not worry about the version of the library you can do this:

dependencies {
    compile(name:'mylibrary', ext:'aar')
}

as its kind of annoying to have to update the version everytime. Also it makes the not worrying about the name space easier this way.


After following the first and second steps mentioned in the hcpl's answer in the same thread, we added , '*.aar'], dir: 'libs' in the our-android-app-project-based-on-gradle/app/build.gradle file as shown below:

...

dependencies {
       implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')

...

Our gradle version is com.android.tools.build:gradle:3.2.1


btw @aar doesn't have transitive dependency. you need a parameter to turn it on: Transitive dependencies not resolved for aar library using gradle

참고URL : https://stackoverflow.com/questions/24309950/create-aar-file-in-android-studio

반응형