gradle Android获取未指定空间错误,当我尝试升级项目的Gralde版本时

67up9zun  于 2023-10-19  发布在  Android
关注(0)|答案(1)|浏览(159)

当我想将Android项目升级到更高的Gradle版本时,我在编译期间收到此错误:

Namespace not specified. Please specify a namespace in the module's build.gradle file like so:

android {
    namespace 'com.example.namespace'
}

我的困惑是,build.gradle文件中的命名空间已经定义,升级到更高版本时会出现此错误。
build.gradle文件的内容:

<manifest xmlns:android="http://schemas.android.com/apk/res/android">

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:name="${applicationName}"
        android:icon="@mipmap/launcher_icon"
        android:label="xxxxxx">
        <activity
            ...
            
        </activity>
        
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
</manifest>

build.gradle

...
android {
    namespace "mysite.com.myproject"
    compileSdkVersion flutter.compileSdkVersion
    ndkVersion flutter.ndkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_11
        targetCompatibility JavaVersion.VERSION_11
    }

    ...
    defaultConfig {
        applicationId "mysite.com.myproject"
        minSdkVersion 21
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    buildTypes {
        release {
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

为buildscript定义的部分:

buildscript {
    ext.kotlin_version = '1.9.0'
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:8.0.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

最后是distributionUrl部分:

distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-all.zip
goqiplq2

goqiplq21#

打开android -> app -> src -> main -> AndroidManifest.xml.
取代

<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="mysite.com.myproject">

相关问题