SpongePowered / Mixin

Mixin is a trait/mixin and bytecode weaving framework for Java using ASM
MIT License
1.42k stars 193 forks source link

Class version error? #132

Closed PizzaCrust closed 8 years ago

PizzaCrust commented 8 years ago

I'm using Gradle, and not using the default MixinTweaker class. I'm using a custom tweaker class to initialize Mixin.

I keep getting these unsupported class version errors, while I am using JavaVersion.JAVA_8 already.

Here is my custom tweaker class:

package net.pizzacrust.tweaker;

import net.minecraft.launchwrapper.ITweaker;
import net.minecraft.launchwrapper.LaunchClassLoader;
import org.apache.commons.io.IOUtils;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.launch.MixinBootstrap;
import org.spongepowered.asm.mixin.MixinEnvironment;
import org.spongepowered.asm.util.JavaVersion;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class MixinTweaker implements ITweaker{
    @Override
    public void acceptOptions(List<String> args, File gameDir, File assetsDir, String profile) {}

    @Override
    public void injectIntoClassLoader(LaunchClassLoader classLoader) {
        System.out.println(JavaVersion.current() + " : " + resolveCurrentVersion());
        try {
            ClassReader classReader = new ClassReader(IOUtils.toByteArray(getClass().getClassLoader().getResourceAsStream("net/pizzacrust/tweaker/MixinTweaker.class")));
            ClassNode classNode = new ClassNode();
            classReader.accept(classNode, 0);
            System.out.println(classNode.version);
        } catch (IOException e) {
            e.printStackTrace();
        }

        MixinEnvironment.setCompatibilityLevel(MixinEnvironment.CompatibilityLevel.JAVA_7);
        MixinBootstrap.init();
        MixinEnvironment.getDefaultEnvironment().addConfiguration("mixins.json");
    }

    private static double resolveCurrentVersion() {
        String version = System.getProperty("java.version");
        Matcher matcher = Pattern.compile("[0-9]+\\.[0-9]+").matcher(version);
        if (matcher.find()) {
            return Double.parseDouble(matcher.group());
        }
        return 1.6;
    }

    @Override
    public String getLaunchTarget() {
        return "org.example.main.Main";
    }

    @Override
    public String[] getLaunchArguments() {
        return new String[0];
    }
}

My mixin JSON file:

{
  "package": "net.pizzacrust.tweaker",
  "mixins": [
    "MixinMain"
  ]
}

My mixin class:

package net.pizzacrust.tweaker;

import org.example.main.Main;
import org.example.main.ResponsiveTest;
import org.spongepowered.asm.mixin.Mixin;

@Mixin(value = Main.class, remap = false)
public class MixinMain implements ResponsiveTest {
}

Log:

2016-06-11 17:35:39,879 ERROR Error processing element Queue: CLASS_NOT_FOUND
2016-06-11 17:35:41,060 ERROR Unable to locate appender ServerGuiConsole for logger
[17:35:41] [main/INFO]: Loading tweak class name net.pizzacrust.tweaker.MixinTweaker
[17:35:41] [main/INFO]: Using primary tweak class name net.pizzacrust.tweaker.MixinTweaker
[17:35:41] [main/INFO]: Calling tweak class net.pizzacrust.tweaker.MixinTweaker
1.8 : 1.8
52
[17:35:41] [main/INFO]: Compatibility level set to JAVA_7
[17:35:41] [main/INFO]: SpongePowered MIXIN Subsystem Version=0.5.6 Source=file:/C:/Users/HDL/Downloads/Forge/mcp924-beta1/eclipse/CustomTweakerTest/build/libs/CustomTweakerTest-1.0-SNAPSHOT-all.jar Env=UNKNOWN
[17:35:41] [main/INFO]: Loading tweak class name org.spongepowered.asm.mixin.MixinEnvironment$EnvironmentStateTweaker
[17:35:41] [main/INFO]: Calling tweak class org.spongepowered.asm.mixin.MixinEnvironment$EnvironmentStateTweaker
[17:35:41] [main/WARN]: Mixin environment was unable to detect the current side, sided mixins will not be applied
[17:35:41] [main/ERROR]: mixins.json:MixinMain: Unsupported mixin class version 52. Mixin requires compatibility level JAVA_8 or above.
org.spongepowered.asm.mixin.transformer.throwables.InvalidMixinException: Unsupported mixin class version 52. Mixin requires compatibility level JAVA_8 or above.
        at org.spongepowered.asm.mixin.transformer.MixinInfo$State.validateClassVersion(MixinInfo.java:228) ~[CustomTweakerTest-1.0-SNAPSHOT-all.jar:?]
        at org.spongepowered.asm.mixin.transformer.MixinInfo$State.validate(MixinInfo.java:198) ~[CustomTweakerTest-1.0-SNAPSHOT-all.jar:?]
        at org.spongepowered.asm.mixin.transformer.MixinInfo.validate(MixinInfo.java:618) ~[CustomTweakerTest-1.0-SNAPSHOT-all.jar:?]
        at org.spongepowered.asm.mixin.transformer.MixinConfig.postInitialise(MixinConfig.java:426) [CustomTweakerTest-1.0-SNAPSHOT-all.jar:?]
        at org.spongepowered.asm.mixin.transformer.MixinTransformer.prepareConfigs(MixinTransformer.java:662) [CustomTweakerTest-1.0-SNAPSHOT-all.jar:?]
        at org.spongepowered.asm.mixin.transformer.MixinTransformer.select(MixinTransformer.java:569) [CustomTweakerTest-1.0-SNAPSHOT-all.jar:?]
        at org.spongepowered.asm.mixin.transformer.MixinTransformer.transform(MixinTransformer.java:478) [CustomTweakerTest-1.0-SNAPSHOT-all.jar:?]
        at org.spongepowered.asm.mixin.transformer.MixinTransformer$Proxy.transform(MixinTransformer.java:185) [CustomTweakerTest-1.0-SNAPSHOT-all.jar:?]
        at net.minecraft.launchwrapper.LaunchClassLoader.runTransformers(LaunchClassLoader.java:279) [CustomTweakerTest-1.0-SNAPSHOT-all.jar:?]
        at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:176) [CustomTweakerTest-1.0-SNAPSHOT-all.jar:?]
        at java.lang.ClassLoader.loadClass(Unknown Source) [?:1.8.0_92]
        at java.lang.ClassLoader.loadClass(Unknown Source) [?:1.8.0_92]
        at java.lang.Class.forName0(Native Method) [?:1.8.0_92]
        at java.lang.Class.forName(Unknown Source) [?:1.8.0_92]
        at net.minecraft.launchwrapper.Launch.launch(Launch.java:131) [CustomTweakerTest-1.0-SNAPSHOT-all.jar:?]
        at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [CustomTweakerTest-1.0-SNAPSHOT-all.jar:?]
[17:35:41] [main/INFO]: Launching wrapped minecraft {org.example.main.Main}
simon816 commented 8 years ago

MixinEnvironment.setCompatibilityLevel(MixinEnvironment.CompatibilityLevel.JAVA_7);

Should this not be JAVA_8?

PizzaCrust commented 8 years ago

Removed that line and returned this log:

Note: SpongePowered Mixin Annotation Processor v0.5.6
Note: C:\Users\HDL\Downloads\Forge\mcp924-beta1\eclipse\CustomTweakerTest\src\main\java\net\pizzacrust\tweaker\MixinTweaker.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
:compileJava
:processResources UP-TO-DATE
:classes
:run
2016-06-11 17:50:38,648 ERROR Error processing element Queue: CLASS_NOT_FOUND
2016-06-11 17:50:38,696 ERROR Unable to locate appender ServerGuiConsole for logger 
[17:50:38] [main/INFO]: Loading tweak class name net.pizzacrust.tweaker.MixinTweaker
[17:50:38] [main/INFO]: Using primary tweak class name net.pizzacrust.tweaker.MixinTweaker
[17:50:38] [main/INFO]: Calling tweak class net.pizzacrust.tweaker.MixinTweaker
1.8 : 1.8
52
[17:50:38] [main/INFO]: SpongePowered MIXIN Subsystem Version=0.5.6 Source=file:/C:/Users/HDL/Downloads/Gradle/caches/modules-2/files-2.1/org.spongepowered/mixin/0.5.6-SNAPSHOT/b2232400cd45f305ccbf3cc313e75c1d538c4f30/mixin-0.5.6-SNAPSHOT.jar Env=UNKNOWN
[17:50:39] [main/INFO]: Loading tweak class name org.spongepowered.asm.mixin.MixinEnvironment$EnvironmentStateTweaker
[17:50:39] [main/INFO]: Calling tweak class org.spongepowered.asm.mixin.MixinEnvironment$EnvironmentStateTweaker
[17:50:39] [main/WARN]: Mixin environment was unable to detect the current side, sided mixins will not be applied
[17:50:39] [main/ERROR]: mixins.json:MixinMain: Unsupported mixin class version 52. Mixin requires compatibility level JAVA_8 or above.
org.spongepowered.asm.mixin.transformer.throwables.InvalidMixinException: Unsupported mixin class version 52. Mixin requires compatibility level JAVA_8 or above.
    at org.spongepowered.asm.mixin.transformer.MixinInfo$State.validateClassVersion(MixinInfo.java:228) ~[mixin-0.5.6-SNAPSHOT.jar:0.5.6-SNAPSHOT+unknown-b0.git-unknown]
    at org.spongepowered.asm.mixin.transformer.MixinInfo$State.validate(MixinInfo.java:198) ~[mixin-0.5.6-SNAPSHOT.jar:0.5.6-SNAPSHOT+unknown-b0.git-unknown]
    at org.spongepowered.asm.mixin.transformer.MixinInfo.validate(MixinInfo.java:618) ~[mixin-0.5.6-SNAPSHOT.jar:0.5.6-SNAPSHOT+unknown-b0.git-unknown]
    at org.spongepowered.asm.mixin.transformer.MixinConfig.postInitialise(MixinConfig.java:426) [mixin-0.5.6-SNAPSHOT.jar:0.5.6-SNAPSHOT+unknown-b0.git-unknown]
    at org.spongepowered.asm.mixin.transformer.MixinTransformer.prepareConfigs(MixinTransformer.java:662) [mixin-0.5.6-SNAPSHOT.jar:0.5.6-SNAPSHOT+unknown-b0.git-unknown]
    at org.spongepowered.asm.mixin.transformer.MixinTransformer.select(MixinTransformer.java:569) [mixin-0.5.6-SNAPSHOT.jar:0.5.6-SNAPSHOT+unknown-b0.git-unknown]
    at org.spongepowered.asm.mixin.transformer.MixinTransformer.transform(MixinTransformer.java:478) [mixin-0.5.6-SNAPSHOT.jar:0.5.6-SNAPSHOT+unknown-b0.git-unknown]
    at org.spongepowered.asm.mixin.transformer.MixinTransformer$Proxy.transform(MixinTransformer.java:185) [mixin-0.5.6-SNAPSHOT.jar:0.5.6-SNAPSHOT+unknown-b0.git-unknown]
    at net.minecraft.launchwrapper.LaunchClassLoader.runTransformers(LaunchClassLoader.java:279) [launchwrapper-1.11.jar:?]
    at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:176) [launchwrapper-1.11.jar:?]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424) [?:1.8.0_92]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357) [?:1.8.0_92]
    at java.lang.Class.forName0(Native Method) [?:1.8.0_92]
    at java.lang.Class.forName(Class.java:348) [?:1.8.0_92]
    at net.minecraft.launchwrapper.Launch.launch(Launch.java:131) [launchwrapper-1.11.jar:?]
    at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.11.jar:?]
[17:50:39] [main/INFO]: Launching wrapped minecraft {org.example.main.Main}
Mumfrey commented 8 years ago

The mixin tweaker is provided for a reason, use it. You should not use a custom tweaker as this breaks the co-operative loading functionality for other mixin containers.

Since you're using 0.5.6 you should be specifying the compatibility level in the config and not in the init routine.