简体   繁体   English

在发布模式下打开 image_cropper 时应用程序崩溃

[英]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 :我按照文档中的指示在manifest中添加了所有内容:

<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我们将通过多种解决方案尝试 go 并告诉我哪一个是您的问题

1- in your build.gradle(Module: app) you will find this section remove it 1- 在你的build.gradle(Module: app)你会发现这部分删除它

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 2-尝试将所需的权限添加到您的清单

<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 3-尝试将 gradle 版本更改为类似

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

package/android/app/build.gradle包/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在 app/build.gradle 文件的 android 中添加“发布”块,如下所示

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:如果没有,则创建“app/proguard-rules.pro”文件并添加以下行:

-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.我遇到了同样的问题,这是因为我只将 UCropActivity 文本添加到了 Debug 文件夹中的 AndroidManifest.xml 中。 It needed to be added to the AndroidManifest.xml within the Main folder as well for release to work.还需要将其添加到主文件夹中的 AndroidManifest.xml 中才能发布。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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