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

Error when running gradlew build #40

Closed
pepperoni42069 opened this issue May 26, 2022 · 17 comments
Closed

Error when running gradlew build #40

pepperoni42069 opened this issue May 26, 2022 · 17 comments
Labels

Comments

@pepperoni42069
Copy link

Task :wasm FAILED
compiler: jwebassembly-master-SNAPSHOT.jar
WASM compile failed with: Abstract or native method can not be used: java/lang/ref/Reference.refersTo0(Ljava/lang/Object;)Z
If you want to use classes with native code, you must use a library that implements these native methods, such as 'de.inetsoftware:jwebassembly-api:+'.
at java.lang.ref.Reference.refersTo0(Reference.java)

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':wasm'.

Abstract or native method can not be used: java/lang/ref/Reference.refersTo0(Ljava/lang/Object;)Z
If you want to use classes with native code, you must use a library that implements these native methods, such as 'de.inetsoftware:jwebassembly-api:+'.
at java.lang.ref.Reference.refersTo0(Reference.java)

  • Try:

Run with --stacktrace option to get the stack trace.
Run with --info or --debug option to get more log output.
Run with --scan to get full insights.

BUILD FAILED in 2s
3 actionable tasks: 3 executed

@pepperoni42069
Copy link
Author

also is gradlew build even the right command

@Horcrux7
Copy link
Member

Horcrux7 commented May 26, 2022

Yes, you can use gradlew if you like it.

Which Java version do you use?

I have create a wiki page for this error to help with this typical problem.

@pepperoni42069
Copy link
Author

i tried both java 8 and 17 both give me the same error

@pepperoni42069
Copy link
Author

pepperoni42069 commented May 27, 2022

also here is the build.gradle :

buildscript {
    repositories {
        maven { url uri('https://jitpack.io') }
    }
    dependencies {
        classpath 'com.github.i-net-software:jwebassembly-gradle:master-SNAPSHOT'
    }
}

apply plugin: 'de.inetsoftware.jwebassembly'

repositories {
    maven { url 'https://jitpack.io' }
    mavenCentral()
}
dependencies {
    implementation 'de.inetsoftware:jwebassembly-api:0.4'
}

archivesBaseName = 'HelloWorld'


sourceSets {
    main {
        java {
            srcDir 'src/main/java'
        }
    }
}

wasm {
    //Get more debug information if there are problems.
    //logging.level = LogLevel.DEBUG
    //logging.levelInternal = LogLevel.DEBUG

    //Change the output format to the text format *.wat.
    //This can be helpful to understand the problems if you see the generated code as text format.
    //format = 'text'

    //The used JWebAssembly compiler version. The default is the latest release '+'.
    //You can set any valid Gradle version string or a full dependency string.
    //The snapshot version is recommended until a stable release.
    //compilerVersion = 0.2
    compilerVersion = 'com.github.i-net-software:jwebassembly:master-SNAPSHOT'

    //Write method and parameter names into the output *.wasm file.
    //The file will be approximate 10% larger. And it generate a source map.
    //With a source map you can see in the debugger of the browser your source code if available.
    debugNames = true

    //Set an absolute or relative path between the final wasm file location and the source files location.
    ///This is needed for debugging in the browser. It work only if debugNames = true.
    //sourceMapBase = '../../src/main/java/'
    //sourceMapBase = '/src/main/java/'

    //set the destination dir
    //destinationDir = file( 'targetDir' )
}

@Horcrux7
Copy link
Member

  • In Java 8 I can not find a method java/lang/ref/Reference.refersTo0() I expect that you have an error for a different method.
  • Java 17 I have never try. The next step will be Java 11.
  • The question is not how your Gradle script look like. The script seems to work. The problem is your Java code which you try to compile.
  • Do you have analyze the debug output from the compiler?

@pepperoni42069
Copy link
Author

I think the issue could be in: package de.inetsoftware.jwebassembly.web.JSObject.java. Line 18. Can't resolve symbol Nonnull.

@pepperoni42069
Copy link
Author

im 99% sure that this is the issue, i changed my code to an example here and everything worked fine

@pepperoni42069
Copy link
Author

pepperoni42069 commented May 27, 2022

heres the original code that didn't work.

`package org.pepperoni;

/*

  • Copyright 2019 Volker Berlin (i-net software)
  • Licensed under the Apache License, Version 2.0 (the "License");
  • you may not use this file except in compliance with the License.
  • You may obtain a copy of the License at
  •  http://www.apache.org/licenses/LICENSE-2.0
    
  • Unless required by applicable law or agreed to in writing, software
  • distributed under the License is distributed on an "AS IS" BASIS,
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • See the License for the specific language governing permissions and
  • limitations under the License.
    */
    import de.inetsoftware.jwebassembly.api.annotation.Export;
    import de.inetsoftware.jwebassembly.web.dom.Document;
    import de.inetsoftware.jwebassembly.web.dom.HTMLElement;
    import de.inetsoftware.jwebassembly.web.dom.Text;
    import de.inetsoftware.jwebassembly.web.dom.Window;

public class HelloWorld {

@Export
public static void main() {
    Document document = Window.document();
    HTMLElement div = document.createElement("div");
    Text text = document.createTextNode("Hello World, this text come from WebAssembly.");
    div.appendChild( text );
    document.body().appendChild( div );
}

}
`

@pepperoni42069
Copy link
Author

This is because JWebAssembly-API uses java 8, and javax.annoatation.Nonnull doesn't exist in newer vesrion. I will try and make pull request for java 17 compatability

@pepperoni42069
Copy link
Author

Whats the exact jdk and jdk version you use?

@pepperoni42069
Copy link
Author

I added // https://mvnrepository.com/artifact/com.google.code.findbugs/jsr305 implementation group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.2' to my build.gradle and everything works. You can either update the documentation for building with gradle in the wiki, or do some rewriting of JWebAssembly-API to make everything work without adding findbugs to build.gradle.

@Horcrux7
Copy link
Member

Which error do you receive? The annotations are only needed at compile time. Try you to compile the library?

I does not understand what you means. In the start of this thread you point to java.lang.ref.Reference.refersTo0(Reference.java). Now you switch to javax.annoatation.Nonnull. I can not see any context between both.

@pepperoni42069
Copy link
Author

I think this means, your trying to make a refernce to something that doesn't exist, javax.annoatation.Nonnull. Since i included a libary which has javax.annoatation.Nonnull it can resolve the refernce.

@Horcrux7
Copy link
Member

Enable the debug log level and send the log output from compiler.

@pepperoni42069
Copy link
Author

I already fixed the error but ok

@pepperoni42069
Copy link
Author

acctualy nevermind it just decided to work without including fingbugs

@pepperoni42069
Copy link
Author

ok

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

No branches or pull requests

2 participants