diff options
author | Xavier Ducrohet <xav@android.com> | 2010-06-16 15:02:35 -0700 |
---|---|---|
committer | Xavier Ducrohet <xav@android.com> | 2010-06-16 18:23:27 -0700 |
commit | e48a35070a0b27ec8ea99e2cd3bf999a11b175b5 (patch) | |
tree | c06c3be8fd634fb364503b7be063822b35a32e00 /apkbuilder | |
parent | 2a035855ee6c91bdfa25516ea39195ee263471ab (diff) | |
download | sdk-e48a35070a0b27ec8ea99e2cd3bf999a11b175b5.zip sdk-e48a35070a0b27ec8ea99e2cd3bf999a11b175b5.tar.gz sdk-e48a35070a0b27ec8ea99e2cd3bf999a11b175b5.tar.bz2 |
Move Apkbuilder into sdklib.
Change-Id: I88f7e6101b8c03157a320a6c9d9b7424ffbdc7f5
Diffstat (limited to 'apkbuilder')
-rw-r--r-- | apkbuilder/.classpath | 8 | ||||
-rw-r--r-- | apkbuilder/.gitignore | 2 | ||||
-rw-r--r-- | apkbuilder/.project | 17 | ||||
-rw-r--r-- | apkbuilder/Android.mk | 18 | ||||
-rw-r--r-- | apkbuilder/etc/Android.mk | 22 | ||||
-rwxr-xr-x | apkbuilder/etc/apkbuilder | 16 | ||||
-rwxr-xr-x | apkbuilder/etc/apkbuilder.bat | 7 | ||||
-rw-r--r-- | apkbuilder/etc/manifest.txt | 1 | ||||
-rw-r--r-- | apkbuilder/readme.txt | 5 | ||||
-rw-r--r-- | apkbuilder/src/Android.mk | 29 | ||||
-rw-r--r-- | apkbuilder/src/com/android/apkbuilder/ApkBuilderMain.java | 178 | ||||
-rw-r--r-- | apkbuilder/src/com/android/apkbuilder/internal/ApkBuilderHelper.java | 436 |
12 files changed, 9 insertions, 730 deletions
diff --git a/apkbuilder/.classpath b/apkbuilder/.classpath deleted file mode 100644 index 63ec892..0000000 --- a/apkbuilder/.classpath +++ /dev/null @@ -1,8 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<classpath> - <classpathentry kind="src" path="src"/> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> - <classpathentry combineaccessrules="false" kind="src" path="/AndroidPrefs"/> - <classpathentry combineaccessrules="false" kind="src" path="/SdkLib"/> - <classpathentry kind="output" path="bin"/> -</classpath> diff --git a/apkbuilder/.gitignore b/apkbuilder/.gitignore deleted file mode 100644 index fe99505..0000000 --- a/apkbuilder/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -bin - diff --git a/apkbuilder/.project b/apkbuilder/.project deleted file mode 100644 index cc97afc..0000000 --- a/apkbuilder/.project +++ /dev/null @@ -1,17 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<projectDescription> - <name>ApkBuilder</name> - <comment></comment> - <projects> - </projects> - <buildSpec> - <buildCommand> - <name>org.eclipse.jdt.core.javabuilder</name> - <arguments> - </arguments> - </buildCommand> - </buildSpec> - <natures> - <nature>org.eclipse.jdt.core.javanature</nature> - </natures> -</projectDescription> diff --git a/apkbuilder/Android.mk b/apkbuilder/Android.mk deleted file mode 100644 index bdfe5c8..0000000 --- a/apkbuilder/Android.mk +++ /dev/null @@ -1,18 +0,0 @@ -# -# Copyright (C) 2008 The Android Open Source Project -# -# 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. -# -APKBUILDER_LOCAL_DIR := $(call my-dir) -include $(APKBUILDER_LOCAL_DIR)/etc/Android.mk -include $(APKBUILDER_LOCAL_DIR)/src/Android.mk diff --git a/apkbuilder/etc/Android.mk b/apkbuilder/etc/Android.mk deleted file mode 100644 index d74db17..0000000 --- a/apkbuilder/etc/Android.mk +++ /dev/null @@ -1,22 +0,0 @@ -# -# Copyright (C) 2008 The Android Open Source Project -# -# 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. -# - -LOCAL_PATH := $(call my-dir) -include $(CLEAR_VARS) - -LOCAL_PREBUILT_EXECUTABLES := apkbuilder -include $(BUILD_HOST_PREBUILT) - diff --git a/apkbuilder/etc/apkbuilder b/apkbuilder/etc/apkbuilder index 3e7e822..2116cdc 100755 --- a/apkbuilder/etc/apkbuilder +++ b/apkbuilder/etc/apkbuilder @@ -33,18 +33,15 @@ progdir=`pwd` prog="${progdir}"/`basename "${prog}"` cd "${oldwd}" -jarfile=apkbuilder.jar +jarfile=sdklib.jar frameworkdir="$progdir" -libdir="$progdir" if [ ! -r "$frameworkdir/$jarfile" ] then frameworkdir=`dirname "$progdir"`/tools/lib - libdir=`dirname "$progdir"`/tools/lib fi if [ ! -r "$frameworkdir/$jarfile" ] then frameworkdir=`dirname "$progdir"`/framework - libdir=`dirname "$progdir"`/lib fi if [ ! -r "$frameworkdir/$jarfile" ] then @@ -62,20 +59,11 @@ else java_debug= fi -# Mac OS X needs an additional arg, or you get an "illegal thread" complaint. -if [ `uname` = "Darwin" ]; then - os_opts="-XstartOnFirstThread" -else - os_opts= -fi - if [ "$OSTYPE" = "cygwin" ] ; then jarpath=`cygpath -w "$frameworkdir/$jarfile"` - progdir=`cygpath -w "$progdir"` else jarpath="$frameworkdir/$jarfile" fi -# need to use "java.ext.dirs" because "-jar" causes classpath to be ignored # might need more memory, e.g. -Xmx128M -exec java -Xmx128M $os_opts $java_debug -Djava.ext.dirs="$frameworkdir" -Djava.library.path="$libdir" -jar "$jarpath" "$@" +exec java -Xmx128M $java_debug -classpath "$jarpath" com.android.sdklib.build.ApkBuilderMain "$@" diff --git a/apkbuilder/etc/apkbuilder.bat b/apkbuilder/etc/apkbuilder.bat index eaaf9b8..c82f01d 100755 --- a/apkbuilder/etc/apkbuilder.bat +++ b/apkbuilder/etc/apkbuilder.bat @@ -29,20 +29,17 @@ set java_exe= call lib\find_java.bat if not defined java_exe goto :EOF -set jarfile=apkbuilder.jar +set jarfile=sdklib.jar set frameworkdir= -set libdir= if exist %frameworkdir%%jarfile% goto JarFileOk set frameworkdir=lib\ - set libdir=lib\ if exist %frameworkdir%%jarfile% goto JarFileOk set frameworkdir=..\framework\ - set libdir=..\lib\ :JarFileOk set jarpath=%frameworkdir%%jarfile% -call %java_exe% -Djava.ext.dirs=%frameworkdir% -Djava.library.path=%libdir% -jar %jarpath% %* +call %java_exe% -classpath %jarpath% com.android.sdklib.build.ApkBuilderMain %* diff --git a/apkbuilder/etc/manifest.txt b/apkbuilder/etc/manifest.txt deleted file mode 100644 index 6aafb16..0000000 --- a/apkbuilder/etc/manifest.txt +++ /dev/null @@ -1 +0,0 @@ -Main-Class: com.android.apkbuilder.ApkBuilder diff --git a/apkbuilder/readme.txt b/apkbuilder/readme.txt new file mode 100644 index 0000000..1bb7bc8 --- /dev/null +++ b/apkbuilder/readme.txt @@ -0,0 +1,5 @@ +The apkbuilder command line tool is deprecated, and is not maintained anymore. +It is lacking recent build improvements such as support for Library Projects. + +Its source code has been moved into sdklib. +It is recommended to directly use the com.android.sdklib.build.ApkBuilder class instead.
\ No newline at end of file diff --git a/apkbuilder/src/Android.mk b/apkbuilder/src/Android.mk deleted file mode 100644 index 24ab27a..0000000 --- a/apkbuilder/src/Android.mk +++ /dev/null @@ -1,29 +0,0 @@ -# -# Copyright (C) 2008 The Android Open Source Project -# -# 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. -# - -LOCAL_PATH := $(call my-dir) -include $(CLEAR_VARS) - -LOCAL_SRC_FILES := $(call all-subdir-java-files) -LOCAL_JAR_MANIFEST := ../etc/manifest.txt -LOCAL_JAVA_LIBRARIES := \ - androidprefs \ - sdklib - -LOCAL_MODULE := apkbuilder - -include $(BUILD_HOST_JAVA_LIBRARY) - diff --git a/apkbuilder/src/com/android/apkbuilder/ApkBuilderMain.java b/apkbuilder/src/com/android/apkbuilder/ApkBuilderMain.java deleted file mode 100644 index 08124ad..0000000 --- a/apkbuilder/src/com/android/apkbuilder/ApkBuilderMain.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * 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 com.android.apkbuilder; - -import com.android.apkbuilder.internal.ApkBuilderHelper; -import com.android.apkbuilder.internal.ApkBuilderHelper.ApkCreationException; -import com.android.apkbuilder.internal.ApkBuilderHelper.ApkFile; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.util.ArrayList; - - -/** - * Command line APK builder with signing support. - */ -public final class ApkBuilderMain { - - public final static class WrongOptionException extends Exception { - private static final long serialVersionUID = 1L; - - public WrongOptionException(String message) { - super(message); - } - } - - /** - * Main method. This is meant to be called from the command line through an exec. - * <p/>WARNING: this will call {@link System#exit(int)} if anything goes wrong. - * @param args command line arguments. - */ - public static void main(String[] args) { - if (args.length < 1) { - printUsageAndQuit(); - } - - try { - ApkBuilderHelper helper = new ApkBuilderHelper(); - - - // read the first args that should be a file path - File outFile = helper.getOutFile(args[0]); - - ArrayList<FileInputStream> zipArchives = new ArrayList<FileInputStream>(); - ArrayList<File> archiveFiles = new ArrayList<File>(); - ArrayList<ApkFile> javaResources = new ArrayList<ApkFile>(); - ArrayList<FileInputStream> resourcesJars = new ArrayList<FileInputStream>(); - ArrayList<ApkFile> nativeLibraries = new ArrayList<ApkFile>(); - - int index = 1; - do { - String argument = args[index++]; - - if ("-v".equals(argument)) { - helper.setVerbose(true); - } else if ("-d".equals(argument)) { - helper.setDebugMode(true); - } else if ("-u".equals(argument)) { - helper.setSignedPackage(false); - } else if ("-z".equals(argument)) { - // quick check on the next argument. - if (index == args.length) { - printAndExit("Missing value for -z"); - } - - try { - FileInputStream input = new FileInputStream(args[index++]); - zipArchives.add(input); - } catch (FileNotFoundException e) { - throw new ApkCreationException("-z file is not found"); - } - } else if ("-f". equals(argument)) { - // quick check on the next argument. - if (index == args.length) { - printAndExit("Missing value for -f"); - } - - archiveFiles.add(ApkBuilderHelper.getInputFile(args[index++])); - } else if ("-rf". equals(argument)) { - // quick check on the next argument. - if (index == args.length) { - printAndExit("Missing value for -rf"); - } - - ApkBuilderHelper.processSourceFolderForResource( - new File(args[index++]), javaResources); - } else if ("-rj". equals(argument)) { - // quick check on the next argument. - if (index == args.length) { - printAndExit("Missing value for -rj"); - } - - ApkBuilderHelper.processJar(new File(args[index++]), resourcesJars); - } else if ("-nf".equals(argument)) { - // quick check on the next argument. - if (index == args.length) { - printAndExit("Missing value for -nf"); - } - - ApkBuilderHelper.processNativeFolder(new File(args[index++]), - helper.getDebugMode(), nativeLibraries, - helper.isVerbose(), null /*abiFilter*/); - } else if ("-storetype".equals(argument)) { - // quick check on the next argument. - if (index == args.length) { - printAndExit("Missing value for -storetype"); - } - - helper.setStoreType(args[index++]); - } else { - printAndExit("Unknown argument: " + argument); - } - } while (index < args.length); - - helper.createPackage(outFile, zipArchives, archiveFiles, javaResources, resourcesJars, - nativeLibraries); - - } catch (FileNotFoundException e) { - printAndExit(e.getMessage()); - } catch (ApkCreationException e) { - printAndExit(e.getMessage()); - } - } - - private static void printUsageAndQuit() { - // 80 cols marker: 01234567890123456789012345678901234567890123456789012345678901234567890123456789 - System.err.println("A command line tool to package an Android application from various sources."); - System.err.println("Usage: apkbuilder <out archive> [-v][-u][-storetype STORE_TYPE] [-z inputzip]"); - System.err.println(" [-f inputfile] [-rf input-folder] [-rj -input-path]"); - System.err.println(""); - System.err.println(" -v Verbose."); - System.err.println(" -d Debug Mode: Includes debug files in the APK file."); - System.err.println(" -u Creates an unsigned package."); - System.err.println(" -storetype Forces the KeyStore type. If ommited the default is used."); - System.err.println(""); - System.err.println(" -z Followed by the path to a zip archive."); - System.err.println(" Adds the content of the application package."); - System.err.println(""); - System.err.println(" -f Followed by the path to a file."); - System.err.println(" Adds the file to the application package."); - System.err.println(""); - System.err.println(" -rf Followed by the path to a source folder."); - System.err.println(" Adds the java resources found in that folder to the application"); - System.err.println(" package, while keeping their path relative to the source folder."); - System.err.println(""); - System.err.println(" -rj Followed by the path to a jar file or a folder containing"); - System.err.println(" jar files."); - System.err.println(" Adds the java resources found in the jar file(s) to the application"); - System.err.println(" package."); - System.err.println(""); - System.err.println(" -nf Followed by the root folder containing native libraries to"); - System.err.println(" include in the application package."); - - System.exit(1); - } - - private static void printAndExit(String... messages) { - for (String message : messages) { - System.err.println(message); - } - System.exit(1); - } -} diff --git a/apkbuilder/src/com/android/apkbuilder/internal/ApkBuilderHelper.java b/apkbuilder/src/com/android/apkbuilder/internal/ApkBuilderHelper.java deleted file mode 100644 index 3046942..0000000 --- a/apkbuilder/src/com/android/apkbuilder/internal/ApkBuilderHelper.java +++ /dev/null @@ -1,436 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * 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 com.android.apkbuilder.internal; - -import com.android.prefs.AndroidLocation.AndroidLocationException; -import com.android.sdklib.internal.build.DebugKeyProvider; -import com.android.sdklib.internal.build.JavaResourceFilter; -import com.android.sdklib.internal.build.SignedJarBuilder; -import com.android.sdklib.internal.build.DebugKeyProvider.KeytoolException; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.FilenameFilter; -import java.io.IOException; -import java.security.PrivateKey; -import java.security.cert.X509Certificate; -import java.text.DateFormat; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; -import java.util.regex.Pattern; - -/** - * Command line APK builder with signing support. - */ -public final class ApkBuilderHelper { - - private final static Pattern PATTERN_JAR_EXT = Pattern.compile("^.+\\.jar$", - Pattern.CASE_INSENSITIVE); - private final static Pattern PATTERN_NATIVELIB_EXT = Pattern.compile("^.+\\.so$", - Pattern.CASE_INSENSITIVE); - - private final static String NATIVE_LIB_ROOT = "lib/"; - private final static String GDBSERVER_NAME = "gdbserver"; - - public final static class ApkCreationException extends Exception { - private static final long serialVersionUID = 1L; - - public ApkCreationException(String message) { - super(message); - } - - public ApkCreationException(Throwable throwable) { - super(throwable); - } - } - - - /** - * A File to be added to the APK archive. - * <p/>This includes the {@link File} representing the file and its path in the archive. - */ - public final static class ApkFile { - String archivePath; - File file; - - ApkFile(File file, String path) { - this.file = file; - this.archivePath = path; - } - } - - private JavaResourceFilter mResourceFilter = new JavaResourceFilter(); - private boolean mVerbose = false; - private boolean mSignedPackage = true; - private boolean mDebugMode = false; - /** the optional type of the debug keystore. If <code>null</code>, the default */ - private String mStoreType = null; - - public void setVerbose(boolean verbose) { - mVerbose = verbose; - } - - public boolean isVerbose() { - return mVerbose; - } - - public void setSignedPackage(boolean signedPackage) { - mSignedPackage = signedPackage; - } - - public void setDebugMode(boolean debugMode) { - mDebugMode = debugMode; - } - - public boolean getDebugMode() { - return mDebugMode; - } - - /** - * Set the type of the keystore. <code>null</code> means the default. - * @param storeType - */ - public void setStoreType(String storeType) { - mStoreType = storeType; - } - - /** - * Returns the store type. <code>null</code> means default. - * @return - */ - public String getStoreType() { - return mStoreType; - } - - public File getOutFile(String filepath) throws ApkCreationException { - File f = new File(filepath); - - if (f.isDirectory()) { - throw new ApkCreationException(filepath + " is a directory!"); - } - - if (f.exists()) { // will be a file in this case. - if (f.canWrite() == false) { - throw new ApkCreationException("Cannot write " + filepath); - } - } else { - try { - if (f.createNewFile() == false) { - throw new ApkCreationException("Failed to create " + filepath); - } - } catch (IOException e) { - throw new ApkCreationException( - "Failed to create '" + filepath + "' : " + e.getMessage()); - } - } - - return f; - } - - /** - * Returns a {@link File} representing a given file path. The path must represent - * an actual existing file (not a directory). The path may be relative. - * @param filepath the path to a file. - * @return the File representing the path. - * @throws ApkCreationException if the path represents a directory or if the file does not - * exist, or cannot be read. - */ - public static File getInputFile(String filepath) throws ApkCreationException { - File f = new File(filepath); - - if (f.isDirectory()) { - throw new ApkCreationException(filepath + " is a directory!"); - } - - if (f.exists()) { - if (f.canRead() == false) { - throw new ApkCreationException("Cannot read " + filepath); - } - } else { - throw new ApkCreationException(filepath + " does not exists!"); - } - - return f; - } - - /** - * Processes a source folder and adds its java resources to a given list of {@link ApkFile}. - * @param folder the folder representing the source folder. - * @param javaResources the list of {@link ApkFile} to fill. - * @throws ApkCreationException - */ - public static void processSourceFolderForResource(File folder, - ArrayList<ApkFile> javaResources) throws ApkCreationException { - if (folder.isDirectory()) { - // file is a directory, process its content. - File[] files = folder.listFiles(); - for (File file : files) { - processFileForResource(file, null, javaResources); - } - } else { - // not a directory? output error and quit. - if (folder.exists()) { - throw new ApkCreationException(folder.getAbsolutePath() + " is not a folder!"); - } else { - throw new ApkCreationException(folder.getAbsolutePath() + " does not exist!"); - } - } - } - - /** - * Process a jar file or a jar folder - * @param file the {@link File} to process - * @param resourcesJars the collection of FileInputStream to fill up with jar files. - * @throws FileNotFoundException - * @throws ApkCreationException - */ - public static void processJar(File file, Collection<FileInputStream> resourcesJars) - throws FileNotFoundException, ApkCreationException { - if (file.isDirectory()) { - String[] filenames = file.list(new FilenameFilter() { - public boolean accept(File dir, String name) { - return PATTERN_JAR_EXT.matcher(name).matches(); - } - }); - - for (String filename : filenames) { - File f = new File(file, filename); - processJarFile(f, resourcesJars); - } - } else if (file.isFile()) { - processJarFile(file, resourcesJars); - } else { - throw new ApkCreationException(file.getAbsolutePath()+ " does not exist!"); - } - } - - public static void processJarFile(File file, Collection<FileInputStream> resourcesJars) - throws FileNotFoundException { - FileInputStream input = new FileInputStream(file); - resourcesJars.add(input); - } - - /** - * Processes a {@link File} that could be a {@link ApkFile}, or a folder containing - * java resources. - * @param file the {@link File} to process. - * @param path the relative path of this file to the source folder. Can be <code>null</code> to - * identify a root file. - * @param javaResources the Collection of {@link ApkFile} object to fill. - */ - private static void processFileForResource(File file, String path, - Collection<ApkFile> javaResources) { - if (file.isDirectory()) { - // a directory? we check it - if (JavaResourceFilter.checkFolderForPackaging(file.getName())) { - // if it's valid, we append its name to the current path. - if (path == null) { - path = file.getName(); - } else { - path = path + "/" + file.getName(); - } - - // and process its content. - File[] files = file.listFiles(); - for (File contentFile : files) { - processFileForResource(contentFile, path, javaResources); - } - } - } else { - // a file? we check it - if (JavaResourceFilter.checkFileForPackaging(file.getName())) { - // we append its name to the current path - if (path == null) { - path = file.getName(); - } else { - path = path + "/" + file.getName(); - } - - // and add it to the list. - javaResources.add(new ApkFile(file, path)); - } - } - } - - /** - * Process a {@link File} for native library inclusion. - * <p/>The root folder must include folders that include .so files. - * @param root the native root folder. - * @param nativeLibraries the collection to add native libraries to. - * @param verbose verbose mode. - * @param abiFilter optional ABI filter. If non-null only the given ABI is included. - * @throws ApkCreationException - */ - public static void processNativeFolder(File root, boolean debugMode, - Collection<ApkFile> nativeLibraries, boolean verbose, String abiFilter) - throws ApkCreationException { - if (root.isDirectory() == false) { - throw new ApkCreationException(root.getAbsolutePath() + " is not a folder!"); - } - - File[] abiList = root.listFiles(); - - if (verbose) { - System.out.println("Processing native folder: " + root.getAbsolutePath()); - if (abiFilter != null) { - System.out.println("ABI Filter: " + abiFilter); - } - } - - if (abiList != null) { - for (File abi : abiList) { - if (abi.isDirectory()) { // ignore files - - // check the abi filter and reject all other ABIs - if (abiFilter != null && abiFilter.equals(abi.getName()) == false) { - if (verbose) { - System.out.println("Rejecting ABI " + abi.getName()); - } - continue; - } - - File[] libs = abi.listFiles(); - if (libs != null) { - for (File lib : libs) { - // only consider files that are .so or, if in debug mode, that - // are gdbserver executables - if (lib.isFile() && - (PATTERN_NATIVELIB_EXT.matcher(lib.getName()).matches() || - (debugMode && GDBSERVER_NAME.equals(lib.getName())))) { - String path = - NATIVE_LIB_ROOT + abi.getName() + "/" + lib.getName(); - - nativeLibraries.add(new ApkFile(lib, path)); - } - } - } - } - } - } - } - - /** - * Creates the application package - * @param outFile the package file to create - * @param zipArchives the list of zip archive - * @param files the list of files to include in the archive - * @param javaResources the list of java resources from the source folders. - * @param resourcesJars the list of jar files from which to take java resources - * @throws ApkCreationException - */ - public void createPackage(File outFile, Iterable<? extends FileInputStream> zipArchives, - Iterable<? extends File> files, Iterable<? extends ApkFile> javaResources, - Iterable<? extends FileInputStream> resourcesJars, - Iterable<? extends ApkFile> nativeLibraries) throws ApkCreationException { - - // get the debug key - try { - SignedJarBuilder builder; - - if (mSignedPackage) { - System.err.println(String.format("Using keystore: %s", - DebugKeyProvider.getDefaultKeyStoreOsPath())); - - - DebugKeyProvider keyProvider = new DebugKeyProvider( - null /* osKeyPath: use default */, - mStoreType, null /* IKeyGenOutput */); - PrivateKey key = keyProvider.getDebugKey(); - X509Certificate certificate = (X509Certificate)keyProvider.getCertificate(); - - if (key == null) { - throw new ApkCreationException("Unable to get debug signature key"); - } - - // compare the certificate expiration date - if (certificate != null && certificate.getNotAfter().compareTo(new Date()) < 0) { - // TODO, regenerate a new one. - throw new ApkCreationException("Debug Certificate expired on " + - DateFormat.getInstance().format(certificate.getNotAfter())); - } - - builder = new SignedJarBuilder( - new FileOutputStream(outFile.getAbsolutePath(), false /* append */), key, - certificate); - } else { - builder = new SignedJarBuilder( - new FileOutputStream(outFile.getAbsolutePath(), false /* append */), - null /* key */, null /* certificate */); - } - - // add the archives - for (FileInputStream input : zipArchives) { - builder.writeZip(input, null /* filter */); - } - - // add the single files - for (File input : files) { - // always put the file at the root of the archive in this case - builder.writeFile(input, input.getName()); - if (mVerbose) { - System.err.println(String.format("%1$s => %2$s", input.getAbsolutePath(), - input.getName())); - } - } - - // add the java resource from the source folders. - for (ApkFile resource : javaResources) { - builder.writeFile(resource.file, resource.archivePath); - if (mVerbose) { - System.err.println(String.format("%1$s => %2$s", - resource.file.getAbsolutePath(), resource.archivePath)); - } - } - - // add the java resource from jar files. - for (FileInputStream input : resourcesJars) { - builder.writeZip(input, mResourceFilter); - } - - // add the native files - for (ApkFile file : nativeLibraries) { - builder.writeFile(file.file, file.archivePath); - if (mVerbose) { - System.err.println(String.format("%1$s => %2$s", file.file.getAbsolutePath(), - file.archivePath)); - } - } - - // close and sign the application package. - builder.close(); - } catch (KeytoolException e) { - if (e.getJavaHome() == null) { - throw new ApkCreationException(e.getMessage() + - "\nJAVA_HOME seems undefined, setting it will help locating keytool automatically\n" + - "You can also manually execute the following command\n:" + - e.getCommandLine()); - } else { - throw new ApkCreationException(e.getMessage() + - "\nJAVA_HOME is set to: " + e.getJavaHome() + - "\nUpdate it if necessary, or manually execute the following command:\n" + - e.getCommandLine()); - } - } catch (AndroidLocationException e) { - throw new ApkCreationException(e); - } catch (Exception e) { - throw new ApkCreationException(e); - } - } -} |