Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Javacpp 1.5 build failed with Gradle #1311

Closed
onionf91 opened this issue Oct 5, 2019 · 10 comments
Closed

Javacpp 1.5 build failed with Gradle #1311

onionf91 opened this issue Oct 5, 2019 · 10 comments

Comments

@onionf91
Copy link

onionf91 commented Oct 5, 2019

Following configuration work perfect with Javacpp 1.4.x

tasks.compileJava.doLast {
    def projectDir = project.projectDir.absolutePath
    def jsonCppIncludeDir = "$projectDir/../external/modules/jsoncpp/include"
    javaexec {
        main 'org.bytedeco.javacpp.tools.Builder'
        classpath files(configurations.javacpp.asPath)
        args '-cp', tasks.compileJava.destinationDir,
             "-Dplatform.includepath=$projectDir/src/main/cpp:$jsonCppIncludeDir",
             "-Dplatform.root=$System.env.NDK/toolchains/llvm/prebuilt/linux-x86_64",
             '-Dplatform.compiler=bin/clang++',
             "-Dplatform.compiler.default=-O3 -s",
             '-Dplatform.compiler.output=-D__ANDROID_API__=28 -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -target aarch64-linux-android28 -march=armv8-a -Wall -static-libstdc++ -fPIC -shared -Wl,--no-undefined -z text -o\u0020',
             '-Dplatform.link=log',
             "-Dplatform.compiler.srcJsonCpp=${jsonCppSource()}",
             '-Dplatform.library.path=lib/arm64-v8a/'
    }
}

But I got build failed exception as below since I upgrade Javacpp version to 1.5.x

> Task :library:compileJava FAILED
JavaCPP version 1.5.1
Copyright (C) 2011-2019 Samuel Audet <samuel.audet@gmail.com>
Project site: https://github.com/bytedeco/javacpp

Usage: java -jar javacpp.jar [options] [class or package (suffixed with .* or .**)] [commands]

where options include:

    -classpath <path>      Load user classes from path
    -encoding <name>       Character encoding used for input and output files
    -d <directory>         Output all generated files to directory
    -o <name>              Output everything in a file named after given name
    -clean                 Delete the output directory before generating anything in it
    -nogenerate            Do not try to generate C++ source files, only try to parse header files
    -nocompile             Do not compile or delete the generated C++ source files
    -nodelete              Do not delete generated C++ JNI files after compilation
    -header                Generate header file with declarations of callbacks functions
    -copylibs              Copy to output directory dependent libraries (link and preload)
    -copyresources         Copy to output directory resources listed in properties
    -jarprefix <prefix>    Also create a JAR file named "<prefix>-<platform>.jar"
    -properties <resource> Load all platform properties from resource
    -propertyfile <file>   Load all platform properties from file
    -D<property>=<value>   Set platform property to value
    -Xcompiler <option>    Pass option directly to compiler

and where optional commands include:

    -exec [args...]        After build, call java command on the first class
    -print <property>      Print the given platform property, for example, "platform.includepath", and exit
                           "platform.includepath" has jni.h, jni_md.h, etc, and "platform.linkpath", the jvm library


Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.4.1/userguide/command_line_interface.html#sec:command_line_warnings
1 actionable task: 1 executed
<-------------> 0% WAITING
> :library:compileJava

FAILURE: Build failed with an exception.

Is there any migration guide for Gradle users?

@saudet
Copy link
Member

saudet commented Oct 5, 2019 via email

@onionf91
Copy link
Author

onionf91 commented Oct 5, 2019

The error message that gradle return is non-zero exit.

> Process 'command '/home/jason/android-studio/jre/bin/java'' finished with non-zero exit value 2

and stacktrace as below

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':library:compileJava'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$3.accept(ExecuteActionsTaskExecuter.java:151)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$3.accept(ExecuteActionsTaskExecuter.java:148)
        at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:191)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:141)
        at org.gradle.api.internal.tasks.execution.ResolveBeforeExecutionStateTaskExecuter.execute(ResolveBeforeExecutionStateTaskExecuter.java:75)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:62)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:108)
        at org.gradle.api.internal.tasks.execution.ResolveBeforeExecutionOutputsTaskExecuter.execute(ResolveBeforeExecutionOutputsTaskExecuter.java:67)
        at org.gradle.api.internal.tasks.execution.ResolveAfterPreviousExecutionStateTaskExecuter.execute(ResolveAfterPreviousExecutionStateTaskExecuter.java:46)
        at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:94)
        at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:46)
        at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:95)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:57)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:56)
        at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:36)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:73)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:52)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:49)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:416)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:406)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:102)
        at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:49)
        at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:43)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:355)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:343)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:336)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:322)
        at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker$1.execute(DefaultPlanExecutor.java:134)
        at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker$1.execute(DefaultPlanExecutor.java:129)
        at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.execute(DefaultPlanExecutor.java:202)
        at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.executeNextNode(DefaultPlanExecutor.java:193)
        at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:129)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
        at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
        at java.base/java.lang.Thread.run(Thread.java:835)
Caused by: org.gradle.process.internal.ExecException: Process 'command '/home/jason/android-studio/jre/bin/java'' finished with non-zero exit value 2
        at org.gradle.process.internal.DefaultExecHandle$ExecResultImpl.assertNormalExitValue(DefaultExecHandle.java:396)
        at org.gradle.process.internal.DefaultJavaExecAction.execute(DefaultJavaExecAction.java:38)
        at org.gradle.process.internal.DefaultExecActionFactory.javaexec(DefaultExecActionFactory.java:129)
        at org.gradle.groovy.scripts.DefaultScript.javaexec(DefaultScript.java:250)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:567)
        at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:104)
        at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:326)
        at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:352)
        at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:68)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:168)
        at build_crebjz1ptcfx1oicj6w5zv7al$_run_closure4.doCall(/home/jason/Documents/repo/up-source-provider/unifiedprotocol/build.gradle:25)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:567)
        at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:104)
        at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:326)
        at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:264)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1041)
        at groovy.lang.Closure.call(Closure.java:411)
        at groovy.lang

@saudet
Copy link
Member

saudet commented Oct 5, 2019 via email

@onionf91
Copy link
Author

onionf91 commented Oct 5, 2019

If I add args' -print and /some/where/ then the task just exit and nothing to do. I guess the process exit by following logic:

//org.bytedeco.javacpp.tools.Builder.java
...
        if (printPath != null) {
            Collection<Class> classes = builder.classScanner.getClasses();
            ClassProperties p = Loader.loadProperties(classes.toArray(new Class[classes.size()]), builder.properties, true);
            builder.includeJavaPaths(p, builder.header);
            for (String s : p.get(printPath)) {
                System.out.println(s);
            }
            System.exit(0);
        } else if (!addedClasses) {
            printHelp();
            System.exit(2);
        }
...

If I don't put -print and /some/where as args, then gradle's javaexec just return exit code 2 and help info from javacpp. That's why can't I collect any further error message...

@onionf91
Copy link
Author

onionf91 commented Oct 5, 2019

My Gradle configuration is execute javacpp's builder after compile java task, then specific compiled java classes by -cp argument. Its seems like 1.5.x version's builder will just exit with 2 and print help info when *.java file doesn't present on arg list.

@saudet
Copy link
Member

saudet commented Oct 6, 2019

I see what's missing. It used to process all classes by default, but this behavior was confusing, so now we need to specify the classes we want to process, just like it is for other tools like java or javac. If you like the previous default behavior, we should be able to add a .** as an additional argument to the command, as given by javaexec in your build file, but there is a bug preventing this from working actually. I've fixed it in commit bytedeco/javacpp@bdd18ef. Thanks for reporting!

@onionf91
Copy link
Author

onionf91 commented Oct 7, 2019

Thanks a lot.

@saudet
Copy link
Member

saudet commented Nov 6, 2019

Bug fix included in just released JavaCPP 1.5.2! Thanks for reporting.

@saudet saudet closed this as completed Nov 6, 2019
@saudet
Copy link
Member

saudet commented May 21, 2020

BTW, a build plugin for Gradle is now available here:
https://github.com/bytedeco/gradle-javacpp
If you try it out and find anything missing, please let me know!

@onionf91
Copy link
Author

I've tried it. It is pretty good and easy to use. I look forward to seeing it release and publish to maven central. Thanks for your effort and time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants