added OSDection, and prebuilt aapt

This commit is contained in:
Connor Tumbleson 2013-03-28 19:51:08 -05:00
parent c5d2ecf96f
commit 90577d40e8
3 changed files with 84 additions and 14 deletions

View File

@ -332,21 +332,30 @@ final public class AndrolibResources {
// path for aapt binary // path for aapt binary
if (!aaptPath.isEmpty()) { if (!aaptPath.isEmpty()) {
File aaptFile = new File(aaptPath); File aaptFile = new File(aaptPath);
if (aaptFile.canRead() && aaptFile.exists()) { if (aaptFile.canRead() && aaptFile.exists()) {
aaptFile.setExecutable(true); aaptFile.setExecutable(true);
cmd.add(aaptFile.getPath()); cmd.add(aaptFile.getPath());
if (flags.get("verbose")) { if (flags.get("verbose")) {
LOGGER.info(aaptFile.getPath() LOGGER.info(aaptFile.getPath()
+ " being used as aapt location."); + " being used as aapt location.");
} }
} else { } else {
LOGGER.warning("aapt location could not be found. Defaulting back to default"); LOGGER.warning("aapt location could not be found. Defaulting back to default");
cmd.add("aapt");
} try {
cmd.add(getAaptBinaryFile().getAbsolutePath());
} catch (BrutException ignored) {
cmd.add("aapt");
}
}
} else { } else {
cmd.add("aapt"); try {
cmd.add(getAaptBinaryFile().getAbsolutePath());
} catch (BrutException ignored) {
cmd.add("aapt");
}
} }
cmd.add("p"); cmd.add("p");
@ -728,7 +737,7 @@ final public class AndrolibResources {
// if a framework path was specified on the command line, use it // if a framework path was specified on the command line, use it
if (sFrameworkFolder != null) { if (sFrameworkFolder != null) {
path = sFrameworkFolder; path = sFrameworkFolder;
} else if (System.getProperty("os.name").equals("Mac OS X")) { } else if (OSDetection.isMacOSX()) {
// store in user-home, for Mac OS X // store in user-home, for Mac OS X
path = System.getProperty("user.home") + File.separatorChar + "Library/apktool/framework"; path = System.getProperty("user.home") + File.separatorChar + "Library/apktool/framework";
} else { } else {
@ -747,6 +756,33 @@ final public class AndrolibResources {
} }
return dir; return dir;
} }
/**
*
* @see https://github.com/iBotPeaches/platform_frameworks_base
* @return
* @throws AndrolibException
*/
public File getAaptBinaryFile() throws AndrolibException {
try {
if (OSDetection.isMacOSX()) {
mAaptBinary = Jar
.getResourceAsFile("/aapt/macosx/aapt");
} else if (OSDetection.isUnix()) {
mAaptBinary = Jar
.getResourceAsFile("/aapt/linux/aapt");
} else if (OSDetection.isWindows()) {
mAaptBinary = Jar
.getResourceAsFile("/aapt/windows/aapt.exe");
} else {
return null;
}
} catch (BrutException ex) {
throw new AndrolibException(ex);
}
mAaptBinary.setExecutable(true);
return mAaptBinary;
}
public File getAndroidResourcesFile() throws AndrolibException { public File getAndroidResourcesFile() throws AndrolibException {
try { try {
@ -776,5 +812,6 @@ final public class AndrolibResources {
private String mVersionName = null; private String mVersionName = null;
private String mPackageRenamed = null; private String mPackageRenamed = null;
private File mAaptBinary = null;
} }

View File

@ -0,0 +1,33 @@
/**
* Copyright 2010 Ryszard Wiśniewski <brut.alll@gmail.com>
* Copyright 2013 Connor Tumbleson <connor.tumbleson@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package brut.util;
public class OSDetection {
private static String OS = System.getProperty("os.name").toLowerCase();
public static boolean isWindows() {
return (OS.indexOf("win") >= 0);
}
public static boolean isMacOSX() {
return (OS.indexOf("mac") >= 0);
}
public static boolean isUnix() {
return (OS.indexOf("nix") >= 0 || OS.indexOf("nux") >= 0 || OS.indexOf("aix") > 0 || (OS.indexOf("sunos") >= 0));
}
}