我第一次在Android Studio上使用Flutter,安装后我一直收到这个错误,我的Gradle文件版本是4.1.0
Running Gradle task 'assembleDebug'...
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Users\ahmed\flutter12\android\app\build.gradle' line: 24
* What went wrong:
A problem occurred evaluating project ':app'.
> Failed to apply plugin 'com.android.internal.application'.
> Could not create plugin of type 'AppPlugin'.
> Could not generate a decorated class for type AppPlugin.
> com/google/wireless/android/sdk/stats/GradleBuildProject$PluginType
* 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
BUILD FAILED in 5s
Exception: Gradle task assembleDebug failed with exit code 1
Android版本是4.0.1
这是我的build.gradle文件我不知道出了什么问题我更新了我的jdk sdk和android studio到最后的版本4. 1. 2
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 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'
}
apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 30
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.flutterwq"
minSdkVersion 16
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
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.debug
}
}
}
flutter {
source '../..'
}
3条答案
按热度按时间3j86kqsm1#
打开android/build.gradle文件,检查com.android.tools.build:gradle的版本:
让这个版本更小,直到某个版本工作。版本可以从这里选择,在插件列:https://developer.android.com/studio/releases/gradle-plugin#updating-gradle
当gradle太旧而android gradle插件太新时会出现问题。
6ljaweal2#
试试这些步骤。打开Gradle Scripts/gradle-wrapper.properties文件。
将现有版本替换为“6.7-all.zip”:
然后在build.gradle文件中,首先将classpath中的版本替换为4.1.0,然后将'jcenter()'替换为'mavenCentral()':
pbpqsu0x3#