Make sure that any exception during the final packaging properly put an error marker on the project (since build failed.
This commit is contained in:
@@ -204,364 +204,390 @@ public class ApkBuilder extends BaseBuilder {
|
|||||||
// get a project object
|
// get a project object
|
||||||
IProject project = getProject();
|
IProject project = getProject();
|
||||||
|
|
||||||
// Top level check to make sure the build can move forward.
|
// list of referenced projects.
|
||||||
abortOnBadSetup(project);
|
IProject[] referencedProjects = null;
|
||||||
|
|
||||||
// get the list of referenced projects.
|
try {
|
||||||
IProject[] referencedProjects = ProjectHelper.getReferencedProjects(project);
|
// Top level check to make sure the build can move forward.
|
||||||
IJavaProject[] referencedJavaProjects = getJavaProjects(referencedProjects);
|
abortOnBadSetup(project);
|
||||||
|
|
||||||
// get the output folder, this method returns the path with a trailing
|
// get the list of referenced projects.
|
||||||
// separator
|
referencedProjects = ProjectHelper.getReferencedProjects(project);
|
||||||
IJavaProject javaProject = JavaCore.create(project);
|
IJavaProject[] referencedJavaProjects = getJavaProjects(referencedProjects);
|
||||||
IFolder outputFolder = BaseProjectHelper.getOutputFolder(project);
|
|
||||||
|
// get the output folder, this method returns the path with a trailing
|
||||||
// now we need to get the classpath list
|
// separator
|
||||||
ArrayList<IPath> sourceList = BaseProjectHelper.getSourceClasspaths(javaProject);
|
IJavaProject javaProject = JavaCore.create(project);
|
||||||
|
IFolder outputFolder = BaseProjectHelper.getOutputFolder(project);
|
||||||
// First thing we do is go through the resource delta to not
|
|
||||||
// lose it if we have to abort the build for any reason.
|
// now we need to get the classpath list
|
||||||
ApkDeltaVisitor dv = null;
|
ArrayList<IPath> sourceList = BaseProjectHelper.getSourceClasspaths(javaProject);
|
||||||
if (kind == FULL_BUILD) {
|
|
||||||
AdtPlugin.printBuildToConsole(AdtConstants.BUILD_VERBOSE, project,
|
// First thing we do is go through the resource delta to not
|
||||||
Messages.Start_Full_Apk_Build);
|
// lose it if we have to abort the build for any reason.
|
||||||
|
ApkDeltaVisitor dv = null;
|
||||||
mPackageResources = true;
|
if (kind == FULL_BUILD) {
|
||||||
mConvertToDex = true;
|
AdtPlugin.printBuildToConsole(AdtConstants.BUILD_VERBOSE, project,
|
||||||
mBuildFinalPackage = true;
|
Messages.Start_Full_Apk_Build);
|
||||||
} else {
|
|
||||||
AdtPlugin.printBuildToConsole(AdtConstants.BUILD_VERBOSE, project,
|
|
||||||
Messages.Start_Inc_Apk_Build);
|
|
||||||
|
|
||||||
// go through the resources and see if something changed.
|
|
||||||
IResourceDelta delta = getDelta(project);
|
|
||||||
if (delta == null) {
|
|
||||||
mPackageResources = true;
|
mPackageResources = true;
|
||||||
mConvertToDex = true;
|
mConvertToDex = true;
|
||||||
mBuildFinalPackage = true;
|
mBuildFinalPackage = true;
|
||||||
} else {
|
} else {
|
||||||
dv = new ApkDeltaVisitor(this, sourceList, outputFolder);
|
AdtPlugin.printBuildToConsole(AdtConstants.BUILD_VERBOSE, project,
|
||||||
delta.accept(dv);
|
Messages.Start_Inc_Apk_Build);
|
||||||
|
|
||||||
// save the state
|
// go through the resources and see if something changed.
|
||||||
mPackageResources |= dv.getPackageResources();
|
IResourceDelta delta = getDelta(project);
|
||||||
mConvertToDex |= dv.getConvertToDex();
|
if (delta == null) {
|
||||||
mBuildFinalPackage |= dv.getMakeFinalPackage();
|
mPackageResources = true;
|
||||||
}
|
mConvertToDex = true;
|
||||||
|
mBuildFinalPackage = true;
|
||||||
// also go through the delta for all the referenced projects, until we are forced to
|
} else {
|
||||||
// compile anyway
|
dv = new ApkDeltaVisitor(this, sourceList, outputFolder);
|
||||||
for (int i = 0 ; i < referencedJavaProjects.length &&
|
delta.accept(dv);
|
||||||
(mBuildFinalPackage == false || mConvertToDex == false); i++) {
|
|
||||||
IJavaProject referencedJavaProject = referencedJavaProjects[i];
|
|
||||||
delta = getDelta(referencedJavaProject.getProject());
|
|
||||||
if (delta != null) {
|
|
||||||
ReferencedProjectDeltaVisitor refProjectDv = new ReferencedProjectDeltaVisitor(
|
|
||||||
referencedJavaProject);
|
|
||||||
delta.accept(refProjectDv);
|
|
||||||
|
|
||||||
// save the state
|
// save the state
|
||||||
mConvertToDex |= refProjectDv.needDexConvertion();
|
mPackageResources |= dv.getPackageResources();
|
||||||
mBuildFinalPackage |= refProjectDv.needMakeFinalPackage();
|
mConvertToDex |= dv.getConvertToDex();
|
||||||
|
mBuildFinalPackage |= dv.getMakeFinalPackage();
|
||||||
|
}
|
||||||
|
|
||||||
|
// also go through the delta for all the referenced projects, until we are forced to
|
||||||
|
// compile anyway
|
||||||
|
for (int i = 0 ; i < referencedJavaProjects.length &&
|
||||||
|
(mBuildFinalPackage == false || mConvertToDex == false); i++) {
|
||||||
|
IJavaProject referencedJavaProject = referencedJavaProjects[i];
|
||||||
|
delta = getDelta(referencedJavaProject.getProject());
|
||||||
|
if (delta != null) {
|
||||||
|
ReferencedProjectDeltaVisitor refProjectDv = new ReferencedProjectDeltaVisitor(
|
||||||
|
referencedJavaProject);
|
||||||
|
delta.accept(refProjectDv);
|
||||||
|
|
||||||
|
// save the state
|
||||||
|
mConvertToDex |= refProjectDv.needDexConvertion();
|
||||||
|
mBuildFinalPackage |= refProjectDv.needMakeFinalPackage();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
// store the build status in the persistent storage
|
||||||
|
saveProjectBooleanProperty(PROPERTY_CONVERT_TO_DEX , mConvertToDex);
|
||||||
|
saveProjectBooleanProperty(PROPERTY_PACKAGE_RESOURCES, mPackageResources);
|
||||||
|
saveProjectBooleanProperty(PROPERTY_BUILD_APK, mBuildFinalPackage);
|
||||||
|
|
||||||
|
if (dv != null && dv.mXmlError) {
|
||||||
|
AdtPlugin.printBuildToConsole(AdtConstants.BUILD_VERBOSE, project,
|
||||||
|
Messages.Xml_Error);
|
||||||
|
|
||||||
|
// if there was some XML errors, we just return w/o doing
|
||||||
|
// anything since we've put some markers in the files anyway
|
||||||
|
return referencedProjects;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (outputFolder == null) {
|
||||||
|
// mark project and exit
|
||||||
|
markProject(AdtConstants.MARKER_ADT, Messages.Failed_To_Get_Output,
|
||||||
|
IMarker.SEVERITY_ERROR);
|
||||||
|
return referencedProjects;
|
||||||
|
}
|
||||||
|
|
||||||
|
// first thing we do is check that the SDK directory has been setup.
|
||||||
|
String osSdkFolder = AdtPlugin.getOsSdkFolder();
|
||||||
|
|
||||||
|
if (osSdkFolder.length() == 0) {
|
||||||
|
// this has already been checked in the precompiler. Therefore,
|
||||||
|
// while we do have to cancel the build, we don't have to return
|
||||||
|
// any error or throw anything.
|
||||||
|
return referencedProjects;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the extra configs for the project.
|
||||||
|
// The map contains (name, filter) where 'name' is a name to be used in the apk filename,
|
||||||
|
// and filter is the resource filter to be used in the aapt -c parameters to restrict
|
||||||
|
// which resource configurations to package in the apk.
|
||||||
|
Map<String, String> configs = Sdk.getCurrent().getProjectApkConfigs(project);
|
||||||
|
|
||||||
|
// do some extra check, in case the output files are not present. This
|
||||||
|
// will force to recreate them.
|
||||||
|
IResource tmp = null;
|
||||||
|
|
||||||
|
if (mPackageResources == false) {
|
||||||
|
// check the full resource package
|
||||||
|
tmp = outputFolder.findMember(AndroidConstants.FN_RESOURCES_AP_);
|
||||||
|
if (tmp == null || tmp.exists() == false) {
|
||||||
|
mPackageResources = true;
|
||||||
|
mBuildFinalPackage = true;
|
||||||
|
} else {
|
||||||
|
// if the full package is present, we check the filtered resource packages as well
|
||||||
|
if (configs != null) {
|
||||||
|
Set<Entry<String, String>> entrySet = configs.entrySet();
|
||||||
|
|
||||||
|
for (Entry<String, String> entry : entrySet) {
|
||||||
|
String filename = String.format(AndroidConstants.FN_RESOURCES_S_AP_,
|
||||||
|
entry.getKey());
|
||||||
|
|
||||||
// store the build status in the persistent storage
|
tmp = outputFolder.findMember(filename);
|
||||||
saveProjectBooleanProperty(PROPERTY_CONVERT_TO_DEX , mConvertToDex);
|
if (tmp == null || (tmp instanceof IFile &&
|
||||||
saveProjectBooleanProperty(PROPERTY_PACKAGE_RESOURCES, mPackageResources);
|
tmp.exists() == false)) {
|
||||||
saveProjectBooleanProperty(PROPERTY_BUILD_APK, mBuildFinalPackage);
|
String msg = String.format(Messages.s_Missing_Repackaging, filename);
|
||||||
|
AdtPlugin.printBuildToConsole(AdtConstants.BUILD_VERBOSE, project, msg);
|
||||||
if (dv != null && dv.mXmlError) {
|
mPackageResources = true;
|
||||||
AdtPlugin.printBuildToConsole(AdtConstants.BUILD_VERBOSE, project,
|
mBuildFinalPackage = true;
|
||||||
Messages.Xml_Error);
|
break;
|
||||||
|
}
|
||||||
// if there was some XML errors, we just return w/o doing
|
}
|
||||||
// anything since we've put some markers in the files anyway
|
}
|
||||||
return referencedProjects;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (outputFolder == null) {
|
// check classes.dex is present. If not we force to recreate it.
|
||||||
// mark project and exit
|
if (mConvertToDex == false) {
|
||||||
markProject(AdtConstants.MARKER_ADT, Messages.Failed_To_Get_Output,
|
tmp = outputFolder.findMember(AndroidConstants.FN_CLASSES_DEX);
|
||||||
IMarker.SEVERITY_ERROR);
|
if (tmp == null || tmp.exists() == false) {
|
||||||
return referencedProjects;
|
mConvertToDex = true;
|
||||||
}
|
mBuildFinalPackage = true;
|
||||||
|
}
|
||||||
// first thing we do is check that the SDK directory has been setup.
|
}
|
||||||
String osSdkFolder = AdtPlugin.getOsSdkFolder();
|
|
||||||
|
// also check the final file(s)!
|
||||||
if (osSdkFolder.length() == 0) {
|
String finalPackageName = ProjectHelper.getApkFilename(project, null /*config*/);
|
||||||
// this has already been checked in the precompiler. Therefore,
|
if (mBuildFinalPackage == false) {
|
||||||
// while we do have to cancel the build, we don't have to return
|
tmp = outputFolder.findMember(finalPackageName);
|
||||||
// any error or throw anything.
|
if (tmp == null || (tmp instanceof IFile &&
|
||||||
return referencedProjects;
|
tmp.exists() == false)) {
|
||||||
}
|
String msg = String.format(Messages.s_Missing_Repackaging, finalPackageName);
|
||||||
|
AdtPlugin.printBuildToConsole(AdtConstants.BUILD_VERBOSE, project, msg);
|
||||||
// get the extra configs for the project.
|
mBuildFinalPackage = true;
|
||||||
// The map contains (name, filter) where 'name' is a name to be used in the apk filename,
|
} else if (configs != null) {
|
||||||
// and filter is the resource filter to be used in the aapt -c parameters to restrict
|
// if the full apk is present, we check the filtered apk as well
|
||||||
// which resource configurations to package in the apk.
|
|
||||||
Map<String, String> configs = Sdk.getCurrent().getProjectApkConfigs(project);
|
|
||||||
|
|
||||||
// do some extra check, in case the output files are not present. This
|
|
||||||
// will force to recreate them.
|
|
||||||
IResource tmp = null;
|
|
||||||
|
|
||||||
if (mPackageResources == false) {
|
|
||||||
// check the full resource package
|
|
||||||
tmp = outputFolder.findMember(AndroidConstants.FN_RESOURCES_AP_);
|
|
||||||
if (tmp == null || tmp.exists() == false) {
|
|
||||||
mPackageResources = true;
|
|
||||||
mBuildFinalPackage = true;
|
|
||||||
} else {
|
|
||||||
// if the full package is present, we check the filtered resource packages as well
|
|
||||||
if (configs != null) {
|
|
||||||
Set<Entry<String, String>> entrySet = configs.entrySet();
|
Set<Entry<String, String>> entrySet = configs.entrySet();
|
||||||
|
|
||||||
for (Entry<String, String> entry : entrySet) {
|
for (Entry<String, String> entry : entrySet) {
|
||||||
String filename = String.format(AndroidConstants.FN_RESOURCES_S_AP_,
|
String filename = ProjectHelper.getApkFilename(project, entry.getKey());
|
||||||
entry.getKey());
|
|
||||||
|
|
||||||
tmp = outputFolder.findMember(filename);
|
tmp = outputFolder.findMember(filename);
|
||||||
if (tmp == null || (tmp instanceof IFile &&
|
if (tmp == null || (tmp instanceof IFile &&
|
||||||
tmp.exists() == false)) {
|
tmp.exists() == false)) {
|
||||||
String msg = String.format(Messages.s_Missing_Repackaging, filename);
|
String msg = String.format(Messages.s_Missing_Repackaging, filename);
|
||||||
AdtPlugin.printBuildToConsole(AdtConstants.BUILD_VERBOSE, project, msg);
|
AdtPlugin.printBuildToConsole(AdtConstants.BUILD_VERBOSE, project, msg);
|
||||||
mPackageResources = true;
|
|
||||||
mBuildFinalPackage = true;
|
mBuildFinalPackage = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
// at this point we know if we need to recreate the temporary apk
|
||||||
// check classes.dex is present. If not we force to recreate it.
|
// or the dex file, but we don't know if we simply need to recreate them
|
||||||
if (mConvertToDex == false) {
|
// because they are missing
|
||||||
tmp = outputFolder.findMember(AndroidConstants.FN_CLASSES_DEX);
|
|
||||||
if (tmp == null || tmp.exists() == false) {
|
// refresh the output directory first
|
||||||
mConvertToDex = true;
|
IContainer ic = outputFolder.getParent();
|
||||||
mBuildFinalPackage = true;
|
if (ic != null) {
|
||||||
|
ic.refreshLocal(IResource.DEPTH_ONE, monitor);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
// we need to test all three, as we may need to make the final package
|
||||||
// also check the final file(s)!
|
// but not the intermediary ones.
|
||||||
String finalPackageName = ProjectHelper.getApkFilename(project, null /*config*/);
|
if (mPackageResources || mConvertToDex || mBuildFinalPackage) {
|
||||||
if (mBuildFinalPackage == false) {
|
IPath binLocation = outputFolder.getLocation();
|
||||||
tmp = outputFolder.findMember(finalPackageName);
|
if (binLocation == null) {
|
||||||
if (tmp == null || (tmp instanceof IFile &&
|
markProject(AdtConstants.MARKER_ADT, Messages.Output_Missing,
|
||||||
tmp.exists() == false)) {
|
IMarker.SEVERITY_ERROR);
|
||||||
String msg = String.format(Messages.s_Missing_Repackaging, finalPackageName);
|
|
||||||
AdtPlugin.printBuildToConsole(AdtConstants.BUILD_VERBOSE, project, msg);
|
|
||||||
mBuildFinalPackage = true;
|
|
||||||
} else if (configs != null) {
|
|
||||||
// if the full apk is present, we check the filtered apk as well
|
|
||||||
Set<Entry<String, String>> entrySet = configs.entrySet();
|
|
||||||
|
|
||||||
for (Entry<String, String> entry : entrySet) {
|
|
||||||
String filename = ProjectHelper.getApkFilename(project, entry.getKey());
|
|
||||||
|
|
||||||
tmp = outputFolder.findMember(filename);
|
|
||||||
if (tmp == null || (tmp instanceof IFile &&
|
|
||||||
tmp.exists() == false)) {
|
|
||||||
String msg = String.format(Messages.s_Missing_Repackaging, filename);
|
|
||||||
AdtPlugin.printBuildToConsole(AdtConstants.BUILD_VERBOSE, project, msg);
|
|
||||||
mBuildFinalPackage = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// at this point we know if we need to recreate the temporary apk
|
|
||||||
// or the dex file, but we don't know if we simply need to recreate them
|
|
||||||
// because they are missing
|
|
||||||
|
|
||||||
// refresh the output directory first
|
|
||||||
IContainer ic = outputFolder.getParent();
|
|
||||||
if (ic != null) {
|
|
||||||
ic.refreshLocal(IResource.DEPTH_ONE, monitor);
|
|
||||||
}
|
|
||||||
|
|
||||||
// we need to test all three, as we may need to make the final package
|
|
||||||
// but not the intermediary ones.
|
|
||||||
if (mPackageResources || mConvertToDex || mBuildFinalPackage) {
|
|
||||||
IPath binLocation = outputFolder.getLocation();
|
|
||||||
if (binLocation == null) {
|
|
||||||
markProject(AdtConstants.MARKER_ADT, Messages.Output_Missing,
|
|
||||||
IMarker.SEVERITY_ERROR);
|
|
||||||
return referencedProjects;
|
|
||||||
}
|
|
||||||
String osBinPath = binLocation.toOSString();
|
|
||||||
|
|
||||||
// Remove the old .apk.
|
|
||||||
// This make sure that if the apk is corrupted, then dx (which would attempt
|
|
||||||
// to open it), will not fail.
|
|
||||||
String osFinalPackagePath = osBinPath + File.separator + finalPackageName;
|
|
||||||
File finalPackage = new File(osFinalPackagePath);
|
|
||||||
|
|
||||||
// if delete failed, this is not really a problem, as the final package generation
|
|
||||||
// handle already present .apk, and if that one failed as well, the user will be
|
|
||||||
// notified.
|
|
||||||
finalPackage.delete();
|
|
||||||
|
|
||||||
if (configs != null) {
|
|
||||||
Set<Entry<String, String>> entrySet = configs.entrySet();
|
|
||||||
for (Entry<String, String> entry : entrySet) {
|
|
||||||
String packageFilepath = osBinPath + File.separator +
|
|
||||||
ProjectHelper.getApkFilename(project, entry.getKey());
|
|
||||||
|
|
||||||
finalPackage = new File(packageFilepath);
|
|
||||||
finalPackage.delete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// first we check if we need to package the resources.
|
|
||||||
if (mPackageResources) {
|
|
||||||
// remove some aapt_package only markers.
|
|
||||||
removeMarkersFromContainer(project, AndroidConstants.MARKER_AAPT_PACKAGE);
|
|
||||||
|
|
||||||
// need to figure out some path before we can execute aapt;
|
|
||||||
|
|
||||||
// resource to the AndroidManifest.xml file
|
|
||||||
IResource manifestResource = project .findMember(
|
|
||||||
AndroidConstants.WS_SEP + AndroidConstants.FN_ANDROID_MANIFEST);
|
|
||||||
|
|
||||||
if (manifestResource == null
|
|
||||||
|| manifestResource.exists() == false) {
|
|
||||||
// mark project and exit
|
|
||||||
String msg = String.format(Messages.s_File_Missing,
|
|
||||||
AndroidConstants.FN_ANDROID_MANIFEST);
|
|
||||||
markProject(AdtConstants.MARKER_ADT, msg, IMarker.SEVERITY_ERROR);
|
|
||||||
return referencedProjects;
|
return referencedProjects;
|
||||||
}
|
}
|
||||||
|
String osBinPath = binLocation.toOSString();
|
||||||
// get the resource folder
|
|
||||||
IFolder resFolder = project.getFolder(
|
// Remove the old .apk.
|
||||||
AndroidConstants.WS_RESOURCES);
|
// This make sure that if the apk is corrupted, then dx (which would attempt
|
||||||
|
// to open it), will not fail.
|
||||||
// and the assets folder
|
String osFinalPackagePath = osBinPath + File.separator + finalPackageName;
|
||||||
IFolder assetsFolder = project.getFolder(
|
File finalPackage = new File(osFinalPackagePath);
|
||||||
AndroidConstants.WS_ASSETS);
|
|
||||||
|
// if delete failed, this is not really a problem, as the final package generation
|
||||||
// we need to make sure this one exists.
|
// handle already present .apk, and if that one failed as well, the user will be
|
||||||
if (assetsFolder.exists() == false) {
|
// notified.
|
||||||
assetsFolder = null;
|
finalPackage.delete();
|
||||||
}
|
|
||||||
|
if (configs != null) {
|
||||||
IPath resLocation = resFolder.getLocation();
|
Set<Entry<String, String>> entrySet = configs.entrySet();
|
||||||
IPath manifestLocation = manifestResource.getLocation();
|
for (Entry<String, String> entry : entrySet) {
|
||||||
|
String packageFilepath = osBinPath + File.separator +
|
||||||
if (resLocation != null && manifestLocation != null) {
|
ProjectHelper.getApkFilename(project, entry.getKey());
|
||||||
String osResPath = resLocation.toOSString();
|
|
||||||
String osManifestPath = manifestLocation.toOSString();
|
finalPackage = new File(packageFilepath);
|
||||||
|
finalPackage.delete();
|
||||||
String osAssetsPath = null;
|
|
||||||
if (assetsFolder != null) {
|
|
||||||
osAssetsPath = assetsFolder.getLocation().toOSString();
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// build the default resource package
|
|
||||||
if (executeAapt(project, osManifestPath, osResPath,
|
// first we check if we need to package the resources.
|
||||||
osAssetsPath, osBinPath + File.separator +
|
if (mPackageResources) {
|
||||||
AndroidConstants.FN_RESOURCES_AP_, null /*configFilter*/) == false) {
|
// remove some aapt_package only markers.
|
||||||
// aapt failed. Whatever files that needed to be marked
|
removeMarkersFromContainer(project, AndroidConstants.MARKER_AAPT_PACKAGE);
|
||||||
// have already been marked. We just return.
|
|
||||||
|
// need to figure out some path before we can execute aapt;
|
||||||
|
|
||||||
|
// resource to the AndroidManifest.xml file
|
||||||
|
IResource manifestResource = project .findMember(
|
||||||
|
AndroidConstants.WS_SEP + AndroidConstants.FN_ANDROID_MANIFEST);
|
||||||
|
|
||||||
|
if (manifestResource == null
|
||||||
|
|| manifestResource.exists() == false) {
|
||||||
|
// mark project and exit
|
||||||
|
String msg = String.format(Messages.s_File_Missing,
|
||||||
|
AndroidConstants.FN_ANDROID_MANIFEST);
|
||||||
|
markProject(AdtConstants.MARKER_ADT, msg, IMarker.SEVERITY_ERROR);
|
||||||
return referencedProjects;
|
return referencedProjects;
|
||||||
}
|
}
|
||||||
|
|
||||||
// now do the same thing for all the configured resource packages.
|
// get the resource folder
|
||||||
if (configs != null) {
|
IFolder resFolder = project.getFolder(
|
||||||
Set<Entry<String, String>> entrySet = configs.entrySet();
|
AndroidConstants.WS_RESOURCES);
|
||||||
for (Entry<String, String> entry : entrySet) {
|
|
||||||
String outPathFormat = osBinPath + File.separator +
|
// and the assets folder
|
||||||
AndroidConstants.FN_RESOURCES_S_AP_;
|
IFolder assetsFolder = project.getFolder(
|
||||||
String outPath = String.format(outPathFormat, entry.getKey());
|
AndroidConstants.WS_ASSETS);
|
||||||
if (executeAapt(project, osManifestPath, osResPath,
|
|
||||||
osAssetsPath, outPath, entry.getValue()) == false) {
|
// we need to make sure this one exists.
|
||||||
// aapt failed. Whatever files that needed to be marked
|
if (assetsFolder.exists() == false) {
|
||||||
// have already been marked. We just return.
|
assetsFolder = null;
|
||||||
return referencedProjects;
|
}
|
||||||
|
|
||||||
|
IPath resLocation = resFolder.getLocation();
|
||||||
|
IPath manifestLocation = manifestResource.getLocation();
|
||||||
|
|
||||||
|
if (resLocation != null && manifestLocation != null) {
|
||||||
|
String osResPath = resLocation.toOSString();
|
||||||
|
String osManifestPath = manifestLocation.toOSString();
|
||||||
|
|
||||||
|
String osAssetsPath = null;
|
||||||
|
if (assetsFolder != null) {
|
||||||
|
osAssetsPath = assetsFolder.getLocation().toOSString();
|
||||||
|
}
|
||||||
|
|
||||||
|
// build the default resource package
|
||||||
|
if (executeAapt(project, osManifestPath, osResPath,
|
||||||
|
osAssetsPath, osBinPath + File.separator +
|
||||||
|
AndroidConstants.FN_RESOURCES_AP_, null /*configFilter*/) == false) {
|
||||||
|
// aapt failed. Whatever files that needed to be marked
|
||||||
|
// have already been marked. We just return.
|
||||||
|
return referencedProjects;
|
||||||
|
}
|
||||||
|
|
||||||
|
// now do the same thing for all the configured resource packages.
|
||||||
|
if (configs != null) {
|
||||||
|
Set<Entry<String, String>> entrySet = configs.entrySet();
|
||||||
|
for (Entry<String, String> entry : entrySet) {
|
||||||
|
String outPathFormat = osBinPath + File.separator +
|
||||||
|
AndroidConstants.FN_RESOURCES_S_AP_;
|
||||||
|
String outPath = String.format(outPathFormat, entry.getKey());
|
||||||
|
if (executeAapt(project, osManifestPath, osResPath,
|
||||||
|
osAssetsPath, outPath, entry.getValue()) == false) {
|
||||||
|
// aapt failed. Whatever files that needed to be marked
|
||||||
|
// have already been marked. We just return.
|
||||||
|
return referencedProjects;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// build has been done. reset the state of the builder
|
||||||
|
mPackageResources = false;
|
||||||
|
|
||||||
|
// and store it
|
||||||
|
saveProjectBooleanProperty(PROPERTY_PACKAGE_RESOURCES, mPackageResources);
|
||||||
}
|
}
|
||||||
|
|
||||||
// build has been done. reset the state of the builder
|
|
||||||
mPackageResources = false;
|
|
||||||
|
|
||||||
// and store it
|
|
||||||
saveProjectBooleanProperty(PROPERTY_PACKAGE_RESOURCES, mPackageResources);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
// then we check if we need to package the .class into classes.dex
|
||||||
// then we check if we need to package the .class into classes.dex
|
if (mConvertToDex) {
|
||||||
if (mConvertToDex) {
|
if (executeDx(javaProject, osBinPath, osBinPath + File.separator +
|
||||||
if (executeDx(javaProject, osBinPath, osBinPath + File.separator +
|
AndroidConstants.FN_CLASSES_DEX, referencedJavaProjects) == false) {
|
||||||
AndroidConstants.FN_CLASSES_DEX, referencedJavaProjects) == false) {
|
// dx failed, we return
|
||||||
// dx failed, we return
|
|
||||||
return referencedProjects;
|
|
||||||
}
|
|
||||||
|
|
||||||
// build has been done. reset the state of the builder
|
|
||||||
mConvertToDex = false;
|
|
||||||
|
|
||||||
// and store it
|
|
||||||
saveProjectBooleanProperty(PROPERTY_CONVERT_TO_DEX, mConvertToDex);
|
|
||||||
}
|
|
||||||
|
|
||||||
// now we need to make the final package from the intermediary apk
|
|
||||||
// and classes.dex.
|
|
||||||
// This is the default package with all the resources.
|
|
||||||
|
|
||||||
String classesDexPath = osBinPath + File.separator + AndroidConstants.FN_CLASSES_DEX;
|
|
||||||
if (finalPackage(osBinPath + File.separator + AndroidConstants.FN_RESOURCES_AP_,
|
|
||||||
classesDexPath,osFinalPackagePath, javaProject,
|
|
||||||
referencedJavaProjects) == false) {
|
|
||||||
return referencedProjects;
|
|
||||||
}
|
|
||||||
|
|
||||||
// now do the same thing for all the configured resource packages.
|
|
||||||
if (configs != null) {
|
|
||||||
String resPathFormat = osBinPath + File.separator +
|
|
||||||
AndroidConstants.FN_RESOURCES_S_AP_;
|
|
||||||
|
|
||||||
Set<Entry<String, String>> entrySet = configs.entrySet();
|
|
||||||
for (Entry<String, String> entry : entrySet) {
|
|
||||||
// make the filename for the resource package.
|
|
||||||
String resPath = String.format(resPathFormat, entry.getKey());
|
|
||||||
|
|
||||||
// make the filename for the apk to generate
|
|
||||||
String apkOsFilePath = osBinPath + File.separator +
|
|
||||||
ProjectHelper.getApkFilename(project, entry.getKey());
|
|
||||||
if (finalPackage(resPath, classesDexPath, apkOsFilePath, javaProject,
|
|
||||||
referencedJavaProjects) == false) {
|
|
||||||
return referencedProjects;
|
return referencedProjects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// build has been done. reset the state of the builder
|
||||||
|
mConvertToDex = false;
|
||||||
|
|
||||||
|
// and store it
|
||||||
|
saveProjectBooleanProperty(PROPERTY_CONVERT_TO_DEX, mConvertToDex);
|
||||||
|
}
|
||||||
|
|
||||||
|
// now we need to make the final package from the intermediary apk
|
||||||
|
// and classes.dex.
|
||||||
|
// This is the default package with all the resources.
|
||||||
|
|
||||||
|
String classesDexPath = osBinPath + File.separator + AndroidConstants.FN_CLASSES_DEX;
|
||||||
|
if (finalPackage(osBinPath + File.separator + AndroidConstants.FN_RESOURCES_AP_,
|
||||||
|
classesDexPath,osFinalPackagePath, javaProject,
|
||||||
|
referencedJavaProjects) == false) {
|
||||||
|
return referencedProjects;
|
||||||
|
}
|
||||||
|
|
||||||
|
// now do the same thing for all the configured resource packages.
|
||||||
|
if (configs != null) {
|
||||||
|
String resPathFormat = osBinPath + File.separator +
|
||||||
|
AndroidConstants.FN_RESOURCES_S_AP_;
|
||||||
|
|
||||||
|
Set<Entry<String, String>> entrySet = configs.entrySet();
|
||||||
|
for (Entry<String, String> entry : entrySet) {
|
||||||
|
// make the filename for the resource package.
|
||||||
|
String resPath = String.format(resPathFormat, entry.getKey());
|
||||||
|
|
||||||
|
// make the filename for the apk to generate
|
||||||
|
String apkOsFilePath = osBinPath + File.separator +
|
||||||
|
ProjectHelper.getApkFilename(project, entry.getKey());
|
||||||
|
if (finalPackage(resPath, classesDexPath, apkOsFilePath, javaProject,
|
||||||
|
referencedJavaProjects) == false) {
|
||||||
|
return referencedProjects;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// we are done.
|
||||||
|
|
||||||
|
// get the resource to bin
|
||||||
|
outputFolder.refreshLocal(IResource.DEPTH_ONE, monitor);
|
||||||
|
|
||||||
|
// build has been done. reset the state of the builder
|
||||||
|
mBuildFinalPackage = false;
|
||||||
|
|
||||||
|
// and store it
|
||||||
|
saveProjectBooleanProperty(PROPERTY_BUILD_APK, mBuildFinalPackage);
|
||||||
|
|
||||||
|
// reset the installation manager to force new installs of this project
|
||||||
|
ApkInstallManager.getInstance().resetInstallationFor(project);
|
||||||
|
|
||||||
|
AdtPlugin.printBuildToConsole(AdtConstants.BUILD_VERBOSE, getProject(),
|
||||||
|
"Build Success!");
|
||||||
|
}
|
||||||
|
} catch (Exception exception) {
|
||||||
|
// try to catch other exception to actually display an error. This will be useful
|
||||||
|
// if we get an NPE or something so that we can at least notify the user that something
|
||||||
|
// went wrong.
|
||||||
|
|
||||||
|
// first check if this is a CoreException we threw to cancel the build.
|
||||||
|
if (exception instanceof CoreException) {
|
||||||
|
if (((CoreException)exception).getStatus().getCode() == IStatus.CANCEL) {
|
||||||
|
// Project is already marked with an error. Nothing to do
|
||||||
|
return referencedProjects;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// we are done.
|
String msg = exception.getMessage();
|
||||||
|
if (msg == null) {
|
||||||
|
msg = exception.getClass().getCanonicalName();
|
||||||
|
}
|
||||||
|
|
||||||
// get the resource to bin
|
msg = String.format("Unknown error: %1$s", msg);
|
||||||
outputFolder.refreshLocal(IResource.DEPTH_ONE, monitor);
|
AdtPlugin.printErrorToConsole(project, msg);
|
||||||
|
markProject(AdtConstants.MARKER_ADT, msg, IMarker.SEVERITY_ERROR);
|
||||||
// build has been done. reset the state of the builder
|
|
||||||
mBuildFinalPackage = false;
|
|
||||||
|
|
||||||
// and store it
|
|
||||||
saveProjectBooleanProperty(PROPERTY_BUILD_APK, mBuildFinalPackage);
|
|
||||||
|
|
||||||
// reset the installation manager to force new installs of this project
|
|
||||||
ApkInstallManager.getInstance().resetInstallationFor(project);
|
|
||||||
|
|
||||||
AdtPlugin.printBuildToConsole(AdtConstants.BUILD_VERBOSE, getProject(),
|
|
||||||
"Build Success!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return referencedProjects;
|
return referencedProjects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void startupOnInitialize() {
|
protected void startupOnInitialize() {
|
||||||
super.startupOnInitialize();
|
super.startupOnInitialize();
|
||||||
@@ -921,7 +947,6 @@ public class ApkBuilder extends BaseBuilder {
|
|||||||
AdtPlugin.printErrorToConsole(javaProject.getProject(), msg);
|
AdtPlugin.printErrorToConsole(javaProject.getProject(), msg);
|
||||||
markProject(AdtConstants.MARKER_ADT, msg, IMarker.SEVERITY_ERROR);
|
markProject(AdtConstants.MARKER_ADT, msg, IMarker.SEVERITY_ERROR);
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
if (fos != null) {
|
if (fos != null) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user