Fix ApkTool errors after decompile: Change sparseResources to false

This commit is contained in:
AndnixSH
2023-09-13 11:50:23 +02:00
parent 58314b84e0
commit c897d959a3
5 changed files with 34 additions and 23 deletions
+17 -22
View File
@@ -12,9 +12,9 @@ namespace APKToolGUI.ApkTool
{
public class ApkFixer
{
public static bool FixAndroidManifest(string path)
public static bool FixAndroidManifest(string decompilePath)
{
string manifestPath = Path.Combine(path, "AndroidManifest.xml");
string manifestPath = Path.Combine(decompilePath, "AndroidManifest.xml");
if (File.Exists(manifestPath))
{
string maniFestText = File.ReadAllText(manifestPath);
@@ -26,13 +26,27 @@ namespace APKToolGUI.ApkTool
maniFestText = maniFestText.Replace("android:localeConfig=\"@xml/locales_config\"", "");
maniFestText = maniFestText.Replace("STAMP_TYPE_DISTRIBUTION_APK", "STAMP_TYPE_STANDALONE_APK");
File.WriteAllText(Path.Combine(path, "AndroidManifest.xml"), maniFestText);
File.WriteAllText(manifestPath, maniFestText);
return true;
}
return false;
}
public static bool FixApktoolYml(string decompilePath)
{
string ymlPath = Path.Combine(decompilePath, "apktool.yml");
if (File.Exists(ymlPath))
{
string yml = File.ReadAllText(ymlPath);
yml = yml.Replace("sparseResources: true", "sparseResources: false");
File.WriteAllText(ymlPath, yml);
return true;
}
return false;
}
public static bool RemoveApkToolDummies(string path)
{
string resPath = Path.Combine(path, "res", "values");
@@ -43,24 +57,5 @@ namespace APKToolGUI.ApkTool
}
return false;
}
public static bool ChangeSdkTo29(string path)
{
string ymlPath = Path.Combine(path, "apktool.yml");
if (File.Exists(ymlPath))
{
string ymll = File.ReadAllText(ymlPath);
int sdk = 30;
int.TryParse(StringExt.Regex(@"(?<= targetSdkVersion: \')(.*?)(?=\')", ymll), out sdk);
if (sdk >= 30)
{
ymll = ymll.Replace("targetSdkVersion: '" + sdk + "'", "targetSdkVersion: '29'");
File.WriteAllText(ymlPath, ymll);
return true;
}
}
return false;
}
}
}
+4
View File
@@ -751,6 +751,8 @@ namespace APKToolGUI
{
if (ApkFixer.FixAndroidManifest(outputDir))
ToLog(ApktoolEventType.None, Language.FixAndroidManifest);
if (ApkFixer.FixApktoolYml(outputDir))
ToLog(ApktoolEventType.None, Language.FixApktoolYml);
if (ApkFixer.RemoveApkToolDummies(outputDir))
ToLog(ApktoolEventType.None, Language.RemoveApkToolDummies);
}
@@ -892,6 +894,8 @@ namespace APKToolGUI
{
if (ApkFixer.FixAndroidManifest(outputDir))
ToLog(ApktoolEventType.None, Language.FixAndroidManifest);
if (ApkFixer.FixApktoolYml(outputDir))
ToLog(ApktoolEventType.None, Language.FixApktoolYml);
if (ApkFixer.RemoveApkToolDummies(outputDir))
ToLog(ApktoolEventType.None, Language.RemoveApkToolDummies);
}
+1 -1
View File
@@ -2302,7 +2302,7 @@
<value>454, 16</value>
</metadata>
<data name="checkBox_DECODE_FixError.ToolTip" xml:space="preserve">
<value>It will remove isSplitRequired, extractNativeLibs, useEmbeddedDex, APKTOOL_DUMMY and set </value>
<value>It will remove extractNativeLibs, useEmbeddedDex, APKTOOL_DUMMY, split related attributes and set sparseResources to false</value>
</data>
<data name="&gt;&gt;checkBox_DECODE_FixError.Name" xml:space="preserve">
<value>checkBox_DECODE_FixError</value>
+9
View File
@@ -762,6 +762,15 @@ namespace APKToolGUI.Languages {
}
}
/// <summary>
/// Looks up a localized string similar to Fixed apktool.yml.
/// </summary>
internal static string FixApktoolYml {
get {
return ResourceManager.GetString("FixApktoolYml", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Folder does not exist.
/// </summary>
+3
View File
@@ -531,4 +531,7 @@
<data name="OpenDecFolder" xml:space="preserve">
<value>Open decompile output folder</value>
</data>
<data name="FixApktoolYml" xml:space="preserve">
<value>Fixed apktool.yml</value>
</data>
</root>