将 gradle 更新到 8.0 后,如果我在 android build.gradle 中设置了命名空间,则在构建 apk 事件时会出现命名空间错误
这是我的构建 gradle 代码
build.gradle:android /应用程序
android {
compileSdkVersion localProperties.getProperty('flutter.compileSdkVersion').toInteger()//33
namespace 'com.appidname.here'
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
applicationId "com.appidname.here"
minSdkVersion localProperties.getProperty('flutter.minSdkVersion').toInteger()//21
targetSdkVersion localProperties.getProperty('flutter.targetSdkVersion').toInteger()//33
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
....
}
build.gradle:android
buildscript {
ext.kotlin_version = '1.8.22'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
....
这是我在构建 apk 或 appbuble 时遇到的错误。
错误
* What went wrong:
A problem occurred configuring project ':webview_pro_android'.
> Could not create an instance of type com.android.build.api.variant.impl.LibraryVariantBuilderImpl.
> Namespace not specified. Please specify a namespace in the module's build.gradle file like so:
android {
namespace 'com.example.namespace'
}
从错误中我认为命名空间尚未在所有插件模块中设置。 如何解决这个问题,如何向所有插件模块添加命名空间? 谢谢
我认为你应该将以下代码添加到文件“build.gradle:android/app”
将以下代码粘贴到“android”标签:
命名空间'package_name你的项目'