// this shouldn't happen as we have checked ahead of calling getDebugKey.
throw new RuntimeException(e);
}
try {
Packager packager = new Packager(
outApkLocation, androidResPkgLocation, classesDexLocation,
signingInfo, mLogger);
packager.setDebugJniMode(buildType.isDebugJniBuild());
// figure out conflicts!
JavaResourceProcessor resProcessor = new JavaResourceProcessor(packager);
if (mVariant.getBuildTypeSourceSet() != null) {
Set<File> buildTypeJavaResLocations =
mVariant.getBuildTypeSourceSet().getJavaResources();
for (File buildTypeJavaResLocation : buildTypeJavaResLocations) {
if (buildTypeJavaResLocation != null &&
buildTypeJavaResLocation.isDirectory()) {
resProcessor.addSourceFolder(buildTypeJavaResLocation.getAbsolutePath());
}
}
}
for (SourceSet sourceSet : mVariant.getFlavorSourceSets()) {
Set<File> flavorJavaResLocations = sourceSet.getJavaResources();
for (File flavorJavaResLocation : flavorJavaResLocations) {
if (flavorJavaResLocation != null && flavorJavaResLocation.isDirectory()) {
resProcessor.addSourceFolder(flavorJavaResLocation.getAbsolutePath());
}
}
}
Set<File> mainJavaResLocations = mVariant.getDefaultSourceSet().getJavaResources();
for (File mainJavaResLocation : mainJavaResLocations) {
if (mainJavaResLocation != null && mainJavaResLocation.isDirectory()) {
resProcessor.addSourceFolder(mainJavaResLocation.getAbsolutePath());
}
}
// add the resources from the jar files.
List<JarDependency> jars = mVariant.getJars();
if (jars != null) {
for (JarDependency jar : jars) {
packager.addResourcesFromJar(new File(jar.getLocation()));
}
}
// add the resources from the libs jar files
List<AndroidDependency> libs = mVariant.getDirectLibraries();
addLibJavaResourcesToPackager(packager, libs);
// also add resources from library projects and jars
if (jniLibsLocation != null) {
packager.addNativeLibraries(jniLibsLocation);
}
packager.sealApk();
} catch (PackagerException e) {
throw new RuntimeException(e);
} catch (SealedPackageException e) {
throw new RuntimeException(e);
}