Sri*_*h S 66 android android-studio ionic-framework
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)
升级到 Android Studio Flamingo 并提供 AGP Upgrade Assistant 从 7.4.2 到 8.0.0 后,我收到此错误。
这是一个 ionic 项目,因此命名空间已经在 build.gradle 文件中指定,如下所示,
构建.gradle
apply plugin: 'com.android.application'
android {
namespace 'com.example.m'
compileSdkVersion rootProject.ext.compileSdkVersion
defaultConfig {
applicationId "io.ionic.starter"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
aaptOptions {
// Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
// Default: https://android.googlesource.com/platform/frameworks/base/+/282e181b58cf72b6ca770dc7ca5f91f135444502/tools/aapt/AaptAssets.cpp#61
ignoreAssetsPattern '!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~'
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
flatDir{
dirs '../capacitor-cordova-android-plugins/src/main/libs', 'libs'
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
implementation "androidx.coordinatorlayout:coordinatorlayout:$androidxCoordinatorLayoutVersion"
implementation "androidx.core:core-splashscreen:$coreSplashScreenVersion"
implementation project(':capacitor-android')
testImplementation "junit:junit:$junitVersion"
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
implementation project(':capacitor-cordova-android-plugins')
}
apply from: 'capacitor.build.gradle'
try {
def servicesJSON = file('google-services.json')
if (servicesJSON.text) {
apply plugin: 'com.google.gms.google-services'
}
} catch(Exception e) {
logger.info("google-services.json not found, google-services plugin not applied. Push Notifications won't work")
}
Run Code Online (Sandbox Code Playgroud)
我尝试将命名空间添加到 AndroidManifest.xml 作为包名称,并作为 build.gradle 中的命名空间属性。仍然遇到同样的错误。
Ayk*_*dağ 42
Android Gradle 插件更新 >= 8.xx后会出现此错误要消除错误,请使用以下方法:
buildscript {
ext.kotlin_version = '1.8.22'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
mavenCentral()
}
// This code is where all the magic happens and fixes the error.
subprojects {
afterEvaluate { project ->
if (project.hasProperty('android')) {
project.android {
if (namespace == null) {
namespace project.group
}
}
}
}
}
// This code is where all the magic happens and fixes the error.
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
Run Code Online (Sandbox Code Playgroud)
问题出在哪里?
问题与命名空间有关。早期版本的 gradle,他们从 AndroidManifest.xml 中删除了命名空间并转移到 gradle 文件中。即使您的项目的命名空间转移到新系统,某些 flutter 插件也可能无法更新到最新的 gradle 版本。
解决方案
为了解决这个问题,我们将以下代码添加到顶级 gradle 文件中,以便通过 gradle 添加其子项目(插件)的命名空间。
subprojects {
afterEvaluate { project ->
if (project.hasProperty('android')) {
project.android {
if (namespace == null) {
namespace project.group
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
小智 15
这是一个已知的问题。
https://github.com/ionic-team/capacitor/issues/6504
如果您使用的是电容器 4,请勿升级到 gradle 8。
就我而言,我必须在 Android Studio 中打开每个电容器插件,然后检查每个电容器插件的“AndroidManifest.xml”,并使用“命名空间”将包名称复制到相关的“build.gradle”。
归档时间: |
|
查看次数: |
74073 次 |
最近记录: |