我正在尝试为我的 flutter 项目构建 APK,但遇到大量 Gradle 错误。这里的类似问题没有任何有效的答案。这是构建命令的输出:
One or more plugins require a higher Android NDK version.
Fix this issue by adding the following to /Users/jacobmiller/Local Documents/Development/app/android/app/build.gradle:
android {
ndkVersion "25.1.8937393"
...
}
Font asset "MaterialIcons-Regular.otf" was tree-shaken, reducing it from 1645184 to 3056 bytes (99.8% reduction). Tree-shaking can be disabled by providing the --no-tree-shake-icons flag when building your app.
Incorrect package="io.flutter.plugins.firebase.core" found in source AndroidManifest.xml: /Users/jacobmiller/.pub-cache/hosted/pub.dev/firebase_core-2.25.4/android/src/main/AndroidManifest.xml.
Setting the namespace via the package attribute in the source AndroidManifest.xml is no longer supported.
Recommendation: remove package="io.flutter.plugins.firebase.core" from the source AndroidManifest.xml: /Users/jacobmiller/.pub-cache/hosted/pub.dev/firebase_core-2.25.4/android/src/main/AndroidManifest.xml.
Incorrect package="io.flutter.plugins.firebase.messaging" found in source AndroidManifest.xml: /Users/jacobmiller/.pub-cache/hosted/pub.dev/firebase_messaging-14.7.15/android/src/main/AndroidManifest.xml.
Setting the namespace via the package attribute in the source AndroidManifest.xml is no longer supported.
Recommendation: remove package="io.flutter.plugins.firebase.messaging" from the source AndroidManifest.xml: /Users/jacobmiller/.pub-cache/hosted/pub.dev/firebase_messaging-14.7.15/android/src/main/AndroidManifest.xml.
Incorrect package="com.hui.bluetooth_enable" found in source AndroidManifest.xml: /Users/jacobmiller/.pub-cache/hosted/pub.dev/bluetooth_enable_fork-0.1.6/android/src/main/AndroidManifest.xml.
Setting the namespace via the package attribute in the source AndroidManifest.xml is no longer supported.
Recommendation: remove package="com.hui.bluetooth_enable" from the source AndroidManifest.xml: /Users/jacobmiller/.pub-cache/hosted/pub.dev/bluetooth_enable_fork-0.1.6/android/src/main/AndroidManifest.xml.
Incorrect package="com.mr.flutter.plugin.filepicker" found in source AndroidManifest.xml: /Users/jacobmiller/.pub-cache/hosted/pub.dev/file_picker-6.1.1/android/src/main/AndroidManifest.xml.
Setting the namespace via the package attribute in the source AndroidManifest.xml is no longer supported.
Recommendation: remove package="com.mr.flutter.plugin.filepicker" from the source AndroidManifest.xml: /Users/jacobmiller/.pub-cache/hosted/pub.dev/file_picker-6.1.1/android/src/main/AndroidManifest.xml.
FAILURE: Build completed with 4 failures.
1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':bluetooth_enable_fork:processReleaseManifest'.
> A failure occurred while executing com.android.build.gradle.tasks.ProcessLibraryManifest$ProcessLibWorkAction
> Incorrect package="com.hui.bluetooth_enable" found in source AndroidManifest.xml: /Users/jacobmiller/.pub-cache/hosted/pub.dev/bluetooth_enable_fork-0.1.6/android/src/main/AndroidManifest.xml.
Setting the namespace via the package attribute in the source AndroidManifest.xml is no longer supported.
Recommendation: remove package="com.hui.bluetooth_enable" from the source AndroidManifest.xml: /Users/jacobmiller/.pub-cache/hosted/pub.dev/bluetooth_enable_fork-0.1.6/android/src/main/AndroidManifest.xml.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
==============================================================================
2: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':firebase_messaging:processReleaseManifest'.
> A failure occurred while executing com.android.build.gradle.tasks.ProcessLibraryManifest$ProcessLibWorkAction
> Incorrect package="io.flutter.plugins.firebase.messaging" found in source AndroidManifest.xml: /Users/jacobmiller/.pub-cache/hosted/pub.dev/firebase_messaging-14.7.15/android/src/main/AndroidManifest.xml.
Setting the namespace via the package attribute in the source AndroidManifest.xml is no longer supported.
Recommendation: remove package="io.flutter.plugins.firebase.messaging" from the source AndroidManifest.xml: /Users/jacobmiller/.pub-cache/hosted/pub.dev/firebase_messaging-14.7.15/android/src/main/AndroidManifest.xml.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
==============================================================================
3: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':file_picker:processReleaseManifest'.
> A failure occurred while executing com.android.build.gradle.tasks.ProcessLibraryManifest$ProcessLibWorkAction
> Incorrect package="com.mr.flutter.plugin.filepicker" found in source AndroidManifest.xml: /Users/jacobmiller/.pub-cache/hosted/pub.dev/file_picker-6.1.1/android/src/main/AndroidManifest.xml.
Setting the namespace via the package attribute in the source AndroidManifest.xml is no longer supported.
Recommendation: remove package="com.mr.flutter.plugin.filepicker" from the source AndroidManifest.xml: /Users/jacobmiller/.pub-cache/hosted/pub.dev/file_picker-6.1.1/android/src/main/AndroidManifest.xml.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
==============================================================================
4: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':firebase_core:processReleaseManifest'.
> A failure occurred while executing com.android.build.gradle.tasks.ProcessLibraryManifest$ProcessLibWorkAction
> Incorrect package="io.flutter.plugins.firebase.core" found in source AndroidManifest.xml: /Users/jacobmiller/.pub-cache/hosted/pub.dev/firebase_core-2.25.4/android/src/main/AndroidManifest.xml.
Setting the namespace via the package attribute in the source AndroidManifest.xml is no longer supported.
Recommendation: remove package="io.flutter.plugins.firebase.core" from the source AndroidManifest.xml: /Users/jacobmiller/.pub-cache/hosted/pub.dev/firebase_core-2.25.4/android/src/main/AndroidManifest.xml.
这是我的settings.gradle:
pluginManagement {
def flutterSdkPath = {
def properties = new Properties()
file("local.properties").withInputStream { properties.load(it) }
def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
return flutterSdkPath
}
settings.ext.flutterSdkPath = flutterSdkPath()
includeBuild("${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle")
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}
plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version '8.2.0' apply false
id "org.jetbrains.kotlin.android" version "1.9.22" apply false
}
include ":app"
构建.gradle:
allprojects {
repositories {
google()
mavenCentral()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
afterEvaluate {
android {
namespace 'add your namespace here'
}
}
project.evaluationDependsOn(':app')
}
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
应用程序/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'
}
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
namespace "com.jacobmiller.app"
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 {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.jacobmiller.app"
// 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.
minSdkVersion 21
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
signingConfigs {
release {
if (System.getenv("ANDROID_KEYSTORE_PATH")) {
storeFile file(System.getenv("ANDROID_KEYSTORE_PATH"))
keyAlias System.getenv("ANDROID_KEYSTORE_ALIAS")
keyPassword System.getenv("ANDROID_KEYSTORE_PRIVATE_KEY_PASSWORD")
storePassword System.getenv("ANDROID_KEYSTORE_PASSWORD")
} else if (keystoreProperties != null) {
// Make sure to define these properties in your local.properties file or set them as environment variables
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
}
buildTypes {
release {
signingConfig signingConfigs.release
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
flutter {
source '../..'
}
dependencies {}
有什么解决办法吗?我现在也遇到同样的错误,我很沮丧。我的 IOS 应用程序工作正常,但我的 Android 应用程序出现问题。