android - 任务 ':app:transformClassesWithMultidexlistForDebug' 执行失败。在 flutter 中

标签 android ios dart flutter

使用插件image_picker_saver: ^0.1.0 plugin in flutter

出现这个错误: ` PS E:\PROJECTS\Flutter Projects\signature_view_new> flutter run 在 Debug模式下在 Nokia 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

主 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;
  }
}

签名.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'
}

最佳答案

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

关于android - 任务 ':app:transformClassesWithMultidexlistForDebug' 执行失败。在 flutter 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54784436/

相关文章:

android微调器下拉项目未显示

ios - 从 url 方案中获取文本字符串在 appdelegate 中有效,但在 viewcontroller 中无效

ios - swift 4 中的 SideMenu 功能

ios - 使用 NSNumberFormatter 将数字转换为格式

android-studio - 在 Android Studio 中使用 Flutter 时更改 Auto-Indent Lines 设置

android - 如何在 flutter 中设置滚动条颜色?

javascript - react native Android WebView : javaScriptEnabled does not seem to be working

java - 将 Action 添加到 Action Bar Android

java - 在同一个包中找不到类

dart - Flutter HTTP Post 返回 415