Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Kotlin support when using gradle 8 #3792

Merged
merged 1 commit into from
Mar 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ public class AndroidGradleBuilder extends Executor {

private boolean useGradle8 = true;

// Flag to indicate whether we should strip kotlin from user classes
// Necessary for using gradle 8 because kotlin seems to be included by default,
// so we get duplicate class errors.
private boolean stripKotlinFromUserClasses = true;

private boolean extendAppCompatActivity = false;

private boolean useJava8SourceLevel = true;
Expand Down Expand Up @@ -477,6 +482,8 @@ public boolean build(File sourceZip, final BuildRequest request) throws BuildExc
newFirebaseMessaging = request.getArg("android.newFirebaseMessaging", "true").equals("true");
useGradle8 = request.getArg("android.useGradle8", ""+(useGradle8 || newFirebaseMessaging || facebookSupported)).equals("true");
extendAppCompatActivity = request.getArg("android.extendAppCompatActivity", "false").equals("true");
// When using gradle 8 we need to strip kotlin files from user classes otherwise we get duplicate class errors
stripKotlinFromUserClasses = useGradle8;
useJava8SourceLevel = request.getArg("android.java8", ""+useJava8SourceLevel).equals("true");
if (useGradle8) {
getGradleJavaHome(); // will throw build exception if JAVA17_HOME is not set
Expand Down Expand Up @@ -976,6 +983,9 @@ public boolean build(File sourceZip, final BuildRequest request) throws BuildExc
} catch (Exception ex) {
throw new BuildException("Failed to extract source zip "+sourceZip, ex);
}
if (stripKotlinFromUserClasses) {
stripKotlin(dummyClassesDir);
}

File appDir = buildToolsVersionInt >= 27 ?
new File(srcDir.getParentFile(), "app") :
Expand Down Expand Up @@ -4445,4 +4455,19 @@ private void initPlayServiceVersions(BuildRequest request) {
}
}
}

private void stripKotlin(File dummyClassesDir) {
String[] skipDirectories = new String[] {
"org" + File.separator + "jetbrains" + File.separator + "annotations",
"org" + File.separator + "intellij" + File.separator + "lang" + File.separator + "annotations",
"kotlin"
};
for (String path : skipDirectories) {
File directory = new File(dummyClassesDir, path);
if (directory.isDirectory()) {
log("Deleting directory " + directory);
delTree(directory, true);
}
}
}
}
Loading