aboutsummaryrefslogtreecommitdiffstats
path: root/anttasks/src/com/android/ant
diff options
context:
space:
mode:
Diffstat (limited to 'anttasks/src/com/android/ant')
-rw-r--r--anttasks/src/com/android/ant/AaptExecTask.java82
-rw-r--r--anttasks/src/com/android/ant/ComputeDependencyTask.java24
-rw-r--r--anttasks/src/com/android/ant/DependencyGraph.java2
3 files changed, 95 insertions, 13 deletions
diff --git a/anttasks/src/com/android/ant/AaptExecTask.java b/anttasks/src/com/android/ant/AaptExecTask.java
index c96f7d0..5fd57b8 100644
--- a/anttasks/src/com/android/ant/AaptExecTask.java
+++ b/anttasks/src/com/android/ant/AaptExecTask.java
@@ -16,12 +16,16 @@
package com.android.ant;
+import com.android.sdklib.internal.build.SymbolLoader;
+import com.android.sdklib.internal.build.SymbolWriter;
+
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.ExecTask;
import org.apache.tools.ant.types.Path;
import java.io.File;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -95,8 +99,10 @@ public final class AaptExecTask extends SingleDependencyTask {
private final ArrayList<NoCompress> mNoCompressList = new ArrayList<NoCompress>();
private String mLibraryResFolderPathRefid;
private String mLibraryPackagesRefid;
+ private String mLibraryRFileRefid;
private boolean mNonConstantId;
private String mIgnoreAssets;
+ private String mBinFolder;
private String mProguardFile;
/**
@@ -322,6 +328,14 @@ public final class AaptExecTask extends SingleDependencyTask {
mLibraryPackagesRefid = libraryPackagesRefid;
}
+ public void setLibraryRFileRefid(String libraryRFileRefid) {
+ mLibraryRFileRefid = libraryRFileRefid;
+ }
+
+ public void setBinFolder(Path binFolder) {
+ mBinFolder = TaskHelper.checkSinglePath("binFolder", binFolder);
+ }
+
public void setProguardFile(Path proguardFile) {
mProguardFile = TaskHelper.checkSinglePath("proguardFile", proguardFile);
}
@@ -370,19 +384,34 @@ public final class AaptExecTask extends SingleDependencyTask {
if (mLibraryPackagesRefid == null) {
throw new BuildException("Missing attribute libraryPackagesRefid");
}
+ if (mLibraryRFileRefid == null) {
+ throw new BuildException("Missing attribute libraryRFileRefid");
+ }
Project taskProject = getProject();
String libPkgProp = null;
+ Path libRFileProp = null;
// if the parameters indicate generation of the R class, check if
// more R classes need to be created for libraries, only if this project itself
// is not a library
if (mNonConstantId == false && mRFolder != null && new File(mRFolder).isDirectory()) {
libPkgProp = taskProject.getProperty(mLibraryPackagesRefid);
- if (libPkgProp != null) {
- // Replace ";" with ":" since that's what aapt expects
- libPkgProp = libPkgProp.replace(';', ':');
+ Object rFilePath = taskProject.getReference(mLibraryRFileRefid);
+
+ // if one is null, both should be
+ if ((libPkgProp == null || rFilePath == null) &&
+ rFilePath != libPkgProp) {
+ throw new BuildException(String.format(
+ "Both %1$s and %2$s should resolve to valid values.",
+ mLibraryPackagesRefid, mLibraryRFileRefid));
+ }
+
+ if (rFilePath instanceof Path) {
+ libRFileProp = (Path) rFilePath;
+ } else if (rFilePath != null) {
+ throw new BuildException("attribute libraryRFileRefid must reference a Path object.");
}
}
@@ -530,9 +559,14 @@ public final class AaptExecTask extends SingleDependencyTask {
}
}
- if (mNonConstantId == false && libPkgProp != null && libPkgProp.length() > 0) {
- task.createArg().setValue("--extra-packages");
- task.createArg().setValue(libPkgProp);
+ // if this is a library or there are library dependencies
+ if (mNonConstantId || (libPkgProp != null && libPkgProp.length() > 0)) {
+ if (mBinFolder == null) {
+ throw new BuildException(
+ "Missing attribute binFolder when compiling libraries or projects with libraries.");
+ }
+ task.createArg().setValue("--output-text-symbols");
+ task.createArg().setValue(mBinFolder);
}
// if the project contains libraries, force auto-add-overlay
@@ -639,5 +673,41 @@ public final class AaptExecTask extends SingleDependencyTask {
// execute it.
task.execute();
+
+ // now if the project has libraries, R needs to be created for each libraries
+ try {
+ if (libPkgProp != null && !libPkgProp.isEmpty()) {
+ SymbolLoader symbolValues = new SymbolLoader(new File(mBinFolder, "R.txt"));
+ symbolValues.load();
+
+ // we have two props which contains list of items. Both items reprensent 2 data of
+ // a single property.
+ // Don't want to use guava's splitter because it doesn't provide a list of the
+ // result. but we know the list starts with a ; so strip it.
+ if (libPkgProp.startsWith(";")) {
+ libPkgProp = libPkgProp.substring(1).trim();
+ }
+ String[] packages = libPkgProp.split(";");
+ String[] rFiles = libRFileProp.list();
+
+ if (packages.length != rFiles.length) {
+ throw new BuildException(String.format(
+ "%1$s and %2$s must contain the same number of items.",
+ mLibraryPackagesRefid, mLibraryRFileRefid));
+ }
+
+ for (int i = 0 ; i < packages.length ; i++) {
+ SymbolLoader symbols = new SymbolLoader(new File(rFiles[i]));
+ symbols.load();
+
+ SymbolWriter writer = new SymbolWriter(mRFolder, packages[i],
+ symbols, symbolValues);
+ writer.write();
+ }
+ }
+ } catch (IOException e) {
+ throw new BuildException(e);
+ }
+
}
}
diff --git a/anttasks/src/com/android/ant/ComputeDependencyTask.java b/anttasks/src/com/android/ant/ComputeDependencyTask.java
index 878c49f..7d96c70 100644
--- a/anttasks/src/com/android/ant/ComputeDependencyTask.java
+++ b/anttasks/src/com/android/ant/ComputeDependencyTask.java
@@ -59,6 +59,7 @@ public class ComputeDependencyTask extends GetLibraryPathTask {
private String mJarLibraryPathOut;
private String mLibraryNativeFolderPathOut;
private String mLibraryBinAidlFolderPathOut;
+ private String mLibraryRFilePathOut;
private int mTargetApi = -1;
private boolean mVerbose = false;
@@ -82,6 +83,10 @@ public class ComputeDependencyTask extends GetLibraryPathTask {
mLibraryBinAidlFolderPathOut = libraryBinAidlFolderPathOut;
}
+ public void setLibraryRFilePathOut(String libraryRFilePathOut) {
+ mLibraryRFilePathOut = libraryRFilePathOut;
+ }
+
public void setLibraryNativeFolderPathOut(String libraryNativeFolderPathOut) {
mLibraryNativeFolderPathOut = libraryNativeFolderPathOut;
}
@@ -110,6 +115,9 @@ public class ComputeDependencyTask extends GetLibraryPathTask {
if (mLibraryBinAidlFolderPathOut == null) {
throw new BuildException("Missing attribute libraryBinFolderPathOut");
}
+ if (mLibraryRFilePathOut == null) {
+ throw new BuildException("Missing attribute libraryRFilePathOut");
+ }
if (mTargetApi == -1) {
throw new BuildException("Missing attribute targetApi");
}
@@ -124,6 +132,7 @@ public class ComputeDependencyTask extends GetLibraryPathTask {
final Path resFolderPath = new Path(antProject);
final Path nativeFolderPath = new Path(antProject);
final Path binAidlFolderPath = new Path(antProject);
+ final Path rFilePath = new Path(antProject);
final StringBuilder packageStrBuilder = new StringBuilder();
// custom jar processor doing a bit more than just collecting the jar files
@@ -157,12 +166,6 @@ public class ComputeDependencyTask extends GetLibraryPathTask {
element.setPath(libRootPath + '/' + SdkConstants.FD_OUTPUT +
'/' + SdkConstants.FD_AIDL);
- // get the bin folder. $PROJECT/bin for now
- // FIXME: support renamed folder.
- element = binAidlFolderPath.createPathElement();
- element.setPath(libRootPath + "/" + SdkConstants.FD_OUTPUT +
- "/" + SdkConstants.FD_AIDL);
-
// get the package from the manifest.
FileWrapper manifest = new FileWrapper(libRootPath,
SdkConstants.FN_ANDROID_MANIFEST_XML);
@@ -172,6 +175,14 @@ public class ComputeDependencyTask extends GetLibraryPathTask {
if (value != null) { // aapt will complain if it's missing.
packageStrBuilder.append(';');
packageStrBuilder.append(value);
+
+ // get the text R file. $PROJECT/bin/R.txt for now
+ // This must be in sync with the package list.
+ // FIXME: support renamed folder.
+ element = rFilePath.createPathElement();
+ element.setPath(libRootPath + "/" + SdkConstants.FD_OUTPUT +
+ "/" + "R.txt");
+
}
} catch (Exception e) {
throw new BuildException(e);
@@ -225,6 +236,7 @@ public class ComputeDependencyTask extends GetLibraryPathTask {
if (hasLibraries) {
antProject.addReference(mLibraryResFolderPathOut, resFolderPath);
antProject.setProperty(mLibraryPackagesOut, packageStrBuilder.toString());
+ antProject.addReference(mLibraryRFilePathOut, rFilePath);
}
File projectFolder = antProject.getBaseDir();
diff --git a/anttasks/src/com/android/ant/DependencyGraph.java b/anttasks/src/com/android/ant/DependencyGraph.java
index f8564da..7cb13a0 100644
--- a/anttasks/src/com/android/ant/DependencyGraph.java
+++ b/anttasks/src/com/android/ant/DependencyGraph.java
@@ -426,7 +426,7 @@ public class DependencyGraph {
/**
* Reads and returns the content of a text file.
- * @param file the file path to the text file
+ * @param file the file to read
* @return null if the file could not be read
*/
private static List<String> readFile(File file) {