flutter gradle 构建失败 gradle 4.2.2 和 sdk 版本 31
flutter gradle build failed with gradle 4.2.2 and sdk version 31
我在构建 flutter 移动应用程序时遇到以下错误:
* What went wrong:
Execution failed for task ':location_permissions:parseReleaseLocalResources'.
> Could not resolve all files for configuration ':location_permissions:androidApis'.
> Failed to transform android.jar to match attributes {artifactType=android-platform-attr, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}.
> Execution failed for PlatformAttrTransform: C:\Users\zukijuki\AppData\Local\Android\sdk\platforms\android-29\android.jar.
> C:\Users\zukijuki\AppData\Local\Android\sdk\platforms\android-29\android.jar
我的 android/build.gradle
配置文件:
buildscript {
repositories {
google()
mavenCentral()
maven {
url 'https://maven.fabric.io/public'
}
maven {
url 'https://plugins.gradle.org/m2/'
}
maven {
url 'https://maven.google.com'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.2'
classpath 'com.google.gms:google-services:4.3.3'
classpath 'io.fabric.tools:gradle:1.28.1'
}
}
及以下app/build.gradle
:
...
android {
compileSdkVersion 31
buildToolsVersion '28.0.3'
lintOptions {
//disable 'InvalidPackage'
}
defaultConfig {
applicationId "com.example"
minSdkVersion 22
multiDexEnabled true
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
resConfigs "en", "US"
}
...
}
flutter {
source '../..'
}
dependencies {
implementation("com.google.android.gms:play-services-base:17.0.0"){ force = true }
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.android.gms:play-services-location:16.0.0'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.facebook.android:facebook-android-sdk:[5,6)'
}
configurations {
all*.exclude group: 'com.google.guava', module: 'listenablefuture'
}
apply plugin: 'com.google.gms.google-services'
apply plugin: 'io.fabric'
有解决上述问题的办法吗?
提前致谢...
===更新
- gradle.properties
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
android.enableR8=true
使用Android Studio Bumblebee | 2021.1.1 Patch 3
构建
重新安装API级别29,30,31,32还是无法解决
android 的一些配置文件似乎丢失了。
尝试重新安装 Android SDK。
为此,您需要从 SDK Manager 卸载然后重新安装。
通过以下方式查找:单击“工具”>“SDK 管理器”。
我终于通过将 Gradle 版本降级到 4.1.0
解决了这个问题
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
...
}
我在构建 flutter 移动应用程序时遇到以下错误:
* What went wrong:
Execution failed for task ':location_permissions:parseReleaseLocalResources'.
> Could not resolve all files for configuration ':location_permissions:androidApis'.
> Failed to transform android.jar to match attributes {artifactType=android-platform-attr, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}.
> Execution failed for PlatformAttrTransform: C:\Users\zukijuki\AppData\Local\Android\sdk\platforms\android-29\android.jar.
> C:\Users\zukijuki\AppData\Local\Android\sdk\platforms\android-29\android.jar
我的 android/build.gradle
配置文件:
buildscript {
repositories {
google()
mavenCentral()
maven {
url 'https://maven.fabric.io/public'
}
maven {
url 'https://plugins.gradle.org/m2/'
}
maven {
url 'https://maven.google.com'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.2'
classpath 'com.google.gms:google-services:4.3.3'
classpath 'io.fabric.tools:gradle:1.28.1'
}
}
及以下app/build.gradle
:
...
android {
compileSdkVersion 31
buildToolsVersion '28.0.3'
lintOptions {
//disable 'InvalidPackage'
}
defaultConfig {
applicationId "com.example"
minSdkVersion 22
multiDexEnabled true
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
resConfigs "en", "US"
}
...
}
flutter {
source '../..'
}
dependencies {
implementation("com.google.android.gms:play-services-base:17.0.0"){ force = true }
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.android.gms:play-services-location:16.0.0'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.facebook.android:facebook-android-sdk:[5,6)'
}
configurations {
all*.exclude group: 'com.google.guava', module: 'listenablefuture'
}
apply plugin: 'com.google.gms.google-services'
apply plugin: 'io.fabric'
有解决上述问题的办法吗?
提前致谢...
===更新
- gradle.properties
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
android.enableR8=true
使用
构建Android Studio Bumblebee | 2021.1.1 Patch 3
重新安装API级别29,30,31,32还是无法解决
android 的一些配置文件似乎丢失了。
尝试重新安装 Android SDK。
为此,您需要从 SDK Manager 卸载然后重新安装。
通过以下方式查找:单击“工具”>“SDK 管理器”。
我终于通过将 Gradle 版本降级到 4.1.0
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
...
}