Dol*_*rma 19 android gradle build.gradle flutter
我决定使用最新版本并Gradle更新后出现此错误,但无法解决AndroidManifest.xmlbuild.gradle
错误:
Namespace not specified. Please specify a namespace in the module's build.gradle file like so:
android {
namespace 'com.example.namespace'
}
If the package attribute is specified in the source AndroidManifest.xml, it can be migrated automatically to the namespace value in the build.gradle file using the AGP Upgrade Assistant; please refer to https://developer.android.com/studio/build/agp-upgrade-assistant for more information.
Run Code Online (Sandbox Code Playgroud)
应用build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:8.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
Run Code Online (Sandbox Code Playgroud)
gradle.wrapper.properties:
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
Run Code Online (Sandbox Code Playgroud)
AndroidManifest.xml
Namespace not specified. Please specify a namespace in the module's build.gradle file like so:
android {
namespace 'com.example.namespace'
}
If the package attribute is specified in the source AndroidManifest.xml, it can be migrated automatically to the namespace value in the build.gradle file using the AGP Upgrade Assistant; please refer to https://developer.android.com/studio/build/agp-upgrade-assistant for more information.
Run Code Online (Sandbox Code Playgroud)
和build.gradle
plugins {
id "com.android.application"
id "kotlin-android"
id "dev.flutter.flutter-gradle-plugin"
}
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
android {
namespace "com.example.xxxxx"
compileSdkVersion flutter.compileSdkVersion
ndkVersion flutter.ndkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
applicationId "com.example.xxxxx"
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
buildTypes {
release {
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {}
Run Code Online (Sandbox Code Playgroud)
Dmi*_*zak 14
为了解决依赖项目中命名空间声明的问题,我在 android/build.gradle 中添加了以下 Gradle 脚本:
subprojects {
afterEvaluate { project ->
if (project.hasProperty('android')) {
project.android {
if (namespace == null) {
namespace project.group
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
它使用包名称并将其设置为命名空间(如果尚未在依赖项中指定)
Ced*_*dar 11
我已将以下行添加到app/build.gradle
android{
namespace 'com.example.application
....
}
Run Code Online (Sandbox Code Playgroud)
请务必将其添加到项目文件夹中 app 文件夹中的build.gradle文件中。
我认为namespace出现此问题是因为 Java JDK 17 目前支持 Gradle 8.x,而不是版本 18 到 20。
Gradle 用户指南暗示了不兼容性: https://docs.gradle.org/current/userguide/compatibility.html#java
我目前使用的是 Java 20,使用命名空间对AndroidManifest.xml和build.gradle进行主题化也没有解决我的问题,但是通过降级到 Gradle 7.4.2,我能够让 Flutter 和 Android Studio 进行构建。
所以我的建议是降级你的 Gradle 版本,或者降级你的 Java 版本。
小智 -6
不要在文件中使用命名空间build.gradle,而是使用applicationId如下所示的名称空间,
defaultConfig {
applicationId "com.myApp.example"
minSdkVersion 16
targetSdkVersion 30
versionCode 33
versionName "0.3.4"
Run Code Online (Sandbox Code Playgroud)
如果这对您不起作用,请创建一个新的项目设置并尝试使用新的项目设置构建您的应用程序。
file >> new project >> project folder path
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
30681 次 |
| 最近记录: |