这是在 Android Studio 中尝试 AGP Upgrade Assistant 后显示的。
我在两个 build.gradle 中都没有缺少名称空间:
plugins {
// id "com.android.application"
// id "kotlin-android"
// // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
id 'com.android.application'
id 'com.google.gms.google-services'
id 'kotlin-android'
id 'com.google.firebase.crashlytics'
// Uncomment if using Firebase Performance Monitoring
// id 'com.google.firebase.firebase-perf'
id 'org.jetbrains.kotlin.android' version '2.0.0' apply false
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 flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('../../apps-keys/my_rents/key.properties')
println("Keystore properties file exists: ${keystorePropertiesFile.exists()}")
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
println("Keystore properties loaded: ${keystoreProperties}")
} else {
throw new GradleException("Keystore properties file not found: $keystorePropertiesFile")
}
android {
namespace = "com.drodriguez.my_rents"
compileSdk = flutter.compileSdkVersion
ndkVersion = flutter.ndkVersion
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId = "com.drodriguez.my_rents"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
minSdk = 23
targetSdk = flutter.targetSdkVersion
versionCode = flutterVersionCode.toInteger()
versionName = flutterVersionName
multiDexEnabled = true
}
signingConfigs {
release {
keyAlias = keystoreProperties['keyAlias']
keyPassword = keystoreProperties['keyPassword']
storeFile = keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword = keystoreProperties['storePassword']
}
debug {
keyAlias = keystoreProperties['keyAlias']
keyPassword = keystoreProperties['keyPassword']
storeFile = keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword = keystoreProperties['storePassword']
}
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig = signingConfigs.release
}
}
}
flutter {
source = "../.."
}
dependencies {
// https://firebase.google.com/docs/android/setup?hl=es
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.6.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
implementation 'com.android.billingclient:billing:7.0.0'
implementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'
implementation 'com.facebook.android:facebook-android-sdk:[8,9)'
implementation 'com.google.ads.mediation:facebook:6.17.0.0'
// Firebase performance
// implementation platform('com.google.firebase:firebase-bom:29.0.0')
implementation 'com.google.firebase:firebase-perf:21.0.1'
// implementation 'com.google.firebase:firebase-core' // deprecated
implementation 'com.google.firebase:firebase-analytics:22.0.2'
implementation 'com.google.firebase:firebase-auth:23.0.0'
implementation 'com.google.firebase:firebase-firestore:25.0.0'
implementation 'com.google.firebase:firebase-crashlytics:19.0.3'
implementation 'androidx.work:work-runtime-ktx:2.9.0'
}
或 AndroidManifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.drodriguez.my_rents">
复制此答案:https://stackoverflow.com/a/77625024/4858133
为了解决依赖项目中命名空间声明的问题,我在 android/build.gradle 中添加了以下 Gradle 脚本:
subprojects {
afterEvaluate { project ->
if (project.hasProperty('android')) {
project.android {
if (namespace == null) {
namespace project.group
}
}
}
}
}
它使用包名称并将其设置为命名空间(如果尚未在依赖项中指定)