diff --git a/appinventor/buildserver/src/com/google/appinventor/buildserver/tasks/android/AttachAarLibs.java b/appinventor/buildserver/src/com/google/appinventor/buildserver/tasks/android/AttachAarLibs.java index 1a325769f98..9ea6e66a7fc 100644 --- a/appinventor/buildserver/src/com/google/appinventor/buildserver/tasks/android/AttachAarLibs.java +++ b/appinventor/buildserver/src/com/google/appinventor/buildserver/tasks/android/AttachAarLibs.java @@ -44,16 +44,27 @@ public TaskResult execute(AndroidCompilerContext context) { // walk components list for libraries ending in ".aar" try { - for (Set libs : context.getComponentInfo().getLibsNeeded().values()) { - Iterator i = libs.iterator(); + for (String type : context.getComponentInfo().getLibsNeeded().keySet()) { + Iterator 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// - 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); diff --git a/appinventor/components/src/com/google/appinventor/components/scripts/ExternalComponentGenerator.java b/appinventor/components/src/com/google/appinventor/components/scripts/ExternalComponentGenerator.java index 1d8d7e72ca4..438421b19a5 100644 --- a/appinventor/components/src/com/google/appinventor/components/scripts/ExternalComponentGenerator.java +++ b/appinventor/components/src/com/google/appinventor/components/scripts/ExternalComponentGenerator.java @@ -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", @@ -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. *