執行命令:flutter build apk --release
報錯
Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!FAILURE: Build failed with an exception. * What went wrong:
A problem occurred configuring project ':isar_flutter_libs'.
> Could not create an instance of type com.android.build.api.variant.impl.LibraryVariantBuilderImpl. > Namespace not specified. Specify a namespace in the module's build file: C:\Users\17602\AppData\Local\Pub\Cache\hosted\pub.flutter-io.cn\isar_flutter_libs-3.1.0+1\android\build.gradle. See https://d.android.com/r/tools/upgrade-assistant/set-namespace for information about setting the namespace.If you've specified the package attribute in the source AndroidManifest.xml, you can use the AGP Upgrade Assistant to migrate to the namespace value in the build file. Refer to https://d.android.com/r/tools/upgrade-assistant/agp-upgrade-assistant for general information about using the AGP Upgrade Assistant.* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org. BUILD FAILED in 1s
Running Gradle task 'assembleRelease'... 1,292ms
Gradle task assembleRelease failed with exit code 1
- 然后參考:https://github.com/isar/isar/issues/1672
在\android\build.gradle.kts文件中添加以下代碼
// 添加這部分代碼,且當前subprojects 必須是當前文件的第一個subprojects塊
subprojects {afterEvaluate {project.extensions.configure<com.android.build.gradle.BaseExtension> {if (namespace == null) namespace = project.group.toString()}}
}
再次嘗試構建,發現會提示另一個錯誤:
FAILURE: Build failed with an exception.What went wrong:
Execution failed for task ':isar_flutter_libs:verifyReleaseResources'.
A failure occurred while executing com.android.build.gradle.tasks.VerifyLibraryResourcesTask$Action
Android resource linking failed
ERROR:E:......\build\isar_flutter_libs\intermediates\merged_res\release\values\values.xml:194: AAPT: error: resource android:attr/lStar not found.Try:
Run with --stacktrace option to get the stack trace.
Run with --info or --debug option to get more log output.
Run with --scan to get full insights.Get more help at https://help.gradle.org
- 最后再另一個issue里面找到了解決方案:
https://github.com/isar/isar/issues/1681
使用以下subprojects 區塊代碼,替換\android\build.gradle.kts里的所有subprojects 區塊
subprojects {val newSubprojectBuildDir: Directory = newBuildDir.dir(project.name)project.layout.buildDirectory.value(newSubprojectBuildDir)
}subprojects {afterEvaluate {if (project.hasProperty("android")) {val androidExtension = project.extensions.findByName("android")if (androidExtension is com.android.build.gradle.BaseExtension) {androidExtension.compileSdkVersion = "android-35"androidExtension.buildToolsVersion = "35.0.0"androidExtension.ndkVersion = "27.0.12077973"if (androidExtension.namespace == null) {androidExtension.namespace = project.group.toString()}}}}
}subprojects {project.evaluationDependsOn(":app")
}
最后再執行構建命令就可以成功構建了
但是后來發現isar在github上已經兩年多沒更新了,遂切換其他本地數據庫