내 gradle 빌드에 로컬 .aar 파일 추가
그래서 나는 Android-Library를 만들고 성공적으로 이것을 .aar 파일로 컴파일했습니다.이 aar 파일 : "projectx-sdk-1.0.0.aar"
이제 새 프로젝트가이 aar에 의존하기를 원 하므로이 게시물을 따르십시오 : http : // life. nimbco.us/referencing-local-aar-files-with-android-studios-new-gradle-based-build-system/
그러나 원하는 결과를 얻지 못하기 때문에 게시물이 혼란 스럽습니다.
aar의 패키지 이름은 : com.projectx.photosdk
이고 내부 모듈이 호출됩니다.sdk
내 현재 프로젝트 구조는 다음과 같습니다.
|-SuperAwesomeApp
|--.idea
|--gradle
|--App
|---aars
|----projectx-sdk-1.0.0.aar
|---build
|---jars
|---src
|---build.gradle
그리고 그는 내 gradle 빌드 파일입니다.
apply plugin: 'android'
buildscript {
repositories {
mavenCentral()
flatDir {
dirs 'aars'
}
}
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 11
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:gridlayout-v7:19.0.1'
compile 'com.android.support:support-v4:19.0.1'
compile 'com.android.support:appcompat-v7:19.0.1'
compile 'com.projectx.photosdk:sdk:1.0.0@aar'
// compile files( 'aars/sdk-1.0.0.aar' ) // Does not work either
}
// 편집하다
내가 얻는 오류 :
Failed to refresh Gradle project 'SuperAwesomeApp'
Could not find com.projectx.photosdk:sdk:1.0.0.
Required by:
SuperAwesomeApp:App:unspecified
flatDir
블록을 잘못된 repostories
블록 에 넣었습니다 . repositories
블록 내부 buildscript
어디 안드로이드 Gradle을 플러그인 아니라 의존성의 나머지 부분을 찾을 수 Gradle을 알려줍니다. 다음 repositories
과 같은 또 다른 최상위 블록이 필요합니다.
repositories {
mavenCentral()
flatDir {
dirs 'aars'
}
}
나는 이것을 테스트했고 내 설정에서 잘 작동합니다.
1.3으로 테스트 한 최신 버전의 Android Studio에서 maven / jcenter 저장소에서 가져온 파일이 아닌 로컬 .AAR 파일을 사용하려면 File> New> New module 로 이동하여 Import .JAR / .AAR Package를 선택하십시오 .
결국 다음과 같이 보이는 매우 간단한 build.gradle 파일이 포함 된 프로젝트의 새 모듈입니다 .
configurations.create("default")
artifacts.add("default", file('this-is-yours-package-in-aar-format.aar'))
물론, 다른 프로젝트는 정규 컴파일 프로젝트 지시문 으로이 새 모듈을 참조해야합니다 . 따라서 간단한이 새로운 모듈을 사용하는 프로젝트에서 로컬 .aar 파일에는 build.gradle이 있습니다.
[...]
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
ompile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:design:23.1.0'
[...]
compile project(':name-of-module-created-via-new-module-option-described-above')
}
[...]
Gradle 3.0.1을 사용하는 Android Studio 3.1.3에서.
단순히 다른 작업을 추가 implementation fileTree(dir: 'libs', include: ['*.aar'])
하거나 추가 implementation files('libs/app-release.aar')
하지 않습니다 flatdir
.
요즘 (이 질문 이후 1 년 이상) Android Studio> 1.0에서는 로컬 종속성이 제대로 작동합니다.
- Android SDK는 다음의 기본 로컬 저장소에서 종속성을 찾습니다.
$ANDROID_HOME/extras/android/m2repository/
로컬 라이브러리 프로젝트에서 aar를이 디렉토리에 게시 할 수 있습니다. 다음은 모듈
build.gradle
파일에 추가 할 수있는 스 니펫입니다 (예 : sdk / build.gradle).apply plugin: 'maven' uploadArchives { repositories { mavenDeployer { repository(url: "file://localhost" + System.getenv("ANDROID_HOME") + "/extras/android/m2repository/") pom.version = '1.0-SNAPSHOT' pom.groupId = 'your.package' pom.artifactId = 'sdk-name' } } }
- some reference gradle docs http://gradle.org/docs/current/userguide/artifact_management.html
- In your library project, run
./gradlew uploadArchives
to publish the aar to that directory - In the application project you want to use the library in, add the dependency to your project/app/build.gradle.
compile 'your.package:sdk-name:1.0-SNAPSHOT'
For local dependency, the next gradle build should find the previously deployed archive and that's it!
In my case, I use the above for local dev, but also have a Bamboo continuous integration server for the Library that publishes each build to a shared Nexus artifact repository. The full library code to deploy the artifact then becomes:
uploadArchives {
repositories {
mavenDeployer {
if (System.getenv("BAMBOO_BUILDNUMBER") != null) {
// Deploy to shared repository
repository(url: "http://internal-nexus.url/path/") {
authentication(userName: "user", password: "****")
}
pom.version = System.getenv("BAMBOO_BUILDNUMBER")
} else {
// Deploy to local Android sdk m2repository
repository(url: "file://localhost" + System.getenv("ANDROID_HOME")
+ "/extras/android/m2repository/")
pom.version = '1.0-SNAPSHOT'
}
pom.groupId = 'your.package'
pom.artifactId = 'sdk-name'
}
}
}
In order to tell applications to download from my internal Nexus repository, I added the internal Nexus maven repository just above jcenter() in both "repositories" blocks in the project/build.gradle
repositories {
maven {
url "http://internal-nexus.url/path/"
}
jcenter()
}
And application dependency then looks like compile 'your.package:sdk-name:45'
When I update the 45 version to 46 is when my project will grab the new artifact from the Nexus server.
With the newest Gradle version there is now a slightly updated way of doing what Stan suggested (see maving publishing)
apply plugin: 'maven-publish'
publishing {
publications {
aar(MavenPublication) {
groupId 'org.your-group-id'
artifactId 'your-artifact-id'
version 'x.x.x'
// Tell maven to prepare the generated "*.aar" file for publishing
artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")
}
}
repositories {
maven {
url("file:" + System.getenv("HOME") + "/.m2/repository")
}
}
}
It seems adding .aar files as local dependency is not yet supported(Planned to be supported in 0.5.0 Beta)
https://code.google.com/p/android/issues/detail?id=55863
But the way you are using your library in dependency will only work if your library is on central maven repository or in the local maven repository.
Refer this for How to use local maven repository to use .aar in module dependencies.
http://www.flexlabs.org/2013/06/using-local-aar-android-library-packages-in-gradle-builds
참고URL : https://stackoverflow.com/questions/21882804/adding-local-aar-files-to-my-gradle-build
'Program Tip' 카테고리의 다른 글
전체 디렉토리에 대한 패치를 작성하여 업데이트하는 방법은 무엇입니까? (0) | 2020.11.14 |
---|---|
애니메이션이있는 함수가 다른 함수를 실행할 때까지 완료 될 때까지 기다립니다. (0) | 2020.11.14 |
npm 설치시 최대 호출 스택 크기 초과 (0) | 2020.11.14 |
더 나은 Windows 명령 줄 셸 (0) | 2020.11.14 |
"무한"반복자가 잘못된 설계입니까? (0) | 2020.11.14 |