简体   繁体   中英

The app crashes when opening image_cropper in release mode

My app keeps crashing when I try to open image cropper in release mode.

I added everything in the manifest as directed in the documentation :

<activity
       android:name="com.yalantis.ucrop.UCropActivity"
       android:screenOrientation="portrait"
       android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>

How I use it:

Future<void> _cropImage(File imageFile, int index) async {
if(imageFile != null){
  File cropped = await ImageCropper.cropImage(
      sourcePath: imageFile.path,
      aspectRatio: CropAspectRatio(ratioX: 1.0, ratioY: 1.0),
      compressQuality: 100,
      maxHeight: height,
      maxWidth: width,
      androidUiSettings: AndroidUiSettings(
        toolbarTitle: "",
        toolbarWidgetColor: Colors.black.withOpacity(0.6),
        statusBarColor: Colors.black,
        activeControlsWidgetColor: Colors.white,
      )
  );

  setState(() {
    compress(cropped, index);
  });
}}

As soon as I start the app in release mode, the following error message appears:

E/AndroidRuntime(13412): FATAL EXCEPTION: main

E/AndroidRuntime(13412): Process: com.packages.xxx, PID: 13412

E/AndroidRuntime(13412): java.lang.NoSuchMethodError: No static method 
asAttributeSet(Li/a/a/a;)Landroid/util/AttributeSet; in class Landroid/util/Xml; or its super classes (declaration of 'android.util.Xml' appears in /system/framework/framework.jar!classes3.dex)

E/AndroidRuntime(13412):        at a.a.n.g.inflate(Unknown Source:21)

E/AndroidRuntime(13412):        at com.yalantis.ucrop.UCropActivity.onCreateOptionsMenu(Unknown Source:6)

E/AndroidRuntime(13412):        at android.app.Activity.onCreatePanelMenu(Activity.java:4212)

E/AndroidRuntime(13412):        at androidx.fragment.app.d.onCreatePanelMenu(Unknown Source:2)

E/AndroidRuntime(13412):        at a.a.n.i.onCreatePanelMenu(Unknown Source:2)

E/AndroidRuntime(13412):        at androidx.appcompat.app.g$j.onCreatePanelMenu(Unknown Source:8)

E/AndroidRuntime(13412):        at a.a.n.i.onCreatePanelMenu(Unknown Source:2)

E/AndroidRuntime(13412):        at androidx.appcompat.app.j.m(Unknown Source:25)

E/AndroidRuntime(13412):        at androidx.appcompat.app.j$a.run(Unknown Source:2)

E/AndroidRuntime(13412):        at android.os.Handler.handleCallback(Handler.java:938)

E/AndroidRuntime(13412):        at android.os.Handler.dispatchMessage(Handler.java:99)

E/AndroidRuntime(13412):        at android.os.Looper.loop(Looper.java:233)

E/AndroidRuntime(13412):        at android.app.ActivityThread.main(ActivityThread.java:7959)

E/AndroidRuntime(13412):        at java.lang.reflect.Method.invoke(Native Method)

E/AndroidRuntime(13412):        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:631)

E/AndroidRuntime(13412):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:978)

How can I fix this?. Thanks.

We will go through multiple solutions try them and tell me which one is your problem

1- in your build.gradle(Module: app) you will find this section remove it

if (details.requested.group == 'com.android.support'
&& !details.requested.name.contains('multidex') ) {
details.useVersion "27.1.1"
}
if (details.requested.group == 'androidx.core'
&& !details.requested.name.contains('androidx') ) {
details.useVersion "1.0.1"
}
if (requested.group == "androidx") {
if (!requested.name.startsWith("multidex")) {
details.useVersion "${targetSdk}.+"
}

2- Try adding the needed permissions to your manifest

<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

3- Try changing the gradle version into something like

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

package/android/app/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 plugin: 'com.google.gms.google-services'
    apply plugin: 'kotlin-android'
    apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
    
    def keystoreProperties = new Properties()
    def keystorePropertiesFile = rootProject.file('key.properties')
    if (keystorePropertiesFile.exists()) {
        keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
    }

android {
    compileSdkVersion 30

sourceSets {
    main.java.srcDirs += 'src/main/kotlin'
}

de

faultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.packages.xxx"
        minSdkVersion 24
        targetSdkVersion 30
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        multiDexEnabled true
    }

    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
            storePassword keystoreProperties['storePassword']
        }
    }

    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 {
        implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
        implementation platform('com.google.firebase:firebase-bom:27.1.0')
        implementation 'com.google.firebase:firebase-analytics'
        implementation 'com.android.support:multidex:1.0.3'
    }

I was facing the same issue and below code, changes fixed it:

Add 'release' block inside the android in app/build.gradle file like give below

buildTypes {
        release {
            useProguard true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.debug
        }
    }

Create if not, 'app/proguard-rules.pro' file and add the following lines:

-dontwarn com.yalantis.ucrop**
-keep class com.yalantis.ucrop** { *; }
-keep interface com.yalantis.ucrop** { *; }
-keep class androidx.appcompat.** { *; }

After this release mode worked for me.

I had the same issue and it was because I only added the UCropActivity text into the AndroidManifest.xml within the Debug folder. It needed to be added to the AndroidManifest.xml within the Main folder as well for release to work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM