diff --git a/app/.gitignore b/app/.gitignore index 4ff0d833..de8b9cf0 100644 --- a/app/.gitignore +++ b/app/.gitignore @@ -1,3 +1,6 @@ +# Files generated due to fix +android/build/app/ + # Miscellaneous *.class *.log diff --git a/app/CONTRIBUTING.md b/app/CONTRIBUTING.md index 34974fd9..77bc3ac5 100644 --- a/app/CONTRIBUTING.md +++ b/app/CONTRIBUTING.md @@ -28,6 +28,24 @@ alias flutter-generate='dart run build_runner build --delete-conflicting-outputs alias flutter-clean='find . -maxdepth 20 -type f \( -name "*.inject.summary" -o -name "*.inject.dart" -o -name "*.g.dart" \) -delete' ``` +## Updating Flutter and Android + +... can be super painful, because Java, Gradle, and Kotlin versions may be +wrong. + +Often problems in packages arise that rely on older Gradle versions. + +The places to check are: + +- Your Flutter version +- Your `JAVA_HOME` version +- The Gradle version in `gradle-wrapper.properties`; the recommended versions + are "between 7.3 and 7.6.1." (see + [Android Java Gradle migration guide](https://docs.flutter.dev/release/breaking-changes/android-java-gradle-migration-guide)) +- The Java version in `android/app/build/gradle` +- The Java version used for Gradle (check in Android Studio) +- The Kotlin version in `settings.gradle` + ## Architecture The app consists of multiple so-called modules. Our main modules (usually app diff --git a/app/android/build.gradle b/app/android/build.gradle index aca8b4a2..329f8738 100644 --- a/app/android/build.gradle +++ b/app/android/build.gradle @@ -18,6 +18,55 @@ allprojects { } } +subprojects { + afterEvaluate { project -> + // From https://medium.com/@vortj/solving-namespace-errors-in-flutters-android-gradle-configuration-c2baa6262f8b + if (project.hasProperty('android')) { + project.android { + if (namespace == null) { + namespace = project.group.toString() // Set namespace as fallback + } + project.tasks.whenTaskAdded { task -> + if (task.name.contains('processDebugManifest') || task.name.contains('processReleaseManifest')) { + task.doFirst { + File manifestFile = file("${projectDir}/src/main/AndroidManifest.xml") + if (manifestFile.exists()) { + String manifestContent = manifestFile.text + if (manifestContent.contains('package=')) { + manifestContent = manifestContent.replaceAll(/package="[^"]*"/, "") + manifestFile.write(manifestContent) + println "Removed 'package' attribute from ${manifestFile}" + } + } + } + } + } + } + } + // From https://github.com/flutter/flutter/issues/153281#issuecomment-2292201697 + if (project.extensions.findByName("android") != null) { + Integer pluginCompileSdk = project.android.compileSdk + if (pluginCompileSdk != null && pluginCompileSdk < 31) { + project.logger.error( + "Warning: Overriding compileSdk version in Flutter plugin: " + + project.name + + " from " + + pluginCompileSdk + + " to 31 (to work around https://issuetracker.google.com/issues/199180389)." + + "\nIf there is not a new version of " + project.name + ", consider filing an issue against " + + project.name + + " to increase their compileSdk to the latest (otherwise try updating to the latest version)." + ) + project.android { + compileSdk 31 + } + } + } + } + project.buildDir = "${rootProject.buildDir}/${project.name}" + project.evaluationDependsOn(":app") +} + rootProject.buildDir = '../build' subprojects { project.buildDir = "${rootProject.buildDir}/${project.name}" @@ -27,3 +76,10 @@ subprojects { tasks.register("clean", Delete) { delete rootProject.buildDir } + +// From https://stackoverflow.com/a/69050529 +configurations.all { + resolutionStrategy { + force 'androidx.core:core-ktx:1.6.0' + } +}