2 naruto900814two naruto900814two 于 2014.12.10 14:56 提问

gradle打包Android程序,如何打包时不包含依赖包

使用gradle打包Android程序,希望不包含依赖的lib中的jar包,就像在eclipse的build Path中勾掉依赖,同理下图的操作怎么在gradle的构建打包中实现

3个回答

joyerf
joyerf   2015.01.14 17:05

Eclipse这样

joyerf
joyerf   2015.01.14 17:08

楼主有啥解决思路吗?

joyerf
joyerf   2015.01.14 17:14

https://stackoverflow.com/questions/16107477/gradle-how-to-make-a-compile-scope-file-dependency-excluded-in-packaging

There probably is a cleaner and simpler solution but you could then specify a custom configuration:

configurations {
compileOnly
}
and then specify all dependencies:

dependencies {
compile fileTree(dir: 'dependencies/compile/archive', include: '*.jar', exclude: 'management.jar')
compileOnly files('dependencies/compile/archive/management.jar')
}
Finally add the compileOnly configuration to classpaths of all source sets

sourceSets.all {
compileClasspath += configurations.compileOnly
}
This way management.jar should be on the classpath for compilation but won't be packaged.

EDIT Only now I fully understand your problem. The following worked for me on a test project.

In core project gradle file:

repositories {
flatDir {
dirs 'dependencies/compile/archive'
}
}

dependencies {
compile fileTree(dir: 'dependencies/compile/archive', include: '*.jar', exclude: 'management.jar')
compile ':management:'
}
In project that depends on core:

repositories {
flatDir {
dirs new File(project(':core').projectDir, 'dependencies/compile/archive')
}
}

dependencies {
compile(project(':core')) {
exclude module: 'management'
}
compileOnly ':management':
}

sourceSets.all {
compileClasspath += configurations.compileOnly
}

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!