Flutter构建失败(Android转换活动失败)

huangapple go评论61阅读模式
英文:

Flutter Build Failing ( Android Transforming Activity failed)

问题

I see you have a complex error related to Gradle dependencies and transformation issues. To address this error, you can try the following steps:

  1. Check Gradle Version: Ensure that you are using a compatible version of Gradle for your project. You can update the Gradle version in the gradle-wrapper.properties file if needed.

  2. Update Flutter Packages: Make sure you have the latest versions of Flutter and your Flutter packages. Run the following commands in your project directory:

    flutter pub upgrade
    flutter clean
    flutter pub get
    
  3. Check SDK Versions: Verify that your Android SDK and Flutter SDK versions are compatible with your dependencies. Ensure that they match the versions specified in your pubspec.yaml file.

  4. Check Firebase Dependencies: Firebase dependencies can sometimes cause conflicts. Ensure that you have compatible versions of Firebase plugins by checking the official Firebase documentation for the latest versions.

  5. Check Android Gradle Plugin Version: Make sure you are using a compatible version of the Android Gradle plugin. You can update it in your project-level build.gradle file.

  6. Check Gradle Caches: Sometimes, Gradle cache corruption can lead to issues. Try deleting the .gradle directory in your project's root folder and the Gradle caches in your home directory (~/.gradle/caches) and then run your project again.

  7. Check for Duplicate Dependencies: Ensure that there are no duplicate dependencies or conflicting versions of libraries in your pubspec.yaml file.

  8. Jetifier: If you are migrating from an older AndroidX version, you may need to enable Jetifier to ensure compatibility. You can do this in your gradle.properties file by adding android.useAndroidX=true and android.enableJetifier=true.

After performing these steps, rebuild your project to see if the issue is resolved. If the problem persists, please provide more specific details about any error messages you encounter, and I'll try to assist further.

英文:

I am getting this build error. I have done gradle cache rebuild, flutter clean and pub get but still no progress. My application uses flutter_simple_Edge_detetion as available here. Since the author is not supporting the package further I am using dart version 2.10.5 and flutter version 3.7.1.

I know that this is a dependency issue as stated in this Stack Overflow question. However the answer is not very much descriptive and clear.
This is my error:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeDebugAssets'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Failed to transform activity-1.6.1.aar (androidx.activity:activity:1.6.1) to match attributes {artifactType=android-assets, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.libraryelements=aar, org.gradle.status=release, org.gradle.usage=java-runtime}.
      > Execution failed for JetifyTransform: C:\Users\Admin\.gradle\caches\modules-2\files-2.1\androidx.activity\activity.6.1139afb40f2e445f869f2a5f07eb056b1661a3c\activity-1.6.1.aar.
         > Failed to transform 'C:\Users\Admin\.gradle\caches\modules-2\files-2.1\androidx.activity\activity.6.1139afb40f2e445f869f2a5f07eb056b1661a3c\activity-1.6.1.aar' using Jetifier. Reason: null. (Run with --stacktrace for more details.)
   > Failed to transform activity-1.6.1.aar (androidx.activity:activity:1.6.1) to match attributes {artifactType=android-assets, org.gradle.status=release}.
      > Execution failed for JetifyTransform: C:\Users\Admin\.gradle\caches\modules-2\files-2.1\androidx.activity\activity.6.1139afb40f2e445f869f2a5f07eb056b1661a3c\activity-1.6.1.aar.
         > Failed to transform 'C:\Users\Admin\.gradle\caches\modules-2\files-2.1\androidx.activity\activity.6.1139afb40f2e445f869f2a5f07eb056b1661a3c\activity-1.6.1.aar' using Jetifier. Reason: null. (Run with --stacktrace for more details.)
   > Failed to transform annotation-experimental-1.3.0.aar (androidx.annotation:annotation-experimental:1.3.0) to match attributes {artifactType=android-assets, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.libraryelements=aar, org.gradle.status=release, org.gradle.usage=java-runtime}.
      > Execution failed for JetifyTransform: C:\Users\Admin\.gradle\caches\modules-2\files-2.1\androidx.annotation\annotation-experimental.3.087c6f545117dcd474e69e1a93cacec9d7334af\annotation-experimental-1.3.0.aar.
         > Failed to transform 'C:\Users\Admin\.gradle\caches\modules-2\files-2.1\androidx.annotation\annotation-experimental.3.087c6f545117dcd474e69e1a93cacec9d7334af\annotation-experimental-1.3.0.aar' using Jetifier. Reason: null. (Run with --stacktrace for more details.)

* 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 9s
Exception: Gradle task assembleDebug failed with exit code 1

Following is my pubspeck.yaml file:

name: temp
description: A new Flutter project.
publish_to: 'none'
version: 1.0.0+1

environment:
  sdk: ">=2.10.5 <3.0.0"
dependencies:
  flutter:
    sdk: flutter
  cupertino_icons: ^1.0.2
  camera: ^0.10.0+1
  path_provider: ^2.0.11
  image_picker: 0.8.7+4
  image_picker_android: 0.8.6+11
  permission_handler: ^10.0.0
  flutter_speed_dial: ^6.0.0
  mobile_scanner: ^2.0.0
  flutter_vibrate: ^1.3.0
  fluttertoast: ^8.0.9
  url_launcher: 6.1.6
  flutter_spinkit: ^5.1.0
  carousel_slider: ^4.1.1
  css_filter: ^1.0.2
  photofilters: ^3.0.1
  provider: ^6.0.4
  reorderable_grid: ^1.0.5
  pinch_zoom_release_unzoom: ^0.0.10
  overlay_loading_progress: ^1.0.0
  hidable: 1.0.3
  flutter_image_compress: ^1.1.3
  flutter_isolate: ^2.0.4
  wakelock: ^0.6.2
  draggable_scrollbar: ^0.1.0
  #  pdf: ^3.8.4
  share_extend: ^2.0.0
  alh_pdf_view: 1.2.0
  external_path: ^1.0.3
  search_page: ^2.2.0
  animated_icon: 0.0.4
  printing: 5.9.3
  firebase_core: 2.8.0
  firebase_auth: ^4.2.4
  firebase_storage: ^11.0.10
  firebase_storage_web: ^3.3.19
  cloud_firestore: ^4.3.1
  google_sign_in: ^5.4.2
  flutter_signin_button: ^2.0.0
  connectivity_plus: ^3.0.2
  animated_text_kit: ^4.2.2
  simple_animations: 1.3.3
  animate_gradient: ^0.0.2
  lottie: ^1.4.0
  ionicons: ^0.2.1
  cached_network_image: ^3.2.3
  sqflite: 2.2.3
  uuid: ^3.0.7
  intl: ^0.17.0
  path: ^1.8.2
  shared_preferences: 2.0.17
  pdfx: ^2.3.0
  animated_toggle_switch: ^0.6.1
  percent_indicator: ^4.2.2
  share_plus: ^4.5.3
  package_info: ^0.4.0+16
  firebase_remote_config: ^3.0.13
  font_awesome_flutter: ^9.2.0
  bulleted_list: ^0.0.1+0.1a
  google_nav_bar: ^5.0.6
  google_fonts: ^4.0.3
  animated_text: ^1.0.2
  video_player: ^2.6.0
  cloud_functions: ^4.0.13
  scratcher: ^2.3.0
  flutter_svg: ^1.1.6
  google_mobile_ads: ^2.4.0
  flutter_countdown_timer: ^4.1.0
  flutter_native_splash: ^2.2.16
  awesome_notifications: ^0.6.21
  simple_edge_detection:
    path: C:/Users/Admin/StudioProjects/flutter-simple-edge-detection

dev_dependencies:
  flutter_test:
    sdk: flutter

  flutter_lints: ^2.0.0

flutter:
  uses-material-design: true
  assets:
    - images/
    - assets/
    - assets/fonts/

Here is the project level build.gradle:

buildscript {
    ext.kotlin_version = '1.6.10'
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.4'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.15'
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Here is the app\build.gradle:

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'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    packagingOptions {
        pickFirst 'lib/x86/libc++_shared.so'
        pickFirst 'lib/x86_64/libc++_shared.so'
        pickFirst 'lib/armeabi-v7a/libc++_shared.so'
        pickFirst 'lib/arm64-v8a/libc++_shared.so'
    }

    compileSdkVersion localProperties.getProperty('flutter.compileSdkVersion').toInteger()
    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.example.temp"
        // You can update the following values to match your application needs.
        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
        minSdkVersion localProperties.getProperty('flutter.minSdkVersion').toInteger()
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        ndk {
            abiFilters 'arm-linux-androideabi'
        }
    }

    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 '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation platform('com.google.firebase:firebase-bom:31.1.1')
    implementation 'com.google.firebase:firebase-auth'
    implementation 'com.google.android.gms:play-services-auth:20.4.0'
    implementation 'com.google.firebase:firebase-analytics'
    implementation 'com.google.firebase:firebase-storage'
    implementation 'com.google.firebase:firebase-firestore'}

My gradle-wrapper.properties:

#Fri Jun 23 08:50:38 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip

I have tried cleaning gradle cache, updated my flutter version from 3.3.9 to 3.2.1 but can't seem to figure out how to solve this issue. Any more information required then please tell.

Any answer will be deeply appreciated🙏

答案1

得分: 0

错误是由于我的Flutter项目中的依赖关系引起的。具体来说,当我观察pubspec.lock文件时,发现了一个image_picker_android包。由于版本0.8.6+15,Flutter.dev团队将androidx.activity从1.6.1升级到了1.7.0,您可以在这里看到

总结一下,我降级了这个依赖项,并更改了一些其他依赖项的版本,现在错误已经消失了。

请注意,还有其他依赖项也会引发错误,但不是我在问题中发布的特定错误。祝编码愉快!

英文:

The error was due to my dependencies in my flutter project. Specifically, when I observed the pubspeck.lock file, then there was an image_picker_android package. Due to the version 0.8.6+15, the flutter.dev team had upgraded the androidx.activity from 1.6.1 to 1.7.0, as you can see here.

So to sum it up, I downgraded this dependency, and changed some other dependencies' versions and the error is gone now.

Note that there were other dependencies too which were causing an error but not the specific error which I posted in the question.
Happy coding!

huangapple
  • 本文由 发表于 2023年5月20日 22:50:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76295817.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定