Gradle을 사용하여 aar 라이브러리에 대한 전이 종속성이 해결되지 않았습니다.
나는 한동안 조사했고 아마 여기에서 aar 및 전이 종속성 과 관련된 가장 인기있는 답변을 보았지만 어떻게 든이 작업을 수행하는 방법이 아직 명확하지 않습니다.
그래서:
주어진 gradle 구성이있는 Android 라이브러리가 있습니다.
apply plugin: 'android-library'
apply plugin: 'android-maven'
version = "1.0.0"
group = "com.somepackage"
buildscript {
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
classpath 'com.github.dcendents:android-maven-plugin:1.0'
}
}
android {
compileSdkVersion 19
buildToolsVersion '19.0.3'
defaultConfig {
minSdkVersion 10
}
}
repositories {
maven { url 'http://www.bugsense.com/gradle/' }
}
dependencies {
provided 'com.google.android.gms:play-services:+'
provided 'com.android.support:appcompat-v7:+'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.bugsense.trace:bugsense:3.6'
compile 'commons-net:commons-net:3.3'
}
그런 다음 로컬 maven repo에 gradle install
. 배포 된 라이브러리의 POM 파일은 다음과 같습니다.
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sprezzat</groupId>
<artifactId>app</artifactId>
<version>1.0.0</version>
<packaging>aar</packaging>
<dependencies>
<dependency>
<groupId>com.bugsense.trace</groupId>
<artifactId>bugsense</artifactId>
<version>3.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
그리고 마지막으로 위의 라이브러리를 종속성으로 사용하는 내 Android 애플리케이션의 gradle 구성 :
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
mavenLocal()
}
android {
compileSdkVersion 15
buildToolsVersion "19.0.2"
defaultConfig {
minSdkVersion 10
targetSdkVersion 18
}
}
dependencies {
compile 'com.google.android.gms:play-services:+'
compile 'com.android.support:appcompat-v7:+'
compile 'com.somepackage:LIBRARY_NAME:1.0.0@aar'
}
그리고 전화에 응용 프로그램을 배포 한 후 NoClassDefFoundError
내 안드로이드 라이브러리의 컴파일 종속성에 속하는 클래스를 얻 습니다.
다음을 사용하여 내 Android 애플리케이션 종속성 검사 gradle dependencies
:
apk - Classpath packaged with the compiled main classes.
+--- com.google.android.gms:play-services:+ -> 4.3.23
| \--- com.android.support:support-v4:19.0.1 -> 19.1.0
+--- com.android.support:appcompat-v7:+ -> 19.1.0
| \--- com.android.support:support-v4:19.1.0
\--- com.somepackage:LIBRARY_NAME:1.0.0
According to above tree, all transitive dependencies are not detected. Where is the problem and how should it be done correctly?
I have solved my problem by setting transitive
attribute for my aar dependency:
compile ('com.somepackage:LIBRARY_NAME:1.0.0@aar'){
transitive=true
}
you should not use "@aar", if use "@" is become "Artifact only notation", if you want to use "@" and want have dependence transitive, you should add "transitive=true"
Try this if you are using aar locally:
compile(project(:your-library-name)) {
transitive=true
}
Simply adding @aar at the end of the dependency is what worked for me.
dependencies {
implementation 'org.videolan.vlc:libvlc:3.0.13@aar'
}
For me complete publishing solution looks like this:
apply plugin: 'com.github.dcendents.android-maven'
group = GROUP
version = VERSION
// you could move it to env variable or property
def publishFlavorless = true
def firstTask = null
android.libraryVariants.all { variant ->
if (variant.name.toLowerCase().contains("debug")) {
// Workaround for https://github.com/gradle/gradle/issues/1487
if (publishFlavorless && firstTask == null) {
def bundleTask = tasks["bundle${variant.name.capitalize()}Aar"]
firstTask = bundleTask
artifacts {
archives(firstTask.archivePath) {
builtBy firstTask
name = project.name
}
}
}
return
}
def bundleTask = tasks["bundle${variant.name.capitalize()}Aar"]
artifacts {
archives(bundleTask.archivePath) {
classifier variant.flavorName
builtBy bundleTask
name = project.name
}
}
}
install {
repositories.mavenInstaller {
// This generates POM.xml with proper parameters
pom.project {
name POM_NAME
artifactId POM_ARTIFACT_ID
// For aar it is equal to 'aar' with jar transitive dependencies won't work
packaging POM_PACKAGING
description POM_DESCRIPTION
}
}
}
The transitive = true
block is required as well ...
'Nice programing' 카테고리의 다른 글
Chrome이 로컬 jQuery 쿠키를 무시하는 이유는 무엇입니까? (0) | 2020.10.05 |
---|---|
내 git 'master'브랜치의 이름을 'release'로 어떻게 바꾸나요? (0) | 2020.10.05 |
새로운 랜덤 라이브러리가 std :: rand ()보다 나은 이유는 무엇입니까? (0) | 2020.10.05 |
C 컴파일 오류 : "변수 크기의 개체를 초기화 할 수 없습니다." (0) | 2020.10.05 |
git 로그 그래프 읽는 방법 (0) | 2020.10.05 |