diff options
7 files changed, 78 insertions, 31 deletions
diff --git a/anttasks/src/com/android/ant/NewSetupTask.java b/anttasks/src/com/android/ant/NewSetupTask.java index c0e8d2a..45a18c3 100644 --- a/anttasks/src/com/android/ant/NewSetupTask.java +++ b/anttasks/src/com/android/ant/NewSetupTask.java @@ -82,6 +82,7 @@ public class NewSetupTask extends Task { private String mProjectLibrariesPackageOut; private String mProjectLibrariesJarsOut; private String mProjectLibrariesLibsOut; + private String mTargetApiOut; public void setProjectTypeOut(String projectTypeOut) { mProjectTypeOut = projectTypeOut; @@ -127,6 +128,10 @@ public class NewSetupTask extends Task { mProjectLibrariesLibsOut = projectLibrariesLibsOut; } + public void setTargetApiOut(String targetApiOut) { + mTargetApiOut = targetApiOut; + } + @Override public void execute() throws BuildException { if (mProjectTypeOut == null) { @@ -162,6 +167,9 @@ public class NewSetupTask extends Task { if (mProjectLibrariesLibsOut == null) { throw new BuildException("Missing attribute projectLibrariesLibsOut"); } + if (mTargetApiOut == null) { + throw new BuildException("Missing attribute targetApiOut"); + } Project antProject = getProject(); @@ -377,6 +385,12 @@ public class NewSetupTask extends Task { "For '%1$s' SDK Preview, attribute minSdkVersion in AndroidManifest.xml must be '%1$s'", codeName)); } + + // set the API level to the previous API level (which is actually the value in + // androidVersion.) + antProject.setProperty(mTargetApiOut, + Integer.toString(androidVersion.getApiLevel())); + } else if (value.length() > 0) { // for normal platform, we'll only display warnings if the value is lower or higher // than the target api level. @@ -391,6 +405,9 @@ public class NewSetupTask extends Task { AndroidManifest.ATTRIBUTE_MIN_SDK_VERSION)); } + // set the target api to the value + antProject.setProperty(mTargetApiOut, value); + int projectApiLevel = androidVersion.getApiLevel(); if (minSdkValue < projectApiLevel) { System.out.println(String.format( @@ -407,6 +424,9 @@ public class NewSetupTask extends Task { // no minSdkVersion? display a warning System.out.println( "WARNING: No minSdkVersion value set. Application will install on all Android versions."); + + // set the target api to 1 + antProject.setProperty(mTargetApiOut, "1"); } } catch (XPathExpressionException e) { diff --git a/anttasks/src/com/android/ant/RenderScriptTask.java b/anttasks/src/com/android/ant/RenderScriptTask.java index 08eeeed..50284fd 100644 --- a/anttasks/src/com/android/ant/RenderScriptTask.java +++ b/anttasks/src/com/android/ant/RenderScriptTask.java @@ -31,16 +31,17 @@ import java.util.Iterator; import java.util.List; /** - * Task to execute aidl. + * Task to execute renderscript. + * <p> + * It expects 5 attributes:<br> + * 'executable' ({@link Path} with a single path) for the location of the llvm executable<br> + * 'framework' ({@link Path} with 1 or more paths) for the include paths.<br> + * 'genFolder' ({@link Path} with a single path) for the location of the gen folder.<br> + * 'resFolder' ({@link Path} with a single path) for the location of the res folder.<br> + * 'targetApi' for the -target-api value.<br> * <p> - * It expects 3 attributes:<br> - * 'executable' ({@link Path} with a single path) for the location of the aidl executable<br> - * 'framework' ({@link Path} with a single path) for the "preprocessed" file containing all the - * parcelables exported by the framework<br> - * 'genFolder' ({@link Path} with a single path) for the location of the gen folder. - * * It also expects one or more inner elements called "source" which are identical to {@link Path} - * elements. + * elements for where to find .rs files. */ public class RenderScriptTask extends Task { @@ -49,6 +50,7 @@ public class RenderScriptTask extends Task { private String mGenFolder; private String mResFolder; private final List<Path> mPaths = new ArrayList<Path>(); + private String mTargetApi; /** * Sets the value of the "executable" attribute. @@ -70,6 +72,10 @@ public class RenderScriptTask extends Task { mResFolder = TaskHelper.checkSinglePath("resFolder", value); } + public void setTargetApi(String targetApi) { + mTargetApi = targetApi; + } + public Path createSource() { Path p = new Path(getProject()); mPaths.add(p); @@ -90,6 +96,9 @@ public class RenderScriptTask extends Task { if (mResFolder == null) { throw new BuildException("RenderScriptTask's 'resFolder' is required."); } + if (mTargetApi == null) { + throw new BuildException("RenderScriptTask's 'targetApi' is required."); + } Project taskProject = getProject(); @@ -137,6 +146,9 @@ public class RenderScriptTask extends Task { } } + task.createArg().setValue("-target-api"); + task.createArg().setValue(mTargetApi); + task.createArg().setValue("-p"); task.createArg().setValue(mGenFolder); task.createArg().setValue("-o"); @@ -145,11 +157,15 @@ public class RenderScriptTask extends Task { // execute it. task.execute(); + + count++; } } if (count > 0) { - System.out.println(String.format("Compiled %d renderscript files.", count)); + System.out.println(String.format( + "Compiled %d renderscript files (with -target-api set to %s)", + count, mTargetApi)); } else { System.out.println("No renderscript files to compile."); } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/AidlProcessor.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/AidlProcessor.java index 09dd571..f24900f 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/AidlProcessor.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/AidlProcessor.java @@ -91,7 +91,7 @@ public class AidlProcessor extends SourceProcessor { @Override protected void doCompileFiles(List<IFile> sources, BaseBuilder builder, - IProject project, IAndroidTarget projectTarget, + IProject project, IAndroidTarget projectTarget, int minSdkVersion, List<IPath> sourceFolders, List<IFile> notCompiledOut, IProgressMonitor monitor) throws CoreException { // create the command line diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/RenderScriptProcessor.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/RenderScriptProcessor.java index 84fa2d7..e518e23 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/RenderScriptProcessor.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/RenderScriptProcessor.java @@ -133,8 +133,9 @@ public class RenderScriptProcessor extends SourceProcessor { @Override protected void doCompileFiles(List<IFile> sources, BaseBuilder builder, - IProject project, IAndroidTarget projectTarget, List<IPath> sourceFolders, - List<IFile> notCompiledOut, IProgressMonitor monitor) throws CoreException { + IProject project, IAndroidTarget projectTarget, int minSdkVersion, + List<IPath> sourceFolders, List<IFile> notCompiledOut, IProgressMonitor monitor) + throws CoreException { String sdkOsPath = Sdk.getCurrent().getSdkLocation(); @@ -146,7 +147,7 @@ public class RenderScriptProcessor extends SourceProcessor { int depIndex; // create the command line - String[] command = new String[13]; + String[] command = new String[15]; int index = 0; command[index++] = quote(sdkOsPath + SdkConstants.OS_SDK_PLATFORM_TOOLS_FOLDER + SdkConstants.FN_RENDERSCRIPT); @@ -159,6 +160,9 @@ public class RenderScriptProcessor extends SourceProcessor { command[index++] = "-o"; //$NON-NLS-1$ command[index++] = quote(rawFolder.getLocation().toOSString()); + command[index++] = "-target-api"; //$NON-NLS-1$ + command[index++] = Integer.toString(minSdkVersion); + command[index++] = "-d"; //$NON-NLS-1$ command[depIndex = index++] = null; command[index++] = "-MD"; //$NON-NLS-1$ diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/SourceProcessor.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/SourceProcessor.java index 40c7080..8a24cc2 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/SourceProcessor.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/SourceProcessor.java @@ -218,7 +218,7 @@ public abstract class SourceProcessor { * */ public final int compileFiles(BaseBuilder builder, - IProject project, IAndroidTarget projectTarget, + IProject project, IAndroidTarget projectTarget, int minSdkVersion, List<IPath> sourceFolders, IProgressMonitor monitor) throws CoreException { mLastCompilationStatus = COMPILE_STATUS_NONE; @@ -239,7 +239,7 @@ public abstract class SourceProcessor { // list of files that have failed compilation. List<IFile> stillNeedCompilation = new ArrayList<IFile>(); - doCompileFiles(mToCompile, builder, project, projectTarget, sourceFolders, + doCompileFiles(mToCompile, builder, project, projectTarget, minSdkVersion, sourceFolders, stillNeedCompilation, monitor); mToCompile.clear(); @@ -271,7 +271,7 @@ public abstract class SourceProcessor { protected abstract void doCompileFiles( List<IFile> filesToCompile, BaseBuilder builder, - IProject project, IAndroidTarget projectTarget, + IProject project, IAndroidTarget projectTarget, int minSdkVersion, List<IPath> sourceFolders, List<IFile> notCompiledOut, IProgressMonitor monitor) throws CoreException; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/builders/PreCompilerBuilder.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/builders/PreCompilerBuilder.java index 195a279..5a7996e 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/builders/PreCompilerBuilder.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/builders/PreCompilerBuilder.java @@ -360,21 +360,22 @@ public class PreCompilerBuilder extends BaseBuilder { } } + int minSdkValue = -1; + if (minSdkVersion != null) { - int minSdkValue = -1; try { minSdkValue = Integer.parseInt(minSdkVersion); } catch (NumberFormatException e) { // it's ok, it means minSdkVersion contains a (hopefully) valid codename. } - AndroidVersion projectVersion = projectTarget.getVersion(); + AndroidVersion targetVersion = projectTarget.getVersion(); // remove earlier marker from the manifest removeMarkersFromResource(manifestFile, AdtConstants.MARKER_ADT); if (minSdkValue != -1) { - String codename = projectVersion.getCodename(); + String codename = targetVersion.getCodename(); if (codename != null) { // integer minSdk when the target is a preview => fatal error String msg = String.format( @@ -384,21 +385,21 @@ public class PreCompilerBuilder extends BaseBuilder { BaseProjectHelper.markResource(manifestFile, AdtConstants.MARKER_ADT, msg, IMarker.SEVERITY_ERROR); return result; - } else if (minSdkValue < projectVersion.getApiLevel()) { + } else if (minSdkValue < targetVersion.getApiLevel()) { // integer minSdk is not high enough for the target => warning String msg = String.format( "Attribute %1$s (%2$d) is lower than the project target API level (%3$d)", AndroidManifest.ATTRIBUTE_MIN_SDK_VERSION, - minSdkValue, projectVersion.getApiLevel()); + minSdkValue, targetVersion.getApiLevel()); AdtPlugin.printBuildToConsole(BuildVerbosity.VERBOSE, project, msg); BaseProjectHelper.markResource(manifestFile, AdtConstants.MARKER_ADT, msg, IMarker.SEVERITY_WARNING); - } else if (minSdkValue > projectVersion.getApiLevel()) { + } else if (minSdkValue > targetVersion.getApiLevel()) { // integer minSdk is too high for the target => warning String msg = String.format( "Attribute %1$s (%2$d) is higher than the project target API level (%3$d)", AndroidManifest.ATTRIBUTE_MIN_SDK_VERSION, - minSdkValue, projectVersion.getApiLevel()); + minSdkValue, targetVersion.getApiLevel()); AdtPlugin.printBuildToConsole(BuildVerbosity.VERBOSE, project, msg); BaseProjectHelper.markResource(manifestFile, AdtConstants.MARKER_ADT, msg, IMarker.SEVERITY_WARNING); @@ -406,7 +407,7 @@ public class PreCompilerBuilder extends BaseBuilder { } else { // looks like the min sdk is a codename, check it matches the codename // of the platform - String codename = projectVersion.getCodename(); + String codename = targetVersion.getCodename(); if (codename == null) { // platform is not a preview => fatal error String msg = String.format( @@ -426,6 +427,11 @@ public class PreCompilerBuilder extends BaseBuilder { msg, IMarker.SEVERITY_ERROR); return result; } + + // if we get there, the minSdkVersion is a codename matching the target + // platform codename. In this case we set minSdkValue to the previous API + // level, as it's used by source processors. + minSdkValue = targetVersion.getApiLevel(); } } else if (projectTarget.getVersion().isPreview()) { // else the minSdkVersion is not set but we are using a preview target. @@ -494,7 +500,7 @@ public class PreCompilerBuilder extends BaseBuilder { for (SourceProcessor processor : mProcessors) { try { processorStatus |= processor.compileFiles(this, - project, projectTarget, sourceFolderPathList, monitor); + project, projectTarget, minSdkValue, sourceFolderPathList, monitor); } catch (Throwable t) { AdtPlugin.log(t, "Failed to run one of the source processor"); } diff --git a/files/ant/build.xml b/files/ant/build.xml index 609fcb3..821c49b 100644 --- a/files/ant/build.xml +++ b/files/ant/build.xml @@ -176,11 +176,6 @@ <!-- properties for packaging --> <property name="build.packaging.nocrunch" value="true" /> - <!-- Name of the application package extracted from manifest file --> - <xpath input="AndroidManifest.xml" expression="/manifest/@package" - output="manifest.package" /> - - <!-- ********** Macros ********** --> <!-- macro to do a task on if project.is.library is false. @@ -417,6 +412,7 @@ projectLibrariesResOut="project.libraries.res" projectLibrariesPackageOut="project.libraries.package" projectLibrariesLibsOut="project.libraries.libs" + targetApiOut="target.api" /> <!-- sets a few boolean based on android.project.type @@ -547,7 +543,8 @@ <renderscript executable="${renderscript}" framework="${android.rs}" genFolder="${gen.absolute.dir}" - resFolder="${resource.absolute.dir}/raw"> + resFolder="${resource.absolute.dir}/raw" + targetApi="${target.api}"> <source path="${source.absolute.dir}"/> </renderscript> @@ -1159,6 +1156,10 @@ <!-- Uninstalls the package from the default emulator/device --> <target name="uninstall" description="Uninstalls the application from a running emulator or device."> + <!-- Name of the application package extracted from manifest file --> + <xpath input="AndroidManifest.xml" expression="/manifest/@package" + output="manifest.package" /> + <if> <condition> <isset property="manifest.package" /> |