Skip to content

Commit

Permalink
build(app): hacky fix for building APKs
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Nov 14, 2024
1 parent 1ec5fd4 commit 6748553
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Files generated due to fix
android/build/app/

# Miscellaneous
*.class
*.log
Expand Down
18 changes: 18 additions & 0 deletions app/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
56 changes: 56 additions & 0 deletions app/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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'
}
}

0 comments on commit 6748553

Please sign in to comment.