Make the Ant script sign and zipalign release builds.
It will also align debug builds. BUG: 2052744
This commit is contained in:
@@ -28,6 +28,7 @@ import org.apache.tools.ant.Project;
|
||||
import org.apache.tools.ant.ProjectComponent;
|
||||
import org.apache.tools.ant.Task;
|
||||
import org.apache.tools.ant.types.Path;
|
||||
import org.apache.tools.ant.types.Path.PathElement;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@@ -39,6 +40,9 @@ import java.util.Map.Entry;
|
||||
|
||||
public class ApkBuilderTask extends Task {
|
||||
|
||||
// ref id to the <path> object containing all the boot classpaths.
|
||||
private final static String REF_APK_PATH = "android.apks.path";
|
||||
|
||||
/**
|
||||
* Class to represent nested elements. Since they all have only one attribute ('path'), the
|
||||
* same class can be used for all the nested elements (zip, file, sourcefolder, jarfolder,
|
||||
@@ -152,7 +156,7 @@ public class ApkBuilderTask extends Task {
|
||||
|
||||
@Override
|
||||
public void execute() throws BuildException {
|
||||
Project taskProject = getProject();
|
||||
Project antProject = getProject();
|
||||
|
||||
ApkBuilderImpl apkBuilder = new ApkBuilderImpl();
|
||||
apkBuilder.setVerbose(mVerbose);
|
||||
@@ -197,13 +201,16 @@ public class ApkBuilderTask extends Task {
|
||||
ApkBuilderImpl.processNativeFolder(offset, f, mNativeLibraries);
|
||||
}
|
||||
|
||||
// create the Path item that will contain all the generated APKs
|
||||
// for reuse by other targets (signing/zipaligning)
|
||||
Path path = new Path(antProject);
|
||||
|
||||
// first do a full resource package
|
||||
createApk(apkBuilder, null /*configName*/, null /*resourceFilter*/);
|
||||
createApk(apkBuilder, null /*configName*/, null /*resourceFilter*/, path);
|
||||
|
||||
// now see if we need to create file with filtered resources.
|
||||
// Get the project base directory.
|
||||
File baseDir = taskProject.getBaseDir();
|
||||
File baseDir = antProject.getBaseDir();
|
||||
ProjectProperties properties = ProjectProperties.load(baseDir.getAbsolutePath(),
|
||||
PropertyType.DEFAULT);
|
||||
|
||||
@@ -211,9 +218,13 @@ public class ApkBuilderTask extends Task {
|
||||
if (apkConfigs.size() > 0) {
|
||||
Set<Entry<String, String>> entrySet = apkConfigs.entrySet();
|
||||
for (Entry<String, String> entry : entrySet) {
|
||||
createApk(apkBuilder, entry.getKey(), entry.getValue());
|
||||
createApk(apkBuilder, entry.getKey(), entry.getValue(), path);
|
||||
}
|
||||
}
|
||||
|
||||
// finally sets the path in the project with a reference
|
||||
antProject.addReference(REF_APK_PATH, path);
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new BuildException(e);
|
||||
} catch (IllegalArgumentException e) {
|
||||
@@ -230,10 +241,12 @@ public class ApkBuilderTask extends Task {
|
||||
* package will be generated.
|
||||
* @param resourceFilter the resource configuration filter to pass to aapt (if configName is
|
||||
* non null)
|
||||
* @param path Ant {@link Path} to which add the generated APKs as {@link PathElement}
|
||||
* @throws FileNotFoundException
|
||||
* @throws ApkCreationException
|
||||
*/
|
||||
private void createApk(ApkBuilderImpl apkBuilder, String configName, String resourceFilter)
|
||||
private void createApk(ApkBuilderImpl apkBuilder, String configName, String resourceFilter,
|
||||
Path path)
|
||||
throws FileNotFoundException, ApkCreationException {
|
||||
// All the files to be included in the archive have already been prep'ed up, except
|
||||
// the resource package.
|
||||
@@ -259,7 +272,7 @@ public class ApkBuilderTask extends Task {
|
||||
}
|
||||
|
||||
if (mSigned) {
|
||||
filename = filename + "-debug.apk";
|
||||
filename = filename + "-debug-unaligned.apk";
|
||||
} else {
|
||||
filename = filename + "-unsigned.apk";
|
||||
}
|
||||
@@ -284,8 +297,13 @@ public class ApkBuilderTask extends Task {
|
||||
}
|
||||
}
|
||||
|
||||
// out File
|
||||
File f = new File(mOutFolder, filename);
|
||||
|
||||
// add it to the Path object
|
||||
PathElement element = path.createPathElement();
|
||||
element.setLocation(f);
|
||||
|
||||
// and generate the apk
|
||||
apkBuilder.createPackage(f.getAbsoluteFile(), mZipArchives,
|
||||
mArchiveFiles, mJavaResources, mResourcesJars, mNativeLibraries);
|
||||
|
||||
Reference in New Issue
Block a user