gpt4 book ai didi

android - Android Studio-如何导出包含其他jar的jar?

转载 作者:行者123 更新时间:2023-12-03 06:25:36 25 4
gpt4 key购买 nike

我使用下面的gradle生成.jar文件

当我使用下面的gradle导出时,我能够生成.jar文件,但它没有附加从属MyJar文件。

apply plugin: 'com.android.library'//To generate Jar

android {
compileSdkVersion 24
buildToolsVersion "25.0.0"
sourceSets {
main {
//Path to My source code
java {
srcDir 'src/main/java'
}
}
}
defaultConfig {

minSdkVersion 15
targetSdkVersion 24

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

}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.1'
testCompile 'junit:junit:4.12'
compile files('libs/MyJar.jar')//MyJar When generating the Jar this is not include by gradle?
}

//task to delete the old jar
task deleteOldJar(type: Delete) {
delete 'release/ExportedJar.jar'
}

//task to export contents as jar
task exportJar(type: Copy) {
from('build/intermediates/bundles/release/')
into('release/')
include('classes.jar')
//include('MyJar.jar')//Tried this but No luck
rename('classes.jar', 'ExportedJar.jar')
}

exportJar.dependsOn(deleteOldJar, build)

如何实现这一目标...是否有任何转变。

最佳答案

您想要实现的是构建一个所谓的“胖子”。

向库的build.gradle添加另一个任务:

task fatJar(type: Jar) {
baseName = project.name + '-all'
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}

并通过命令行调用:
gradlew fatJar

如果您只想从 .jar文件夹中添加 lib,则将其添加到 build.gradle:
jar {
into('lib') {
from 'libs'
}
}

并从命令行调用:
gradlew :{library_module_name}:jar

关于android - Android Studio-如何导出包含其他jar的jar?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40763347/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com