关于project.json对打包的影响
目前,此项目的说明文档中,对于project这个文件的说明好像没找到,希望作者大大能完善. 因为发现和之前的auto.js不通用. 比如,没有"ignore": ["build"]这个选项,但是有"excludedDirs": [],这个选项,不知道是否通用. 但是当"excludedDirs": [],有值的时候,会导致手机端autojs6不读取project.json文件,需要在手机端写入包名版本号等信息. "excludedDirs": ["build"]不可用
目前尚无 project.json 相关的文档, 另外 AutoJs6 对于打包项目配置功能的代码尚未更新完全 (仅包含部分有效的 JSON 字段).
ignore 字段应该是可用且有效的, 详见 https://github.com/SuperMonster003/AutoJs6/blob/7e59981147396b354c9ff27ffe0fe3e1e0bd32cb/app/src/main/java/org/autojs/autojs/project/ProjectConfig.java#L171:
@SerializedName("excludedDirs")
@SerializedNameCompatible(with = {
@With(value = "ignoredDirs", target = {"AutoJs4", "AutoX"}),
@With(value = "ignore", target = {"Unknown"}),
})
private final List<File> mExcludedDirs = new ArrayList<>();
可见 ignore, ignoreDirs, excludedDirs 均是有效的用于排除文件夹的 JSON 字段.
之所以 "需要在手机端写入报名版本号等信息", 是因为 AutoJs6 对于 project.json 文件的内容有效性进行了判断, 详见 https://github.com/SuperMonster003/AutoJs6/blob/7e59981147396b354c9ff27ffe0fe3e1e0bd32cb/app/src/main/java/org/autojs/autojs/project/ProjectConfig.java#L189:
private static boolean isValid(ProjectConfig config) {
if (TextUtils.isEmpty(config.getName())) {
return false;
}
if (TextUtils.isEmpty(config.getPackageName())) {
return false;
}
if (TextUtils.isEmpty(config.getVersionName())) {
return false;
}
if (TextUtils.isEmpty(config.getMainScriptFileName())) {
return false;
}
return config.getVersionCode() != -1;
}
可见有效的打包项目配置文件, 需要满足内部包含必要的可解析的有效字段, 如 [ 项目名称, 包名, 版本名称 ] 等.
private static final Gson sGson = new GsonBuilder()
.registerTypeAdapter(ProjectConfig.class, new JsonUtils.FuzzyDeserializer<ProjectConfig>())
.registerTypeAdapter(LaunchConfig.class, new JsonUtils.FuzzyDeserializer<LaunchConfig>())
.registerTypeAdapter(ScriptConfig.class, new JsonUtils.FuzzyDeserializer<ScriptConfig>())
.registerTypeAdapter(BuildInfo.class, new JsonUtils.FuzzyDeserializer<BuildInfo>())
.setPrettyPrinting()
.create();
@SerializedName("excludedDirs")
@SerializedNameCompatible(with = {
@With(value = "ignoredDirs", target = {"AutoJs4", "AutoX"}),
@With(value = "ignore", target = {"Unknown"}),
})
private final List<File> mExcludedDirs = new ArrayList<>();
猜测是Gson未注册File类型的适配器,如果设置了excludedDirs的值,因为文本无法转为File对象,则出现异常,导致上述的问题“会导致手机端autojs6不读取project.json文件”
临时解决方案:将不想打包的资源放到build目录下