fix: fix failing apk release build

This commit is contained in:
Patryk Hegenberg 2025-12-01 08:02:23 +01:00
parent d680030b16
commit 952e82eb08
3 changed files with 24 additions and 20 deletions

View file

@ -9,12 +9,12 @@ android {
compileSdk = 36 compileSdk = 36
compileOptions { compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8 sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_17
} }
kotlinOptions { kotlinOptions {
jvmTarget = "1.8" jvmTarget = "17"
} }
defaultConfig { defaultConfig {

View file

@ -1,3 +1,5 @@
import com.android.build.gradle.BaseExtension
buildscript { buildscript {
repositories { repositories {
google() google()
@ -24,31 +26,36 @@ subprojects {
} }
subprojects { subprojects {
// 1. Fix ZUERST registrieren (bevor das Projekt evaluiert wird)
afterEvaluate { afterEvaluate {
// Prüfen, ob das Subprojekt eine Android-Erweiterung hat (Library oder App)
val android = project.extensions.findByName("android") val android = project.extensions.findByName("android")
if (android != null) { if (android != null) {
// Wir versuchen, auf die 'namespace'-Eigenschaft zuzugreifen.
// Da wir hier im Root-Skript sind und die Typen dynamisch sind, nutzen wir Reflection/Dynamik. if (android is BaseExtension) {
android.compileSdkVersion(36)
}
try { try {
val namespaceProp = android.javaClass.getMethod("getNamespace") val androidClass = android.javaClass
try {
val namespaceProp = androidClass.getMethod("getNamespace")
val currentNamespace = namespaceProp.invoke(android) val currentNamespace = namespaceProp.invoke(android)
if (currentNamespace == null) { if (currentNamespace == null) {
// Wenn kein Namespace gesetzt ist, setzen wir ihn auf den Gruppennamen oder Package-Namen val setNamespace = androidClass.getMethod("setNamespace", String::class.java)
val setNamespace = android.javaClass.getMethod("setNamespace", String::class.java)
val newNamespace = project.group.toString() val newNamespace = project.group.toString()
setNamespace.invoke(android, newNamespace) setNamespace.invoke(android, newNamespace)
println("FIX: Namespace für '${project.name}' auf '$newNamespace' gesetzt.") println("FIX: Namespace für '${project.name}' auf '$newNamespace' gesetzt.")
} }
} catch (e: NoSuchMethodException) {
}
} catch (e: Exception) { } catch (e: Exception) {
println("WARNUNG: Konnte Namespace für ${project.name} nicht automatisch setzen: $e") println("WARNUNG: Konnte Namespace für ${project.name} nicht automatisch setzen: $e")
} }
} }
} }
// 2. DANACH erst die Abhängigkeit zur App definieren
project.evaluationDependsOn(":app") project.evaluationDependsOn(":app")
} }

View file

@ -12,13 +12,11 @@ import 'src/shared/data/local/collections/workout_collection.dart';
void main() async { void main() async {
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
// Lock orientation to portrait
await SystemChrome.setPreferredOrientations([ await SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp, DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown, DeviceOrientation.portraitDown,
]); ]);
// Initialize Isar database
final dir = await getApplicationDocumentsDirectory(); final dir = await getApplicationDocumentsDirectory();
final isar = await Isar.open( final isar = await Isar.open(
[UserCollectionSchema, CycleCollectionSchema, WorkoutCollectionSchema], [UserCollectionSchema, CycleCollectionSchema, WorkoutCollectionSchema],
@ -34,5 +32,4 @@ void main() async {
); );
} }
// Global Isar provider
final isarProvider = Provider<Isar>((ref) => throw UnimplementedError()); final isarProvider = Provider<Isar>((ref) => throw UnimplementedError());