Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release version works but APK release doesnt work. #481

Closed
JayadevHaddadi opened this issue Nov 4, 2020 · 23 comments
Closed

Release version works but APK release doesnt work. #481

JayadevHaddadi opened this issue Nov 4, 2020 · 23 comments
Labels
new issue An issue that hasn't yet been seen from the maintainer

Comments

@JayadevHaddadi
Copy link

I'm using latest version of Flutter 1.22.3 and Android Studio 4.1. Flutter doctor has no issues.
Latest version of FilePicker 2.0.11.

When I run the app as debug or release version is fine.
But the APK release when installed crashes immediately. I can not get any reports even when I turn on debuggable for release.
Crash disappears as soon as I disable file_picker.

I appreciate any help.

@JayadevHaddadi JayadevHaddadi added the new issue An issue that hasn't yet been seen from the maintainer label Nov 4, 2020
@miguelpruivo
Copy link
Owner

@JayadevHaddadi try using adb logcat and check what's happening when it crashes.

@hamberluo
Copy link

Add following code to your proguard file.

-keep class androidx.lifecycle.** { *; }

@yoseptara
Copy link

Add following code to your proguard file.

-keep class androidx.lifecycle.** { *; }

where can i find this file sir?

@AleksMx
Copy link

AleksMx commented Nov 5, 2020

log cat:

2020-11-05 17:15:43.974 3764-11864/? E/flutter: [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: PlatformException(already_active, File picker is already active, null, null)
    #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:582)
    #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:159)
    <asynchronous suspension>
    #2      MethodChannel.invokeListMethod (package:flutter/src/services/platform_channel.dart:345)
    <asynchronous suspension>
    #3      FilePickerIO._getPath (package:file_picker/src/file_picker_io.dart:82)
    <asynchronous suspension>
    #4      Attachments.selectFiles (package:xxxx.dart:418)
    <asynchronous suspension>

@AleksMx
Copy link

AleksMx commented Nov 5, 2020

First of all check you Android Grudle version in the android/build.gradle file.

Find this line: classpath 'com.android.tools.build:gradle:X.X.X' - Gradle >= 4.0.0 plugin does not work correctly!

Change to:
classpath 'com.android.tools.build:gradle:3.5.3'

Information about Gradle 4.0.0:
flutter/flutter#58247

@hamberluo
Copy link

Add following code to your proguard file.

-keep class androidx.lifecycle.** { *; }

where can i find this file sir?

You can create proguard-app.pro and use proguardFiles 'proguard-app.pro'

@miguelpruivo
Copy link
Owner

@AleksMx have you managed to fix it?

@AleksMx
Copy link

AleksMx commented Nov 6, 2020

@AleksMx have you managed to fix it?

Yes. It is necessary to downgrade the Gradle plugin version to 3.

@miguelpruivo
Copy link
Owner

@JayadevHaddadi could you please try the suggested fix?

@JayadevHaddadi
Copy link
Author

Thanks for the prompt help.

I changed from 4.0.0 to:
classpath 'com.android.tools.build:gradle:3.5.3'
Then I get this error.

`FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':app:processAmpleReleaseResources'.

A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
Android resource linking failed
C:\Android\AndroidStudioProjects\ample\ample_student_app_flutter\build\file_picker\intermediates\library_manifest\release\AndroidManifest.xml:9:5-15:15: AAPT: error: unexpected element found in .

  • 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 2m 49s
The built failed likely due to AndroidX incompatibilities in a plugin. The tool is about to try using Jetfier to solve the incompatibility.
Building plugin catcher...
Running Gradle task 'assembleAarRelease'...

FAILURE: Build failed with an exception.

  • What went wrong:
    Could not determine the dependencies of task ':compileReleaseAidl'.

SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable or by setting the sdk.dir path in your project's local properties file at 'C:\Android\flutter.pub-cache\hosted\pub.dartlang.org\catcher-0.3.22\android\local.properties'.`

The second error I could remove by adding the local.properties file they ask for.

In AndroidManifest.xml we find:
<?xml version="1.0" encoding="UTF-8"?> <manifest package="com.mr.flutter.plugin.filepicker" xmlns:android="http://schemas.android.com/apk/res/android"> <uses-sdk android:minSdkVersion="16"/> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <queries> <intent> <action android:name="android.intent.action.GET_CONTENT"/> <data android:mimeType="*/*"/> </intent> </queries> </manifest>

:(

Thanks

@miguelpruivo
Copy link
Owner

@JayadevHaddadi could you try checking Android X migration guide and see if it works for you afterwards? Likely to be some incompatibility issue related with it.

@chris-profico
Copy link

The problem has been solved on my side.
By following the recommendations of @miguelpruivo, and I am very grateful to him.

What I have done:

  • I open my project's Android folder via AndroidStudio and run "Sync Project with Gradle Files"

Note: Under AndroidStudio 4.1 you have to open the Android folder of the project and not the project itself to see the “Sync Project with Gradle Files” tool appear (half an hour to find this)

  • AndroidStudio kindly offers to update Gradle, which I did (in my case, 3.5.0 to 4.1.0)

  • I select “Migrate to AndroidX” from Refactor menu… -> Do Refactor

  • I change the values of “compileSdkVersion” and “targetSdkVersion” to 29 in pubspec.yaml

Problem solved!

@JayadevHaddadi
Copy link
Author

I tried whatever @miguelpruivo said and also @chris-pro.
I update gradle to 4.1.
I open Android folder as project in AS, i synced etc.
I refactored to AndroidX.
I tried with SDK 30 and 29 also (I think you meant gradle file @chris-pro)
The app starts but gets stuck on the first screen as APK version. While the normal release/debug version works fine.
:(

@miguelpruivo
Copy link
Owner

@JayadevHaddadi could that be related with something else on your app? Since the app runs anyway.

@AleksMx
Copy link

AleksMx commented Nov 10, 2020

I tried whatever @miguelpruivo said and also @chris-pro.
I update gradle to 4.1.
I open Android folder as project in AS, i synced etc.
I refactored to AndroidX.
I tried with SDK 30 and 29 also (I think you meant gradle file @chris-pro)
The app starts but gets stuck on the first screen as APK version. While the normal release/debug version works fine.
:(

The easiest is to re-create an empty flutter project. Then copy the lib folder into it from you old project. What you do can lead to undefined behavior.

@chris-profico
Copy link

Small correction on my previous post.

My application was working fine in debug mode on the emulator but there were some complications when I wanted to do an app-release.

The issue was related to Gradle version 4 as reported by @AleksMx.
So I downgraded Gradle to version 3.6.3
Now the application now works correctly in debug and release mode.

To summarize the changes that fixed the problem:

Before

android/app/build.gradle

compileSdkVersion 28
targetSdkVersion 28

android/build.gradle

classpath 'com.android.tools.build:gradle:3.5.0'

android/gradle/wrapper/gradle-wrapper.properties

distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip

After

android/app/build.gradle

compileSdkVersion 29
targetSdkVersion 29

android/build.gradle

classpath 'com.android.tools.build:gradle:3.6.3'

android/gradle/wrapper/gradle-wrapper.properties

distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip

@JayadevHaddadi
Copy link
Author

@chris-pro
This finally worked!:))
So happy. Thanks.
I updated those values exactly as prescribed and it worked...
Thanks:)
Thank you @miguelpruivo and @AleksMx

@miguelpruivo
Copy link
Owner

Thank you for your clear explanation @chris-pro! 👌

Closing as it is now resolved.

@SerkanColak
Copy link

Small correction on my previous post.

My application was working fine in debug mode on the emulator but there were some complications when I wanted to do an app-release.

The issue was related to Gradle version 4 as reported by @AleksMx.
So I downgraded Gradle to version 3.6.3
Now the application now works correctly in debug and release mode.

To summarize the changes that fixed the problem:

Before

android/app/build.gradle

compileSdkVersion 28
targetSdkVersion 28

android/build.gradle

classpath 'com.android.tools.build:gradle:3.5.0'

android/gradle/wrapper/gradle-wrapper.properties

distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip

After

android/app/build.gradle

compileSdkVersion 29
targetSdkVersion 29

android/build.gradle

classpath 'com.android.tools.build:gradle:3.6.3'

android/gradle/wrapper/gradle-wrapper.properties

distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip

Works like a charm! Thanks))

@pierre-gancel
Copy link

Sorry but this does not work for me, I followed proguard and gradle advices, yet it crashes when users picks pdf on release mode.
Strangely enough it goes well on debug.

@pierre-gancel
Copy link

pierre-gancel commented Mar 11, 2021

Here is a snippet

FilePickerResult result = await FilePicker.platform.pickFiles(
          allowMultiple: false,
          type: FileType.custom,
          allowedExtensions: ['pdf']);
      if (result != null) {
        File file = File(result.files.single.path);
        //print("nikfilename${file.path.substring(file.path.lastIndexOf("/"))}");
        setState(() => pickedPdfFile = file);
      }

@pierre-gancel
Copy link

here is Flutter Doctor

[✓] Flutter (Channel stable, 1.22.6, on Mac OS X 10.15.7 19H114 darwin-x64, locale en-GB)

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 12.4)
[!] Android Studio (version 4.1)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] VS Code (version 1.54.1)
[✓] Connected device (1 available)

! Doctor found issues in 1 category.
pierre@PierressurlyMBP assurly % flutter doctor -v
[✓] Flutter (Channel stable, 1.22.6, on Mac OS X 10.15.7 19H114 darwin-x64, locale en-GB)
• Flutter version 1.22.6 at /Users/pierre/flutter
• Framework revision 9b2d32b605 (7 weeks ago), 2021-01-22 14:36:39 -0800
• Engine revision 2f0af37152
• Dart version 2.10.5

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
• Android SDK at /Users/pierre/Library/Android/sdk
• Platform android-30, build-tools 30.0.2
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
• All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 12.4)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 12.4, Build version 12D4e
• CocoaPods version 1.10.0

[!] Android Studio (version 4.1)
• Android Studio at /Applications/Android Studio.app/Contents
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)

[✓] VS Code (version 1.54.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.20.0

[✓] Connected device (1 available)
• SM G920F (mobile) • 0815f8aac13f2d04 • android-arm64 • Android 7.0 (API 24)

@emadaljumaily
Copy link

PickedFile work on debug mode but not work on release mode

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel master, 2.6.0-12.0.pre.564, on Microsoft Windows [Version 10.0.19042.1165], locale en-GB)
[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[√] Chrome - develop for the web
[√] Android Studio (version 4.1)
[√] VS Code (version 1.62.3)
[√] Connected device (3 available)

• No issues found!

classpath 'com.android.tools.build:gradle:3.5.3'

compileSdkVersion 31
minSdkVersion 21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new issue An issue that hasn't yet been seen from the maintainer
Projects
None yet
Development

No branches or pull requests

9 participants