Reputation: 415
Using the plugin image_picker_saver: ^0.1.0 plugin in flutter
getting this error: ` PS E:\PROJECTS\Flutter Projects\signature_view_new> flutter run Launching lib/main.dart on Nokia 8 1 in debug mode... Initializing gradle... 4.0s Resolving dependencies... 9.0s Gradle task '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;
}
I tried migrating the project to androidX but getting this error:
build.gradle(app module):
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'
}
Upvotes: 1
Views: 11777
Reputation: 583
This is generally happening due to the old dependencies of your packages. Run
flutter pub upgrade
then run your code as usual you do.
Upvotes: 1
Reputation: 6049
For people working with Firebase,
Go through your Stacktrace and look for the dependency that is causing the crash, for me it was
I just removed the following dependency for Android and it fixes the issue.
implementation 'com.google.firebase:firebase-analytics:17.2.0'
and the App Ran Successfully.
Upvotes: 0
Reputation: 13247
You need to migrate the project to Android X. You can only do this through Android studio 3.3.
Follow the procedures here to Migrate your Project to Android X
Upvotes: 0
Reputation: 5793
I have just run Pakages upgrade and then run flutter clean this work for me.
Upvotes: 0
Reputation: 415
By adding the following code in build.gradle(android module) solved the error for me in :
subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.android.support'
&& !details.requested.name.contains('multidex') ) {
details.useVersion "27.1.0"
}
}
}
}
Upvotes: 1
Reputation: 657871
fluttertoast: ^3.0.0
requires AndroidX
image_picker_saver: ^0.1.0
is not compatible with AndroidX (https://github.com/cnhefang/image_picker_saver/issues/8)
For now I'd suggest to use an older fluttertoast
version
fluttertoast: ^2.0.0
and when https://github.com/cnhefang/image_picker_saver/issues/8 is fixed to update and migrate to AndroidX
Upvotes: 1