diff options
author | Xavier Ducrohet <xav@android.com> | 2009-08-24 11:07:51 -0700 |
---|---|---|
committer | Xavier Ducrohet <xav@android.com> | 2009-08-25 17:17:15 -0700 |
commit | b26676823f17f2c1ee177ba832857cfec246c2a8 (patch) | |
tree | eca254a3590c025659479cf32456201db3103a3b /anttasks/src | |
parent | f31831e6af48a7508d1b5f7e2169ef80237404f0 (diff) | |
download | sdk-b26676823f17f2c1ee177ba832857cfec246c2a8.zip sdk-b26676823f17f2c1ee177ba832857cfec246c2a8.tar.gz sdk-b26676823f17f2c1ee177ba832857cfec246c2a8.tar.bz2 |
Move from arbitrary resource filters to fix ones
Resource filters are used when generating additional APK containing only
specific resources.
The previous UI allowed for any type of filters, but we are moving to a
simpler way with fixed filters.
The first one is the density. Selecting the filter will generate 4 APKs per
application: default (all resources), hdpi (only hdpi/nodpi and default
resources), mdpi, ldpi.
Diffstat (limited to 'anttasks/src')
-rw-r--r-- | anttasks/src/com/android/ant/AaptExecLoopTask.java | 61 | ||||
-rw-r--r-- | anttasks/src/com/android/ant/ApkBuilderTask.java | 14 |
2 files changed, 40 insertions, 35 deletions
diff --git a/anttasks/src/com/android/ant/AaptExecLoopTask.java b/anttasks/src/com/android/ant/AaptExecLoopTask.java index ef74fe7..47b8f48 100644 --- a/anttasks/src/com/android/ant/AaptExecLoopTask.java +++ b/anttasks/src/com/android/ant/AaptExecLoopTask.java @@ -17,6 +17,7 @@ package com.android.ant; import com.android.sdklib.internal.project.ApkConfigurationHelper; +import com.android.sdklib.internal.project.ApkSettings; import com.android.sdklib.internal.project.ProjectProperties; import com.android.sdklib.internal.project.ProjectProperties.PropertyType; @@ -28,7 +29,6 @@ import org.apache.tools.ant.types.Path; import java.io.File; import java.util.Map; -import java.util.Set; import java.util.Map.Entry; /** @@ -38,7 +38,7 @@ import java.util.Map.Entry; * */ public final class AaptExecLoopTask extends Task { - + private String mExecutable; private String mCommand; private String mManifest; @@ -55,7 +55,7 @@ public final class AaptExecLoopTask extends Task { public void setExecutable(String executable) { mExecutable = executable; } - + /** * Sets the value of the "command" attribute. * @param command the value. @@ -63,7 +63,7 @@ public final class AaptExecLoopTask extends Task { public void setCommand(String command) { mCommand = command; } - + /** * Sets the value of the "manifest" attribute. * @param manifest the value. @@ -71,7 +71,7 @@ public final class AaptExecLoopTask extends Task { public void setManifest(Path manifest) { mManifest = manifest.toString(); } - + /** * Sets the value of the "resources" attribute. * @param resources the value. @@ -79,7 +79,7 @@ public final class AaptExecLoopTask extends Task { public void setResources(Path resources) { mResources = resources.toString(); } - + /** * Sets the value of the "assets" attribute. * @param assets the value. @@ -87,7 +87,7 @@ public final class AaptExecLoopTask extends Task { public void setAssets(Path assets) { mAssets = assets.toString(); } - + /** * Sets the value of the "androidjar" attribute. * @param androidJar the value. @@ -95,7 +95,7 @@ public final class AaptExecLoopTask extends Task { public void setAndroidjar(Path androidJar) { mAndroidJar = androidJar.toString(); } - + /** * Sets the value of the "outfolder" attribute. * @param outFolder the value. @@ -103,7 +103,7 @@ public final class AaptExecLoopTask extends Task { public void setOutfolder(Path outFolder) { mOutFolder = outFolder.toString(); } - + /** * Sets the value of the "basename" attribute. * @param baseName the value. @@ -111,19 +111,19 @@ public final class AaptExecLoopTask extends Task { public void setBasename(String baseName) { mBaseName = baseName; } - + /* * (non-Javadoc) - * + * * Executes the loop. Based on the values inside default.properties, this will * create alternate temporary ap_ files. - * + * * @see org.apache.tools.ant.Task#execute() */ @Override public void execute() throws BuildException { Project taskProject = getProject(); - + // first do a full resource package createPackage(null /*configName*/, null /*resourceFilter*/); @@ -132,12 +132,15 @@ public final class AaptExecLoopTask extends Task { File baseDir = taskProject.getBaseDir(); ProjectProperties properties = ProjectProperties.load(baseDir.getAbsolutePath(), PropertyType.DEFAULT); - - Map<String, String> apkConfigs = ApkConfigurationHelper.getConfigs(properties); - if (apkConfigs.size() > 0) { - Set<Entry<String, String>> entrySet = apkConfigs.entrySet(); - for (Entry<String, String> entry : entrySet) { - createPackage(entry.getKey(), entry.getValue()); + + + ApkSettings apkSettings = ApkConfigurationHelper.getSettings(properties); + if (apkSettings != null) { + Map<String, String> apkFilters = apkSettings.getResourceFilters(); + if (apkFilters.size() > 0) { + for (Entry<String, String> entry : apkFilters.entrySet()) { + createPackage(entry.getKey(), entry.getValue()); + } } } } @@ -164,19 +167,19 @@ public final class AaptExecLoopTask extends Task { ExecTask task = new ExecTask(); task.setExecutable(mExecutable); task.setFailonerror(true); - + // aapt command. Only "package" is supported at this time really. task.createArg().setValue(mCommand); - + // filters if needed if (configName != null && resourceFilter != null) { task.createArg().setValue("-c"); task.createArg().setValue(resourceFilter); } - + // force flag task.createArg().setValue("-f"); - + // manifest location task.createArg().setValue("-M"); task.createArg().setValue(mManifest); @@ -187,18 +190,18 @@ public final class AaptExecLoopTask extends Task { task.createArg().setValue("-S"); task.createArg().setValue(mResources); } - + // assets location. This may not exists, and aapt doesn't like it, so we check first. File assets = new File(mAssets); if (assets.isDirectory()) { task.createArg().setValue("-A"); task.createArg().setValue(mAssets); } - + // android.jar task.createArg().setValue("-I"); task.createArg().setValue(mAndroidJar); - + // out file. This is based on the outFolder, baseName, and the configName (if applicable) String filename; if (configName != null && resourceFilter != null) { @@ -206,15 +209,15 @@ public final class AaptExecLoopTask extends Task { } else { filename = mBaseName + ".ap_"; } - + File file = new File(mOutFolder, filename); task.createArg().setValue("-F"); task.createArg().setValue(file.getAbsolutePath()); - + // final setup of the task task.setProject(taskProject); task.setOwningTarget(getOwningTarget()); - + // execute it. task.execute(); } diff --git a/anttasks/src/com/android/ant/ApkBuilderTask.java b/anttasks/src/com/android/ant/ApkBuilderTask.java index 3a15368..b2c445d 100644 --- a/anttasks/src/com/android/ant/ApkBuilderTask.java +++ b/anttasks/src/com/android/ant/ApkBuilderTask.java @@ -20,6 +20,7 @@ import com.android.apkbuilder.ApkBuilder.ApkCreationException; import com.android.apkbuilder.internal.ApkBuilderImpl; import com.android.apkbuilder.internal.ApkBuilderImpl.ApkFile; import com.android.sdklib.internal.project.ApkConfigurationHelper; +import com.android.sdklib.internal.project.ApkSettings; import com.android.sdklib.internal.project.ProjectProperties; import com.android.sdklib.internal.project.ProjectProperties.PropertyType; @@ -35,7 +36,6 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Map; -import java.util.Set; import java.util.Map.Entry; public class ApkBuilderTask extends Task { @@ -214,11 +214,13 @@ public class ApkBuilderTask extends Task { ProjectProperties properties = ProjectProperties.load(baseDir.getAbsolutePath(), PropertyType.DEFAULT); - Map<String, String> apkConfigs = ApkConfigurationHelper.getConfigs(properties); - if (apkConfigs.size() > 0) { - Set<Entry<String, String>> entrySet = apkConfigs.entrySet(); - for (Entry<String, String> entry : entrySet) { - createApk(apkBuilder, entry.getKey(), entry.getValue(), path); + ApkSettings apkSettings = ApkConfigurationHelper.getSettings(properties); + if (apkSettings != null) { + Map<String, String> apkFilters = apkSettings.getResourceFilters(); + if (apkFilters.size() > 0) { + for (Entry<String, String> entry : apkFilters.entrySet()) { + createApk(apkBuilder, entry.getKey(), entry.getValue(), path); + } } } |