buid.gradle
plugins {
id 'java'
id 'war'
id 'maven-publish'
id 'org.bytedeco.gradle-javacpp-build' version '1.5.9'
}
sourceCompatibility = 1.8
compileJava. options. encoding = 'UTF-8'
group = 'kl.kcs'
repositories {
gradlePluginPortal ( )
google ( )
mavenCentral ( )
}
dependencies {
implementation fileTree ( dir: 'src/libs' , includes: [ '*.jar' ] )
implementation 'org.bytedeco:javacpp:1.5.9'
}
sourceSets {
main {
resources {
srcDir 'src/main/resources'
srcDir 'src/main/java'
}
}
}
tasks. withType ( JavaCompile) . configureEach {
options. encoding = "UTF-8"
}
tasks. withType ( org. bytedeco. gradle. javacpp. BuildTask) . configureEach {
println "javacppPlatform= $ javacppPlatform "
def projdir = projectDir. getCanonicalPath ( ) ;
includePath= [ projdir+ File. separator+ "src" + File. separator+ "main" + File. separator+ "cpp" + File. separator+ "include" ]
if ( javacppPlatform. startsWith ( "android" ) ) {
if ( javacppPlatform == "android-arm" ) {
linkPath = [ projdir + "/libs/armeabi-v7a" ] ;
} else if ( javacppPlatform == "android-arm64" ) {
linkPath = [ projdir + "/libs/arm64-v8a" ] ;
}
def ndkPath = "D:\\Android\\Sdk\\ndk\\20.0.5594570"
properties = " $ javacppPlatform -clang"
propertyKeysAndValues = [ 'platform.root' : ndkPath,
'platform.compiler' : " ${ ndkPath } \\toolchains\\llvm\\prebuilt\\windows-x86_64\\bin\\clang++.exe" . toString ( ) ,
]
println ( "propertyKeysAndValues = ${ propertyKeysAndValues } " )
test. enabled = false
println ( "linkPath = ${ linkPath } " )
} else if ( javacppPlatform. startsWith ( "windows" ) ) {
properties = " $ javacppPlatform -mingw"
if ( javacppPlatform. startsWith ( "windows-x86_64" ) ) {
linkPath = [ projdir + "/javacppbuild/ $ javacppPlatform " ] ;
propertyKeysAndValues = [
'platform.compiler' : "D:\\mingw\\mingw64\\bin\\gcc.exe" . toString ( ) ,
'platform.compiler.output' : '-D_JNI_IMPLEMENTATION_ -Wl,-Bstatic -lstdc++ -lgcc_eh -lpthread -Wl,-Bdynamic -Wl,--kill-at -Wall -fPIC -shared -o\u0020'
]
} else {
linkPath = [ projdir + "/javacppbuild/ $ javacppPlatform " ] ;
propertyKeysAndValues = [
'platform.compiler' : "D:\\mingw\\mingw32\\bin\\gcc.exe" . toString ( ) ,
'platform.compiler.output' : '-D_JNI_IMPLEMENTATION_ -Wl,-Bstatic -lstdc++ -lgcc_eh -lpthread -Wl,-Bdynamic -Wl,--kill-at -Wall -fPIC -shared -o\u0020'
]
}
println ( "linkPath = ${ linkPath } " )
println ( "propertyKeysAndValues = ${ propertyKeysAndValues } " )
test. enabled = false
} else if ( javacppPlatform. startsWith ( "linux-x86_64" ) ) {
linkPath = [ projdir + "/javacppbuild/linux-x86_64" ] ;
} else if ( javacppPlatform. startsWith ( "linux-arm64" ) ) {
linkPath = [ projdir + "/javacppbuild/linux-arm64" ] ;
} else if ( javacppPlatform. startsWith ( "linux-mips64el" ) ) {
linkPath = [ projdir + "/javacppbuild/linux-mips64el" ] ;
}
}
jar {
group = " ${ group } "
}
javacppBuildParser {
classOrPackageNames = [ 'com/kl/kcs/*' ]
outputDirectory = file ( " $ buildDir /generated/sources/javacpp/" )
}
javacppBuildCompiler {
deleteJniFiles = true
copyLibs = true
}
mingw编译问题
使用mingw编译会引入三个额外的库,在其他机器上找不到 解决这个的办法是将这三个库静态链接
'platform.compiler.output' : '-D_JNI_IMPLEMENTATION_ -Wl,-Bstatic -lstdc++ -lgcc_eh -lpthread -Wl,-Bdynamic -Wl,--kill-at -Wall -fPIC -shared -o\u0020'