我有一个 Android 项目,它依赖于外部 jar 文件,即A.jar
.
我已经配置了我的安卓build.gradle
首先构建构建的项目A.jar
。然后 Android 构建将继续。
jar 构建后,将 jar 从其构建文件夹复制到 android 项目 lib 文件夹的最佳方法是什么?
所以构建应该继续...
构建 Jar > 将 Jar 复制到库 > 构建 Android 项目。
我不使用 Android Studio,因此我仅通过 gradle 配置文件操作来配置我的项目。
当前构建 jar 的项目已被列为依赖项app/build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "saf.mobilebeats2"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
buildTypes {
debug {
applicationIdSuffix ".debug"
debuggable true
}
}
}
dependencies {
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:appcompat-v7:26.0.0'
implementation project(':dawcore')
// runtime files('../DawCore/build/libs/DawCore.jar')
}
由于您没有使用 Android Studio 并且依赖项模块位于其他一些项目正在使用的其他位置,因此您可能会考虑将 jar 复制到您的libs
依赖模块完成构建并创建要复制的 jar 后的目录。所以整体执行如下:
- 任务 1. 构建依赖模块
- 任务 2. 将 jar 文件复制到 Android 应用程序要使用的特定位置。
- 任务 3. 在构建 Android 应用程序时,将 jar 文件从该特定位置复制到您的
libs
目录。
- 任务 4. 使用以下命令构建 jar
compile files('libs/jar-from-dependency.jar')
现在对于任务 1 和 2:在build.gradle
您的依赖模块的文件。因此,在构建依赖模块后,这会将 jar 复制到复制任务中指定的位置。检查下面的复制函数,了解如何在 gradle 中编写复制函数。
apply plugin: 'java'
task finalize << {
println('Here use the copyTask to copy the jar to a specific directory after each build of your library module')
}
build.finalizedBy(finalize)
// compileJava.finalizedBy(copyJarToAndroid) <-- In your case
这里是doc与此相关的必要功能。
对于任务 3:现在任务很简单。在使用 gradle 构建之前,您需要将 jar 从该特定位置复制到您的 Android 应用程序项目中。以下是您在构建项目之前启动复制任务的方法。
task copyFiles(type: Copy) {
description = 'Copying the jar'
from 'your/jar/directory'
into project(':Path:To:ModuleFrom:Settings.gradle').file('./libs')
include 'jar-from-dependency.jar'
}
project.afterEvaluate {
preBuild.dependsOn copyFiles
}
clean.dependsOn copyFiles
clean.mustRunAfter copyFiles
这将运行copyFiles
启动 gradle clean 时的任务。
因此,对于任务 4:将 jar 添加到您的dependencies
部分。
dependencies {
// ... Other dependencies
compile files('libs/jar-from-dependency.jar')
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)