feat(export): use compileSdkVersion from manifest, update AGP to 8.10.1, other improvements (PR #2528)

* chore(core): export to android project with AGP 8.10.1

* fix code format

* fix export template test

---------

Co-authored-by: Skylot <118523+skylot@users.noreply.github.com>
This commit is contained in:
Akexorcist
2025-06-08 02:09:29 +07:00
committed by GitHub
parent d523f1b15e
commit 46cd3b5597
8 changed files with 31 additions and 9 deletions
@@ -31,7 +31,8 @@ public class AndroidGradleGenerator implements IExportGradleGenerator {
private static final Logger LOG = LoggerFactory.getLogger(AndroidGradleGenerator.class);
private static final Pattern ILLEGAL_GRADLE_CHARS = Pattern.compile("[/\\\\:>\"?*|]");
private static final ApplicationParams UNKNOWN_APP_PARAMS = new ApplicationParams("UNKNOWN", 0, 0, 0, "UNKNOWN", "UNKNOWN", "UNKNOWN");
private static final ApplicationParams UNKNOWN_APP_PARAMS =
new ApplicationParams("UNKNOWN", 0, 0, 0, 0, "UNKNOWN", "UNKNOWN", "UNKNOWN");
private final RootNode root;
private final File projectDir;
@@ -107,6 +108,7 @@ public class AndroidGradleGenerator implements IExportGradleGenerator {
if (exportApp) {
attrs.add(AppAttribute.APPLICATION_LABEL);
attrs.add(AppAttribute.TARGET_SDK_VERSION);
attrs.add(AppAttribute.COMPILE_SDK_VERSION);
attrs.add(AppAttribute.VERSION_NAME);
attrs.add(AppAttribute.VERSION_CODE);
}
@@ -160,6 +162,7 @@ public class AndroidGradleGenerator implements IExportGradleGenerator {
TemplateFile tmpl = TemplateFile.fromResources("/export/android/app.build.gradle.tmpl");
tmpl.add("applicationId", appPackage);
tmpl.add("minSdkVersion", minSdkVersion);
tmpl.add("compileSdkVersion", applicationParams.getCompileSdkVersion());
tmpl.add("targetSdkVersion", applicationParams.getTargetSdkVersion());
tmpl.add("versionCode", applicationParams.getVersionCode());
tmpl.add("versionName", applicationParams.getVersionName());
@@ -174,6 +177,7 @@ public class AndroidGradleGenerator implements IExportGradleGenerator {
TemplateFile tmpl = TemplateFile.fromResources("/export/android/lib.build.gradle.tmpl");
tmpl.add("packageId", pkg);
tmpl.add("minSdkVersion", minSdkVersion);
tmpl.add("compileSdkVersion", applicationParams.getCompileSdkVersion());
tmpl.add("additionalOptions", genAdditionalAndroidPluginOptions(minSdkVersion));
tmpl.save(new File(baseDir, "build.gradle"));
@@ -61,6 +61,7 @@ public class AndroidManifestParser {
String applicationLabel = null;
Integer minSdkVersion = null;
Integer targetSdkVersion = null;
Integer compileSdkVersion = null;
Integer versionCode = null;
String versionName = null;
String mainActivity = null;
@@ -89,6 +90,14 @@ public class AndroidManifestParser {
targetSdkVersion = minSdkVersion;
}
}
if (parseAttrs.contains(AppAttribute.COMPILE_SDK_VERSION)) {
String stringCompileSdk = usesSdk.getAttribute("android:compileSdkVersion");
if (!stringCompileSdk.isEmpty()) {
compileSdkVersion = Integer.valueOf(stringCompileSdk);
} else {
compileSdkVersion = targetSdkVersion;
}
}
}
if (manifest != null) {
if (parseAttrs.contains(AppAttribute.VERSION_CODE)) {
@@ -105,8 +114,8 @@ public class AndroidManifestParser {
application = getApplicationName();
}
return new ApplicationParams(applicationLabel, minSdkVersion, targetSdkVersion, versionCode,
versionName, mainActivity, application);
return new ApplicationParams(applicationLabel, minSdkVersion, targetSdkVersion, compileSdkVersion,
versionCode, versionName, mainActivity, application);
}
private String getApplicationLabel() {
@@ -3,6 +3,7 @@ package jadx.core.utils.android;
public enum AppAttribute {
APPLICATION_LABEL,
MIN_SDK_VERSION,
COMPILE_SDK_VERSION,
TARGET_SDK_VERSION,
VERSION_CODE,
VERSION_NAME,
@@ -8,16 +8,18 @@ public class ApplicationParams {
private final String applicationLabel;
private final Integer minSdkVersion;
private final Integer targetSdkVersion;
private final Integer compileSdkVersion;
private final Integer versionCode;
private final String versionName;
private final String mainActivity;
private final String application;
public ApplicationParams(String applicationLabel, Integer minSdkVersion, Integer targetSdkVersion, Integer versionCode,
String versionName, String mainActivity, String application) {
public ApplicationParams(String applicationLabel, Integer minSdkVersion, Integer targetSdkVersion, Integer compileSdkVersion,
Integer versionCode, String versionName, String mainActivity, String application) {
this.applicationLabel = applicationLabel;
this.minSdkVersion = minSdkVersion;
this.targetSdkVersion = targetSdkVersion;
this.compileSdkVersion = compileSdkVersion;
this.versionCode = versionCode;
this.versionName = versionName;
this.mainActivity = mainActivity;
@@ -36,6 +38,10 @@ public class ApplicationParams {
return targetSdkVersion;
}
public Integer getCompileSdkVersion() {
return compileSdkVersion;
}
public Integer getVersionCode() {
return versionCode;
}
@@ -3,8 +3,8 @@ plugins {
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
namespace "{{applicationId}}"
compileSdkVersion {{compileSdkVersion}}
defaultConfig {
applicationId '{{applicationId}}'
@@ -4,7 +4,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.2'
classpath 'com.android.tools.build:gradle:8.10.1'
}
}
@@ -4,7 +4,7 @@ plugins {
android {
namespace '{{packageId}}'
compileSdk 30
compileSdk {{compileSdkVersion}}
defaultConfig {
minSdk {{minSdkVersion}}
@@ -17,6 +17,7 @@ public class TemplateFileTest {
tmpl.add("versionCode", 3);
tmpl.add("versionName", "1.2.3");
tmpl.add("additionalOptions", "useLibrary 'org.apache.http.legacy'");
tmpl.add("compileSdkVersion", 4);
String res = tmpl.build();
System.out.println(res);
@@ -24,5 +25,6 @@ public class TemplateFileTest {
assertThat(res).contains("targetSdkVersion 2");
assertThat(res).contains("versionCode 3");
assertThat(res).contains("versionName \"1.2.3\"");
assertThat(res).contains("compileSdkVersion 4");
}
}