任务':app:transformClassesWithMultidexlistForDebug'的执行失败。扑朔迷离

时间:2019-02-20 10:45:20

标签: android ios dart flutter

使用插件image_picker_saver:扑朔迷离的^ 0.1.0插件

得到此错误: PS E:\ PROJECTS \ Flutter项目\ 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,但收到此错误: enter image description here

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

6 个答案:

答案 0 :(得分:2)

这通常是由于软件包的旧依赖性而发生的。跑 flutter pub upgrade 然后像往常一样运行代码。

答案 1 :(得分:0)

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

答案 2 :(得分:0)

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

    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 :(得分:0)

我刚刚运行了Pakages升级,然后为我运行了Fluff Clean这项工作。

答案 4 :(得分:0)

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

Follow the procedures here to Migrate your Project to Android X

答案 5 :(得分:0)

对于使用Firebase的人,

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

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

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

,应用成功运行。

相关问题