use of com.tencent.tinker.build.apkparser.AndroidParser in project tinker by Tencent.
the class ManifestDecoder method patch.
@Override
public boolean patch(File oldFile, File newFile) throws IOException, TinkerPatchException {
final boolean ignoreWarning = config.mIgnoreWarning;
try {
AndroidParser oldAndroidManifest = AndroidParser.getAndroidManifest(oldFile);
AndroidParser newAndroidManifest = AndroidParser.getAndroidManifest(newFile);
//check minSdkVersion
int minSdkVersion = Integer.parseInt(oldAndroidManifest.apkMeta.getMinSdkVersion());
if (minSdkVersion < TypedValue.ANDROID_40_API_LEVEL) {
if (config.mDexRaw) {
if (ignoreWarning) {
//ignoreWarning, just log
Logger.e("Warning:ignoreWarning is true, but your old apk's minSdkVersion %d is below 14, you should set the dexMode to 'jar', otherwise, it will crash at some time", minSdkVersion);
} else {
Logger.e("Warning:ignoreWarning is false, but your old apk's minSdkVersion %d is below 14, you should set the dexMode to 'jar', otherwise, it will crash at some time", minSdkVersion);
throw new TinkerPatchException(String.format("ignoreWarning is false, but your old apk's minSdkVersion %d is below 14, you should set the dexMode to 'jar', otherwise, it will crash at some time", minSdkVersion));
}
}
}
//check whether there is any new Android Component
List<String> oldAndroidComponent = oldAndroidManifest.getComponents();
List<String> newAndroidComponent = newAndroidManifest.getComponents();
for (String newComponentName : newAndroidComponent) {
boolean found = false;
for (String oldComponentName : oldAndroidComponent) {
if (newComponentName.equals(oldComponentName)) {
found = true;
break;
}
}
if (!found) {
if (ignoreWarning) {
Logger.e("Warning:ignoreWarning is true, but we found a new AndroidComponent %s, it will crash at some time", newComponentName);
} else {
Logger.e("Warning:ignoreWarning is false, but we found a new AndroidComponent %s, it will crash at some time", newComponentName);
throw new TinkerPatchException(String.format("ignoreWarning is false, but we found a new AndroidComponent %s, it will crash at some time", newComponentName));
}
}
}
} catch (ParseException e) {
e.printStackTrace();
throw new TinkerPatchException("parse android manifest error!");
}
return false;
}
use of com.tencent.tinker.build.apkparser.AndroidParser in project tinker by Tencent.
the class PatchInfoGen method addTinkerID.
private void addTinkerID() throws IOException, ParseException {
if (!config.mPackageFields.containsKey(TypedValue.TINKER_ID)) {
AndroidParser oldAndroidManifest = AndroidParser.getAndroidManifest(config.mOldApkFile);
String tinkerID = oldAndroidManifest.metaDatas.get(TypedValue.TINKER_ID);
if (tinkerID == null) {
throw new TinkerPatchException("can't find TINKER_ID from the old apk manifest file, it must be set!");
}
config.mPackageFields.put(TypedValue.TINKER_ID, tinkerID);
}
if (!config.mPackageFields.containsKey(TypedValue.NEW_TINKER_ID)) {
AndroidParser newAndroidManifest = AndroidParser.getAndroidManifest(config.mNewApkFile);
String tinkerID = newAndroidManifest.metaDatas.get(TypedValue.TINKER_ID);
if (tinkerID == null) {
throw new TinkerPatchException("can't find TINKER_ID from the new apk manifest file, it must be set!");
}
config.mPackageFields.put(TypedValue.NEW_TINKER_ID, tinkerID);
}
}
Aggregations