Skip to content

Commit

Permalink
完全重构模块结构,升级JDER至1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
EB-wilson committed Apr 10, 2024
1 parent 658de8e commit 31f8010
Show file tree
Hide file tree
Showing 188 changed files with 559 additions and 851 deletions.
28 changes: 6 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
需要快速使用UniverseCore,你只需要在`build.gradle`中添加如下依赖项:

dependencies {
compileOnly "com.github.EB-wilson.UniverseCore:mindustry:$uncVersion"
compileOnly "com.github.EB-wilson.UniverseCore:utilties:$uncVersion"
...
compileOnly "com.github.EB-wilson.UniverseCore:core:$uncVersion"
...
}
这包含了主要的mod开发库,但更多时候你需要用到一些其他模块才能更好的使用,一组标准的导入语句如下:

dependencies {
compileOnly "com.github.EB-wilson.UniverseCore:mindustry:$uncVersion"//涵盖了大部分mod制作相关的工具
compileOnly "com.github.EB-wilson.UniverseCore:utilties:$uncVersion"//实用工具集,包含了许多通用工具模块
compileOnly "com.github.EB-wilson.UniverseCore:abstract:$uncVersion"//功能抽象层,一些平台相关的行为被抽象为接口,要使用平台相关API时必须导入该模块
compileOnly "com.github.EB-wilson.UniverseCore:implabstract:$uncVersion"//中间实现层,有一些关于mod和加载器的功能
compileOnly "com.github.EB-wilson.UniverseCore:dynamilizer:$uncVersion"//JDER动态化仓库的内置模块
...
compileOnly "com.github.EB-wilson.UniverseCore:core:$uncVersion"//涵盖了大部分mod制作相关的工具
compileOnly "com.github.EB-wilson.UniverseCore:annotations:$uncVersion"//包括组件化接口在内的注解处理器
annotationProcessor "com.github.EB-wilson.UniverseCore:annotations:$uncVersion"//使用注解处理器
//以下是通常不会用到的内部模块,但仍然允许导入,便于对一些较为复杂的需求进行自定义行为
//compileOnly "com.github.EB-wilson.UniverseCore:core:$uncVersion"//仅有一个核心静态容器,保存了所有的功能接口的实现单例
//compileOnly "com.github.EB-wilson.UniverseCore:android:$uncVersion"//平台相关的功能在安卓的默认实现
//compileOnly "com.github.EB-wilson.UniverseCore:android26:$uncVersion"//在安卓API26以上的安卓平台运行时的实现
//compileOnly "com.github.EB-wilson.UniverseCore:desktop:$uncVersion"//平台相关的功能在桌面的默认实现
//compileOnly "com.github.EB-wilson.UniverseCore:desktop9:$uncVersion"//当桌面版运行时VM版本1.9以上的平台实现
...
}

由于mod加载机制的问题,无法很好的控制mod的加载顺序,且为了保证mod可以正常运行,如果你不想自己编写加载控制,那么你需要导入并使用`annotations`模块(如前文所示),并在你的mod主类添加注解`@Annotations.ImportUNC`,下面是一个实例:
Expand All @@ -34,18 +32,4 @@

这么做之后,当你的mod启动时会检查该前置是否正确安装,如果前置缺失,游戏会弹出提示,指导玩家安装该前置。关于导入语句当中的`requireVersion`,这表示的是你的mod当前版本要求的最低UniverseCore版本号

另外,如果你用于编译的JDK版本为14以上,那么你可能需要在使用了`annotations`模块的build.gradle文件中额外添加如下代码后才能正常编译:

tasks.withType(JavaCompile){
options.fork = true
options.forkOptions.jvmArgs.addAll([
"--add-opens", "jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
"--add-opens", "jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
"--add-opens", "jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED",
"--add-opens", "jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED",
"--add-opens", "jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
"--add-opens", "jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED"
])
}

(待施工)
37 changes: 0 additions & 37 deletions abstract/build.gradle

This file was deleted.

23 changes: 2 additions & 21 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,41 +32,22 @@ tasks.withType(JavaCompile){
}

dependencies {
compileOnly project(":dynamilizer")

compileOnly 'org.ow2.asm:asm:9.4'

compileOnly "com.github.Anuken.Arc:arc-core:$mindustryVersion"
compileOnly "com.github.Anuken.Mindustry:core:$mindustryVersion"
implementation 'com.jakewharton.android.repackaged:dalvik-dx:11.0.0_r3'
compileOnly 'com.jakewharton.android.repackaged:dalvik-dx:11.0.0_r3'

compileOnly files("libs/android.jar")

compileOnly project(":core")
compileOnly project(":abstract")
compileOnly project(":implabstract")
compileOnly project(":utilities")
compileOnly project(":dynamilizer")

annotationProcessor project(":annotations")

testCompileOnly "com.jakewharton.android.repackaged:dalvik-dx:11.0.0_r3"
testCompileOnly project(":core")
testCompileOnly project(":abstract")
testCompileOnly project(":implabstract")
testCompileOnly project(":utilities")
}

shadowJar {
dependencies {
exclude dependency("com.github.Anuken.Arc:arc-core:$mindustryVersion")
exclude dependency("com.github.Anuken.Mindustry:core:$mindustryVersion")
exclude dependency("com.jakewharton.android.repackaged:dalvik-dx:11.0.0_r3")

exclude project(":core")
exclude project(":abstract")
exclude project(":implabstract")
exclude project(":utilities")
}
}

repositories {
Expand Down
14 changes: 7 additions & 7 deletions android/src/main/java/universecore/SetPlatformImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import universecore.androidcore.AndroidMethodInvokeHelper;
import universecore.androidcore.handler.AndroidClassHandler;
import universecore.util.AccessibleHelper;
import universecore.util.mods.IllegalModHandleException;
import universecore.util.IllegalModHandleException;
import universecore.util.mods.ModGetter;
import universecore.util.mods.ModInfo;

Expand Down Expand Up @@ -91,13 +91,13 @@ public static void setImplements(){
Constructor<? extends FieldAccessHelper> faCstr = fieldAccess26Type.getConstructor();
Constructor<? extends MethodInvokeHelper> miCstr = methodInvoke26Type.getConstructor();
ImpCore.fieldAccessHelper = faCstr.newInstance();
ImpCore.methodInvokeHelper = miCstr.newInstance();
UncCore.fieldAccessHelper = faCstr.newInstance();
UncCore.methodInvokeHelper = miCstr.newInstance();
}catch(ClassNotFoundException|NoSuchMethodException|InstantiationException|IllegalAccessException|InvocationTargetException|IOException e){
throw new RuntimeException(e);
}
}catch(ClassNotFoundException ignored){*/
ImpCore.accessibleHelper = new AccessibleHelper() {
UncCore.accessibleHelper = new AccessibleHelper() {
@Override
public void makeAccessible(AccessibleObject object) {
object.setAccessible(true);
Expand All @@ -108,11 +108,11 @@ public void makeClassAccessible(Class<?> clazz) {
//no action
}
};
ImpCore.fieldAccessHelper = new AndroidFieldAccessHelper();
ImpCore.methodInvokeHelper = new AndroidMethodInvokeHelper();
UncCore.fieldAccessHelper = new AndroidFieldAccessHelper();
UncCore.methodInvokeHelper = new AndroidMethodInvokeHelper();
//}

ImpCore.classes = modMain -> {
UncCore.classesFactory = modMain -> {
try{
if(!Mod.class.isAssignableFrom(modMain))
throw new IllegalModHandleException("class was not a mod main class");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,23 @@
import com.android.dx.merge.DexMerger;
import dalvik.system.BaseDexClassLoader;
import dalvik.system.DexClassLoader;
import universecore.util.classes.BaseGeneratedClassLoader;
import universecore.util.classes.AbstractGeneratedClassLoader;
import universecore.util.classes.JarList;
import universecore.util.handler.FieldHandler;
import universecore.util.handler.MethodHandler;
import universecore.util.mods.ModInfo;

import java.io.File;
import java.io.IOException;

public class AndroidGeneratedClassLoader extends BaseGeneratedClassLoader{
public class AndroidGeneratedClassLoader extends AbstractGeneratedClassLoader {
private ClassLoader dvLoader;
protected final ModInfo mod;

public AndroidGeneratedClassLoader(ModInfo mod, ClassLoader parent){
super(mod, parent);
super(JarList.inst().getCacheFile(mod).file(), parent);
this.mod = mod;

updateLoader();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import dynamilize.classmaker.ByteClassLoader;
import dynamilize.classmaker.ClassInfo;
import dynamilize.classmaker.CodeBlock;
import dynamilize.classmaker.code.ILocal;
import dynamilize.classmaker.code.IMethod;
import dynamilize.classmaker.code.IOperate;
import org.objectweb.asm.Opcodes;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package universecore.androidcore.classes;

import arc.Core;
import arc.files.Fi;
import com.android.dex.Dex;
import com.android.dex.DexFormat;
import com.android.dx.command.dexer.DxContext;
import com.android.dx.merge.DexMerger;
import dalvik.system.BaseDexClassLoader;
import dalvik.system.DexClassLoader;
import universecore.util.classes.BaseDynamicClassLoader;
import universecore.util.classes.AbstractDynamicClassLoader;
import universecore.util.classes.JarList;
import universecore.util.handler.FieldHandler;
import universecore.util.handler.MethodHandler;
Expand All @@ -22,6 +24,8 @@
import java.util.jar.JarOutputStream;

public class DexLoaderFactory{
public static Fi jarFileCache = Core.files.cache("tempGenerate.jar");

private static Class<?> inMemoryLoaderClass;
private static Constructor<?> inMemLoaderCstr;

Expand Down Expand Up @@ -52,9 +56,9 @@ public static void writeFile(byte[] data, File file) throws IOException{
}
}

public static abstract class AsClassDexLoader extends BaseDynamicClassLoader{
public static abstract class AsClassDexLoader extends AbstractDynamicClassLoader {
protected AsClassDexLoader(ClassLoader parent){
super(parent);
super(jarFileCache.file(), parent);
}

public abstract void reset();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
import universecore.androidcore.classes.AndroidGeneratedClassLoader;
import universecore.androidcore.classes.DexGenerator;
import universecore.androidcore.classes.DexLoaderFactory;
import universecore.util.classes.AbstractFileClassLoader;
import universecore.util.classes.BaseDynamicClassLoader;
import universecore.util.classes.BaseGeneratedClassLoader;
import universecore.util.classes.JarList;
import universecore.util.classes.*;
import universecore.util.handler.ClassHandler;
import universecore.util.mods.ModGetter;
import universecore.util.mods.ModInfo;
Expand All @@ -27,10 +24,10 @@
import java.util.Arrays;

public class AndroidClassHandler implements ClassHandler{
protected static final BaseDynamicClassLoader dynamicLoader =
protected static final AbstractDynamicClassLoader dynamicLoader =
DexLoaderFactory.getClassLoader(AndroidClassHandler.class.getClassLoader());

protected final BaseGeneratedClassLoader generatedLoader;
protected final AbstractGeneratedClassLoader generatedLoader;

protected boolean generateFinished;

Expand Down
3 changes: 1 addition & 2 deletions android26/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@ tasks.withType(JavaCompile){
}

dependencies {
compileOnly project(":dynamilizer")
compileOnly "com.github.Anuken.Arc:arc-core:$mindustryVersion"
compileOnly "com.github.Anuken.Mindustry:core:$mindustryVersion"

compileOnly project(":core")
compileOnly project(":abstract")
implementation project(":android")
compileOnly project(":dynamilizer")

annotationProcessor project(":annotations")
}
Expand Down
Binary file modified android26/build/tmp/compileJava/previous-compilation-data.bin
Binary file not shown.
Loading

0 comments on commit 31f8010

Please sign in to comment.