Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,27 @@ public TaskResult execute(AndroidCompilerContext context) {

// walk components list for libraries ending in ".aar"
try {
for (Set<String> libs : context.getComponentInfo().getLibsNeeded().values()) {
Iterator<String> i = libs.iterator();
for (String type : context.getComponentInfo().getLibsNeeded().keySet()) {
Iterator<String> i = context.getComponentInfo().getLibsNeeded().get(type).iterator();
while (i.hasNext()) {
String libname = i.next();
String sourcePath = "";
if (libname.endsWith(".aar")) {
i.remove();
if (!processedLibs.contains(libname)) {
if (context.getSimpleCompTypes().contains(type) || "ANDROID".equals(type)) {
final String pathSuffix = context.getResources().getRuntimeFilesDir() + libname;
sourcePath = context.getResource(pathSuffix);
} else if (context.getExtCompTypes().contains(type)) {
final String pathSuffix = "/aars/" + libname;
sourcePath = ExecutorUtils.getExtCompDirPath(type, context.getProject(),
context.getExtTypePathCache()) + pathSuffix;
} else {
context.getReporter().error("Unknown component type: " + type, true);
return TaskResult.generateError("Error while attaching AAR libraries");
}
// explode libraries into ${buildDir}/exploded-aars/<package>/
AARLibrary aarLib = new AARLibrary(new File(context.getResource(
context.getResources().getRuntimeFilesDir() + libname)));
AARLibrary aarLib = new AARLibrary(new File(sourcePath));
aarLib.unpackToDirectory(explodedBaseDir);
context.getComponentInfo().getExplodedAarLibs().add(aarLib);
processedLibs.add(libname);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,19 @@ private static void generateExternalComponentBuildFiles(String packageName, List
JSONObject componentBuildInfo = info.buildInfo;
try {
JSONArray librariesNeeded = componentBuildInfo.getJSONArray("libraries");
JSONArray librariesAar = new JSONArray();
for (int j = 0; j < librariesNeeded.length(); ++j) {
// Copy Library files for Unjar and Jaring
String library = librariesNeeded.getString(j);
copyFile(buildServerClassDirPath + File.separator + library,
extensionTempDirPath + File.separator + library);
if (library.endsWith(".aar")) {
copyExternalAar(library, packageName);
librariesAar.put(library);
}
}
//empty the libraries meta-data to avoid redundancy
componentBuildInfo.put("libraries", new JSONArray());
componentBuildInfo.put("libraries", librariesAar);
} catch(JSONException e) {
// bad
throw new IllegalStateException("Unexpected JSON exception parsing simple_components.json",
Expand Down Expand Up @@ -344,6 +349,22 @@ private static Boolean copyFile(String srcPath, String dstPath) {
return true;
}

private static void copyExternalAar(String library, String packageName)
throws IOException {
File sourceDir = new File(buildServerClassDirPath + File.separator);
File aarFile = new File(sourceDir, library);
if (!aarFile.exists() || !library.endsWith(".aar")) {
return;
}
// Get aar dest directory
File destDir = new File(externalComponentsDirPath + File.separator + packageName + File.separator);
File aarDestDir = new File(destDir, "aars");
ensureFreshDirectory(aarDestDir.getPath(), "Unable to delete the aars directory for the extension.");

System.out.println("Extensions : " + "Copying file aar " + library);
copyFile(aarFile.getAbsolutePath(), aarDestDir.getAbsolutePath() + File.separator + library);
}

/**
* Copy a compiled classes related to a given extension in his package folder.
*
Expand Down