在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):bytedeco/gradle-javacpp开源软件地址(OpenSource Url):https://github.com/bytedeco/gradle-javacpp开源编程语言(OpenSource Language):Java 100.0%开源软件介绍(OpenSource Introduction):Gradle JavaCPPIntroductionGradle JavaCPP offers plugins that make it easy to use JavaCPP and JavaCV as part of the Gradle build system. Please feel free to ask questions on the mailing list if you encounter any problems with the software! I am sure it is far from perfect... Required SoftwareTo use Gradle JavaCPP, you will need to download and install the following software:
Getting StartedGradle JavaCPP comes with 2 plugins:
Fully functional sample projects are also provided in the The Build PluginTo understand how JavaCPP is meant to be used, one should first take a look at the Mapping Recipes for C/C++ Libraries, but a high-level overview of the Basic Architecture is also available to understand the bigger picture. Once comfortable enough with the command line interface, the build plugin for Gradle can be used to integrate easily that workflow as part of plugins {
id 'java-library'
id 'org.bytedeco.gradle-javacpp-build' version "$javacppVersion"
}
// We can set this on the command line too this way: -PjavacppPlatform=android-arm64
ext {
javacppPlatform = 'android-arm64' // or any other platform, defaults to Loader.getPlatform()
}
dependencies {
api "org.bytedeco:javacpp:$javacppVersion"
}
tasks.withType(org.bytedeco.gradle.javacpp.BuildTask) {
// set here default values for all build tasks below, typically just includePath and linkPath,
// but also properties to set the path to the NDK and its compiler in the case of Android
}
javacppBuildCommand {
// typically set here the buildCommand to the script that fills up includePath and linkPath
}
javacppBuildParser {
// typically set here the classOrPackageNames to class names implementing InfoMap
}
javacppBuildCompiler {
// typically set here boolean flags like copyLibs
} Integration with Android StudioIt is also possible to integrate the
android.applicationVariants.all { variant ->
def variantName = variant.name.capitalize() // either "Debug" or "Release"
def javaCompile = project.tasks.getByName("compile${variantName}JavaWithJavac")
def generateJson = project.tasks.getByName("generateJsonModel$variantName")
// Compiles NativeLibraryConfig.java
task "javacppCompileJava$variantName"(type: JavaCompile) {
include 'com/example/myapplication/NativeLibraryConfig.java'
source = javaCompile.source
classpath = javaCompile.classpath
destinationDir = javaCompile.destinationDir
}
// Parses NativeLibrary.h and outputs NativeLibrary.java
task "javacppBuildParser$variantName"(type: org.bytedeco.gradle.javacpp.BuildTask) {
dependsOn "javacppCompileJava$variantName"
classPath = [javaCompile.destinationDir]
includePath = ["$projectDir/src/main/cpp/"]
classOrPackageNames = ['com.example.myapplication.NativeLibraryConfig']
outputDirectory = file("$projectDir/src/main/java/")
}
// Compiles NativeLibrary.java and everything else
javaCompile.dependsOn "javacppBuildParser$variantName"
// Generates jnijavacpp.cpp and jniNativeLibrary.cpp
task "javacppBuildCompiler$variantName"(type: org.bytedeco.gradle.javacpp.BuildTask) {
dependsOn javaCompile
classPath = [javaCompile.destinationDir]
classOrPackageNames = ['com.example.myapplication.NativeLibrary']
compile = false
deleteJniFiles = false
outputDirectory = file("$projectDir/src/main/cpp/")
}
// Picks up the C++ files listed in CMakeLists.txt
generateJson.dependsOn "javacppBuildCompiler$variantName"
}
The Platform PluginWith Maven, we are able to modify dependencies transitively using profiles, and although Gradle doesn't provide such functionality out of the box, it can be emulated via plugins. After adding a single line to the plugins {
id 'java-library'
id 'org.bytedeco.gradle-javacpp-platform' version "$javacppVersion"
}
// We can set this on the command line too this way: -PjavacppPlatform=linux-x86_64,macosx-x86_64,windows-x86_64,etc
ext {
javacppPlatform = 'linux-x86_64,macosx-x86_64,windows-x86_64,etc' // defaults to Loader.getPlatform()
}
dependencies {
api "org.bytedeco:javacv-platform:$javacvVersion" // or any other "-platform" artifacts
} Moreover, in the case of Android, its plugin is not able to use native libraries found in JAR files when building Android App Bundles (AAB files). However, to work around this limitation we can easily use Gradle to extract the files automatically, for example, in the following manner with an additional configurations {
javacpp
}
task javacppExtract(type: Copy) {
dependsOn configurations.javacpp
from { configurations.javacpp.collect { zipTree(it) } }
include "lib/**"
into "$buildDir/javacpp/"
android.sourceSets.main.jniLibs.srcDirs += ["$buildDir/javacpp/lib/"]
tasks.getByName('preBuild').dependsOn javacppExtract
}
dependencies {
implementation group: 'org.bytedeco', name: 'javacv', version: "$javacvVersion"
javacpp group: 'org.bytedeco', name: 'openblas-platform', version: "$openblasVersion-$javacppVersion"
javacpp group: 'org.bytedeco', name: 'opencv-platform', version: "$opencvVersion-$javacppVersion"
javacpp group: 'org.bytedeco', name: 'ffmpeg-platform', version: "$ffmpegVersion-$javacppVersion"
...
} Project lead: Samuel Audet samuel.audet |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论