Shared Library Rebuilding Support

- handles references with shared resources
 - adds support for --shared-lib
 - update unit-tests
This commit is contained in:
Connor Tumbleson 2015-03-08 14:31:21 -05:00
parent 2f7ae8c001
commit 0a74de4ab0
8 changed files with 36 additions and 2 deletions

View File

@ -270,6 +270,7 @@ public class Androlib {
mAndRes.setPackageId((Map<String, String>) meta.get("packageInfo"));
mAndRes.setPackageInfo((Map<String, String>) meta.get("packageInfo"));
mAndRes.setVersionInfo((Map<String, String>) meta.get("versionInfo"));
mAndRes.setSharedLibrary((boolean) meta.get("sharedLibrary"));
if (outFile == null) {
String outFileName = (String) meta.get("apkFileName");

View File

@ -320,6 +320,7 @@ public class ApkDecoder {
putPackageInfo(meta);
putVersionInfo(meta);
putCompressionInfo(meta);
putSharedLibraryInfo(meta);
}
putUnknownInfo(meta);
@ -393,6 +394,10 @@ public class ApkDecoder {
meta.put("compressionType", getCompressionType());
}
private void putSharedLibraryInfo(Map<String, Object> meta) throws AndrolibException {
meta.put("sharedLibrary", mResTable.getSharedLibrary());
}
private boolean getCompressionType() {
return mCompressResources;
}

View File

@ -379,6 +379,10 @@ final public class AndrolibResources {
}
}
public void setSharedLibrary(boolean flag) {
mSharedLibrary = flag;
}
public void aaptPackage(File apkFile, File manifest, File resDir, File rawDir, File assetDir, File[] include)
throws AndrolibException {
@ -428,10 +432,13 @@ final public class AndrolibResources {
// force package id so that some frameworks build with correct id
// disable if user adds own aapt (can't know if they have this feature)
if (mPackageId != null && ! customAapt) {
if (mPackageId != null && ! customAapt && ! mSharedLibrary) {
cmd.add("--forced-package-id");
cmd.add(mPackageId);
}
if (mSharedLibrary) {
cmd.add("--shared-lib");
}
if (mMinSdkVersion != null) {
cmd.add("--min-sdk-version");
cmd.add(mMinSdkVersion);
@ -847,6 +854,8 @@ final public class AndrolibResources {
private String mPackageOriginal = null;
private String mPackageId = null;
private boolean mSharedLibrary = false;
private File mAaptBinary = null;
private final static String[] IGNORED_PACKAGES = new String[] {

View File

@ -35,7 +35,7 @@ public class ResID {
}
public ResID(int package_, int type, int entry, int id) {
this.package_ = package_;
this.package_ = (package_ == 0) ? 2 : package_;
this.type = type;
this.entry = entry;
this.id = id;

View File

@ -37,6 +37,7 @@ public class ResTable {
private String mPackageOriginal;
private int mPackageId;
private boolean mAnalysisMode = false;
private boolean mSharedLibrary = false;
private Map<String, String> mSdkInfo = new LinkedHashMap<String, String>();
private Map<String, String> mVersionInfo = new LinkedHashMap<String, String>();
@ -50,6 +51,13 @@ public class ResTable {
}
public ResResSpec getResSpec(int resID) throws AndrolibException {
// The pkgId is 0x00. That means a shared library is using its
// own resource, so lie to the caller replacing with its own
// packageId
if (resID >> 24 == 0) {
int pkgId = (mPackageId == 0 ? 2 : mPackageId);
resID = (0xFF000000 & (pkgId << 24)) | resID;
}
return getResSpec(new ResID(resID));
}
@ -158,6 +166,10 @@ public class ResTable {
mPackageId = id;
}
public void setSharedLibrary(boolean flag) {
mSharedLibrary = flag;
}
public void clearSdkInfo() {
mSdkInfo.clear();
}
@ -193,4 +205,8 @@ public class ResTable {
public int getPackageId() {
return mPackageId;
}
public boolean getSharedLibrary() {
return mSharedLibrary;
}
}

View File

@ -90,6 +90,7 @@ public class ARSCDecoder {
// for Apktool's use we need a non-zero packageId.
// AOSP indicates 0x02 is next, as 0x01 is system and 0x7F is private.
id = 2;
mResTable.setSharedLibrary(true);
}
String name = mIn.readNullEndedString(128, true);

View File

@ -10,6 +10,7 @@ versionInfo:
versionCode: '1'
versionName: '1.0'
compressionType: false
sharedLibrary: false
unknownFiles:
hidden.file: '8'
unk_folder/unknown_file: '8'

View File

@ -1,2 +1,3 @@
version: 2.0.0
apkFileName: testjar.jar
sharedLibrary: false