Open bingoogolapple opened 6 years ago
private void generateModuleFile(Filer filer, String fileName) {
try {
FileObject fileObject = filer.createResource(StandardLocation.CLASS_OUTPUT, "assets", fileName);
String tempFilePath = fileObject.getName();
String schemaFilePath = tempFilePath.substring(0, tempFilePath.indexOf("build/intermediates/classes")) + fileName;
FileUtils.writeStringToFile(new File(schemaFilePath), "", StandardCharsets.UTF_8);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(String.format(">>> 生成文件 %s 失败 %s", fileName, e.getMessage()));
}
}
/**
* 将模块名称信息写到
* 1.「模块/build/intermediates/classes/debug/assets/xxxx/」目录下
* 2.「aar 解压后目录/classes.jar 解压后目录/assets/xxxx/」目录下
*
* 存在多个同名文件时会中断编译
*
* Android 中通过 AssetManager assetManager = mApplication.getResources().getAssets();
* String[] list = assetManager.list('xxxx'); 来获取
*/
private void writeModuleNameAssetFile(Filer filer, String moduleName) {
Writer writer = null;
try {
String path = "assets/xxxx/" + moduleName;
FileObject fileObject = filer.createResource(StandardLocation.CLASS_OUTPUT, "", path);
writer = fileObject.openWriter();
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(String.format(">>> 写 assets 文件 %s 失败 %s", moduleName, e.getMessage()));
} finally {
if (writer != null) {
try {
writer.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}