【问题标题】:Execution failed for task ':app:transformClassesWithMultidexlistForDebug'. in flutter任务 ':app:transformClassesWithMultidexlistForDebug' 执行失败。飘飘然
【发布时间】:2019-07-14 00:43:51
【问题描述】:

在flutter中使用插件image_picker_saver:^0.1.0插件

收到此错误: ` PS E:\PROJECTS\Flutter Projects\signature_view_new> 颤振运行 在调试模式下在诺基亚 8 1 上启动 lib/main.dart... 正在初始化 gradle... 4.0s 解决依赖关系... 9.0s Gradle 任务 'assembleDebug'...

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.
> com.android.build.api.transform.TransformException: Error while generating the main dex list.

* 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 1m 13s
Gradle task 'assembleDebug'... Done                         75.5s
Gradle task assembleDebug failed with exit code 1`

pubspec.yaml:

name: signature_view_new
description: A new Flutter project.

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# Read more about versioning at semver.org.
version: 1.0.0+1

environment:
  sdk: ">=2.0.0-dev.68.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.2
  # package for saving the screenshot
  image_picker_saver: ^0.1.0
  # pacakge for toast-msg
  fluttertoast: ^3.0.0

dev_dependencies:
  flutter_test:
    sdk: flutter


# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

  # To add assets to your application, add an assets section, like this:
  # assets:
  #  - images/a_dot_burr.jpeg
  #  - images/a_dot_ham.jpeg

  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.io/assets-and-images/#resolution-aware.

  # For details regarding adding assets from package dependencies, see
  # https://flutter.io/assets-and-images/#from-packages

  # To add custom fonts to your application, add a fonts section here,
  # in this "flutter" section. Each entry in this list should have a
  # "family" key with the font family name, and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  # fonts:
  #   - family: Schyler
  #     fonts:
  #       - asset: fonts/Schyler-Regular.ttf
  #       - asset: fonts/Schyler-Italic.ttf
  #         style: italic
  #   - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts from package dependencies,
  # see https://flutter.io/custom-fonts/#from-packages

main.dart:

import 'dart:typed_data';
import 'dart:ui' as ui;
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:signature_view_new/signature.dart';
import 'package:image_picker_saver/image_picker_saver.dart';
import "package:fluttertoast/fluttertoast.dart";

void main() => runApp(MaterialApp(
      home: SignatureView(),
      debugShowCheckedModeBanner: false,
    ));

class SignatureView extends StatefulWidget {
  _SignatureViewState createState() => _SignatureViewState();
}

class _SignatureViewState extends State<SignatureView> {
  static GlobalKey previewContainer = new GlobalKey();
  List<Offset> _points = <Offset>[];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: RepaintBoundary(
        key: previewContainer,
        child: Container(
          width: double.infinity,
          color: Colors.white,
          child: GestureDetector(
            onPanUpdate: (DragUpdateDetails details) {
              setState(() {
                RenderBox object = context.findRenderObject();
                Offset _localPosition =
                    object.globalToLocal(details.globalPosition);
                _points = List.from(_points)..add(_localPosition);
              });
            },
            onPanEnd: (DragEndDetails details) => _points.add(null),
            child: CustomPaint(
              painter: Signature(points: _points),
              size: Size.infinite,
            ),
          ),
        ),
      ),
      floatingActionButton: Stack(
        children: <Widget>[
          Column(
            mainAxisAlignment: MainAxisAlignment.end,
            children: <Widget>[
              FloatingActionButton(
                child: Icon(Icons.screen_share),
                onPressed: _takeScreenShot,
              ),
              FloatingActionButton(
                child: Icon(Icons.clear),
                onPressed: () => _points.clear(),
              ),
            ],
          ),
        ],
      ),
    );
  }

  void _takeScreenShot() async {
    RenderRepaintBoundary boundary =
        previewContainer.currentContext.findRenderObject();
    ui.Image image = await boundary.toImage();
    ByteData byteData = await image.toByteData(format: ui.ImageByteFormat.png);
    Uint8List pngBytes = byteData.buffer.asUint8List();
    print(pngBytes);
    var filePath = await ImagePickerSaver.saveFile(fileData: pngBytes);
    toastMsg(filePath.toString());
    print(filePath);
  }

  toastMsg(String path) {
    var toast = Fluttertoast.showToast(
        msg: "Saved on $path",
        toastLength: Toast.LENGTH_SHORT,
        gravity: ToastGravity.BOTTOM,
        timeInSecForIos: 3,
        backgroundColor: Colors.red,
        textColor: Colors.white,
        fontSize: 16.0);

    print("inside toastMsg");
    return toast;
  }
}

signature.dart:

    import 'package:flutter/material.dart';

class Signature extends CustomPainter{
  List<Offset> points;

  Signature({this.points});

  @override
  void paint(Canvas canvas, Size size) {
    Paint paint = Paint()
      ..color = Colors.black
      ..strokeCap = StrokeCap.round
      ..strokeWidth = 10.0;

      for(int i = 0; i < points.length -1; i++){
        if(points[i] != null && points[i+1] != null){
          canvas.drawLine(points[i], points[i+1], paint);
        }
      }
  }

  @override
  bool shouldRepaint(Signature oldDelegate) => oldDelegate.points != points;
}

我尝试将项目迁移到 androidX 但收到此错误:

build.gradle(app 模块):

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 from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 28

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.signatureviewnew"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }

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

【问题讨论】:

  • 您迁移到 AndroidX 了吗?似乎该插件与 AndroidX 不兼容,这可能会导致错误。
  • 我尝试迁移到 andriodX 但出现错误
  • 它应该不是是必要的。我只是想知道你有没有。
  • 有什么解决办法?

标签: android ios dart flutter


【解决方案1】:

fluttertoast: ^3.0.0 需要 AndroidX
image_picker_saver: ^0.1.0 不兼容 AndroidX (https://github.com/cnhefang/image_picker_saver/issues/8)

现在我建议使用较旧的fluttertoast 版本

fluttertoast: ^2.0.0

https://github.com/cnhefang/image_picker_saver/issues/8 被修复更新并迁移到AndroidX

【讨论】:

  • 我在 pubspec.yaml 中更改了 fluttertoast: ^2.0.0,但出现此错误:D8: Program type already present: android.support.v4.os.ResultReceiver$MyResultReceiver
  • 试试flutter clean。我看到了这个错误,但我不知道如何解决。
【解决方案2】:

通过在 build.gradle(android module) 中添加以下代码为我解决了错误:

    subprojects {
    project.configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'com.android.support'
                    && !details.requested.name.contains('multidex') ) {
                details.useVersion "27.1.0"
            }
        }
    }
}

【讨论】:

    【解决方案3】:

    我刚刚运行了 Pakages 升级,然后为我运行了 flutter clean 这个工作。

    【讨论】:

      【解决方案4】:

      您需要将项目迁移到 Android X。您只能通过 Android Studio 3.3 执行此操作。

      Follow the procedures here to Migrate your Project to Android X

      【讨论】:

        【解决方案5】:

        对于使用 Firebase 的人,

        查看您的 Stacktrace 并查找导致崩溃的依赖项,对我来说是

        我刚刚删除了 Android 的以下依赖项,它解决了这个问题。

        implementation 'com.google.firebase:firebase-analytics:17.2.0'
        

        并且应用程序运行成功。

        【讨论】:

          【解决方案6】:

          这通常是由于您的包的旧依赖关系而发生的。跑步 flutter pub upgrade 然后像往常一样运行你的代码。

          【讨论】:

            猜你喜欢
            • 2021-09-12
            • 2020-12-09
            • 1970-01-01
            • 2018-06-10
            • 2019-11-02
            • 1970-01-01
            • 2020-07-06
            • 2020-11-29
            • 1970-01-01
            相关资源
            最近更新 更多