问题描述
我有一个库项目,它对从项目libs目录加载的cordova.jar具有依赖关系。
这个库项目用作aar一个maven nexus。
在一个应用程序项目中,我对库项目aar(compile ...)有依赖关系。但是应用程序项目与cordova.jar具有相同的依赖关系。因此,在构建applicaton项目时,出现以下错误:
:transformClassesWithDexForDebug
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException:多个dex文件定义了Lorg / apache / cordova / AuthenticationToken ;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:579)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:517)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:164)
at com.android .dx.merge.DexMerger.merge(DexMerger.java:188)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:504)
at com.android.dx .command.dexer.Main.runMonoDex(Main.java:334)
at com.android.dx.command.dexer.Main.run(Main.java:277)
at com.android.dx .command.dexer.Main.main(Main.java:245)
at com.android.dx.command.Main.main(Main.java:106)
为了解决这个问题,我尝试在应用程序项目中加载库aar时排除cordova.jar:
依赖项{
compile('com.my.library:hybridstory:1.0'){
exclude(group:'or g.apache.cordova')
}
}
但这并不工作。我是否做错了什么?
我的第二个问题是:
是否可以排除/ libs / cordova.jar在将库项目上传为aar时,而不是在应用程序中加载库时排除cordova.jar?我怎么能用这个gradle实现这个功能:
apply plugin:'com.android.library'
apply plugin: 'maven'
archivesBaseName ='hybridstory'
group ='com ....'
version = '16 .3.0-SNAPSHOT'
android {
compileSdkVersion 23
buildToolsVersion23.0.2
defaultConfig {
minSdkVersion 16
targetSdkVersion 22
versionCode 1
版本号版本
}
buildTypes {
版本{
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
提供的文件('libs / cordova-5.1.1.jar')
testCompile'junit: junit:4.12'
compile'com.android.support:appcompat-v7:23.4.0'
compile'com ....'
}
任务createJavadoc(type:Javadoc){
source = android.sourceSets.main.java.srcDirs
title = archivesBaseName ++ version
options.overview =src / main / doc-files / overview.html
doLast {
复制{
从src / main / doc-files
复制到$ buildDir / docs / javadoc
}
}
}
uploadArchives {
存储库{
mavenDeployer {
存储库(网址:'https://maven..../content/repositories/om-releases /')
snapshotRepository(url:'https://maven..../content/repositories/om-snapshots/')
}
}
}
任务androidJavadocsJar(类型:Jar,dependsOn:createJavadoc){
classifier ='javadoc'
from createJavadoc.destinationDir
}
任务androidSourcesJar类型:Jar){
classifier ='sources'
from android.sourceSets.main.java.srcDirs
}
artifacts {
archives androidSourcesJar
archives androidJavadocsJar
}
### UPDATE ###
我尝试了Xaver Kapeller建议的提供gradle scope(谢谢!)。但是仍然有cordova.jar打包到aar中。提供的范围是不是工作,或者我错过了什么?
您可以简单地从dir yourmodule / libs中移动库文件在$ d
中修改提供的文件('libs / yourlibrary.jar')到依赖文件中提供的文件('yourlibrary.jar')。
然后清理项目并重建。
I have a library project, which has a dependency to cordova.jar which is loaded from the projects libs directory.
This library project I deploy as an aar to a maven nexus.
In an application project, I have a dependency to the library projects aar (compile ...). But the application project has the same dependency to the cordova.jar.
So when building the applicaton project, I get this error:
:transformClassesWithDexForDebug
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lorg/apache/cordova/AuthenticationToken;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:579)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:517)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:164)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:504)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
at com.android.dx.command.dexer.Main.run(Main.java:277)
at com.android.dx.command.dexer.Main.main(Main.java:245)
at com.android.dx.command.Main.main(Main.java:106)
To solve this, i tried to exclude the cordova.jar when loading the library aar in my application project:
dependencies {
compile ('com.my.library:hybridstory:1.0'){
exclude (group: 'org.apache.cordova')
}
}
But this does not work. Am I doing something wrong?
My second question is:
Is it possible to exclude the /libs/cordova.jar when uploading the library project as aar, instead of excluding the cordova.jar when loading the library in an application? How could I achieve this with this gradle:
apply plugin: 'com.android.library'
apply plugin: 'maven'
archivesBaseName = 'hybridstory'
group = 'com....'
version = '16.3.0-SNAPSHOT'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName version
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
provided files('libs/cordova-5.1.1.jar')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com....'
}
task createJavadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
title = archivesBaseName + " " + version
options.overview = "src/main/doc-files/overview.html"
doLast {
copy {
from "src/main/doc-files"
into "$buildDir/docs/javadoc"
}
}
}
uploadArchives {
repositories {
mavenDeployer {
repository(url: 'https://maven..../content/repositories/om-releases/')
snapshotRepository(url: 'https://maven..../content/repositories/om-snapshots/')
}
}
}
task androidJavadocsJar(type: Jar, dependsOn: createJavadoc) {
classifier = 'javadoc'
from createJavadoc.destinationDir
}
task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
artifacts {
archives androidSourcesJar
archives androidJavadocsJar
}
### UPDATE ###
I tried the gradle scope "provided" as suggested by Xaver Kapeller (thanks!). But there is still the cordova.jar packaged into the aar. Does the provided scope simply not work or am I missing something?
You can simply move the library file from dir yourmodule/libs to dir yourmoudle/and modify " provided files('libs/yourlibrary.jar') " to "provided files('yourlibrary.jar')" in dependency.
then clean the project and rebuild.
这篇关于从aar中排除jar库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!