Android App Build Fails After Installing flutter_secure_storage
Closed this issue · 1 comments
Hello,
I'm having an issue with the flutter_secure_storage package. After installing it, I'm unable to build my Android app. The build process fails with a message indicating that my app has exceeded the 64K method limit and requires Multidex support.
Here's the error message I'm seeing:
Launching lib/main.dart on sdk gphone64 arm64 in debug mode...
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
ERROR:D8: Cannot fit requested classes in a single dex file (# methods: 74755 > 65536)
com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
The number of method references in a .dex file cannot exceed 64K.
Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html
at com.android.builder.dexing.D8DexArchiveMerger.getExceptionToRethrow(D8DexArchiveMerger.java:151)
at com.android.builder.dexing.D8DexArchiveMerger.mergeDexArchives(D8DexArchiveMerger.java:138)
at com.android.build.gradle.internal.tasks.DexMergingWorkAction.merge(DexMergingTask.kt:859)
at com.android.build.gradle.internal.tasks.DexMergingWorkAction.run(DexMergingTask.kt:805)
at com.android.build.gradle.internal.profile.ProfileAwareWorkAction.execute(ProfileAwareWorkAction.kt:74)
at org.gradle.workers.internal.DefaultWorkerServer.execute(DefaultWorkerServer.java:63)
at org.gradle.workers.internal.NoIsolationWorkerFactory$1$1.create(NoIsolationWorkerFactory.java:66)
at org.gradle.workers.internal.NoIsolationWorkerFactory$1$1.create(NoIsolationWorkerFactory.java:62)
at org.gradle.internal.classloader.ClassLoaderUtils.executeInClassloader(ClassLoaderUtils.java:100)
at org.gradle.workers.internal.NoIsolationWorkerFactory$1.lambda$execute$0(NoIsolationWorkerFactory.java:62)
at org.gradle.workers.internal.AbstractWorker$1.call(AbstractWorker.java:44)
at org.gradle.workers.internal.AbstractWorker$1.call(AbstractWorker.java:41)
at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:204)
at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:199)
at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157)
at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:53)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:73)
at org.gradle.workers.internal.AbstractWorker.executeWrappedInBuildOperation(AbstractWorker.java:41)
at org.gradle.workers.internal.NoIsolationWorkerFactory$1.execute(NoIsolationWorkerFactory.java:59)
at org.gradle.workers.internal.DefaultWorkerExecutor.lambda$submitWork$2(DefaultWorkerExecutor.java:212)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.runExecution(DefaultConditionalExecutionQueue.java:187)
at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.access$700(DefaultConditionalExecutionQueue.java:120)
at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner$1.run(DefaultConditionalExecutionQueue.java:162)
at org.gradle.internal.Factories$1.create(Factories.java:31)
at org.gradle.internal.work.DefaultWorkerLeaseService.withLocks(DefaultWorkerLeaseService.java:249)
at org.gradle.internal.work.DefaultWorkerLeaseService.runAsWorkerThread(DefaultWorkerLeaseService.java:109)
at org.gradle.internal.work.DefaultWorkerLeaseService.runAsWorkerThread(DefaultWorkerLeaseService.java:114)
at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.runBatch(DefaultConditionalExecutionQueue.java:157)
at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.run(DefaultConditionalExecutionQueue.java:126)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:49)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, position: null
at Version.fakeStackEntry(Version_3.3.70.java:0)
at com.android.tools.r8.internal.Fj.a(R8_3.3.70_49b71801b8b3de79ea68cec3bf950786c8f90f7a560cea4a2d23a82079b17d04:75)
at com.android.tools.r8.internal.Fj.a(R8_3.3.70_49b71801b8b3de79ea68cec3bf950786c8f90f7a560cea4a2d23a82079b17d04:28)
at com.android.tools.r8.internal.Fj.a(R8_3.3.70_49b71801b8b3de79ea68cec3bf950786c8f90f7a560cea4a2d23a82079b17d04:27)
at com.android.tools.r8.internal.Fj.b(R8_3.3.70_49b71801b8b3de79ea68cec3bf950786c8f90f7a560cea4a2d23a82079b17d04:2)
at com.android.tools.r8.D8.run(R8_3.3.70_49b71801b8b3de79ea68cec3bf950786c8f90f7a560cea4a2d23a82079b17d04:11)
at com.android.builder.dexing.D8DexArchiveMerger.mergeDexArchives(D8DexArchiveMerger.java:136)
... 38 more
Caused by: com.android.tools.r8.internal.f: Cannot fit requested classes in a single dex file (# methods: 74755 > 65536)
at com.android.tools.r8.internal.JT.a(R8_3.3.70_49b71801b8b3de79ea68cec3bf950786c8f90f7a560cea4a2d23a82079b17d04:14)
at com.android.tools.r8.internal.JT.a(R8_3.3.70_49b71801b8b3de79ea68cec3bf950786c8f90f7a560cea4a2d23a82079b17d04:22)
at com.android.tools.r8.internal.n30.a(R8_3.3.70_49b71801b8b3de79ea68cec3bf950786c8f90f7a560cea4a2d23a82079b17d04:524)
at com.android.tools.r8.internal.i30.a(R8_3.3.70_49b71801b8b3de79ea68cec3bf950786c8f90f7a560cea4a2d23a82079b17d04:7)
at com.android.tools.r8.internal.F2.a(R8_3.3.70_49b71801b8b3de79ea68cec3bf950786c8f90f7a560cea4a2d23a82079b17d04:371)
at com.android.tools.r8.internal.F2.a(R8_3.3.70_49b71801b8b3de79ea68cec3bf950786c8f90f7a560cea4a2d23a82079b17d04:455)
at com.android.tools.r8.D8.d(R8_3.3.70_49b71801b8b3de79ea68cec3bf950786c8f90f7a560cea4a2d23a82079b17d04:756)
at com.android.tools.r8.D8.b(R8_3.3.70_49b71801b8b3de79ea68cec3bf950786c8f90f7a560cea4a2d23a82079b17d04:1)
at com.android.tools.r8.internal.Fj.a(R8_3.3.70_49b71801b8b3de79ea68cec3bf950786c8f90f7a560cea4a2d23a82079b17d04:24)
... 41 more
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeExtDexDebug'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.DexMergingTaskDelegate
> There was a failure while executing work items
> A failure occurred while executing com.android.build.gradle.internal.tasks.DexMergingWorkAction
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
The number of method references in a .dex file cannot exceed 64K.
Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html
* 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 23s
[!] App requires Multidex support
Multidex support is required for your android app to build since the number of methods has exceeded 64k. See https://docs.flutter.dev/deployment/android#enabling-multidex-support for more information. You may pass the --no-multidex flag to skip Flutter's multidex support to use a manual solution.
Flutter tool can add multidex support. The following file will be added by flutter:
android/app/src/main/java/io/flutter/app/FlutterMultiDexApplication.java
cannot prompt without a terminal ui
Error: Gradle task assembleDebug failed with exit code 1
Exited (1).
I understand that maybe enabling Multidex support can solve this issue, but I'm concerned about the potential impact on my app's performance and size. I'd like to avoid enabling Multidex if possible. More info:
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.19.1, on macOS 14.2.1 23C71 darwin-arm64, locale
en-MX)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
[✓] Android Studio (version 2021.1)
[✓] VS Code (version 1.87.1)
[✓] Connected device (2 available)
[✓] Network resources
• No issues found!
android/app/build.gradle file:
plugins {
id "com.android.application"
id "kotlin-android"
id "dev.flutter.flutter-gradle-plugin"
}
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
android {
namespace "com.example.my_app_example"
compileSdk flutter.compileSdkVersion
ndkVersion flutter.ndkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.my_app_example"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
// minSdkVersion flutter.minSdkVersion
minSdkVersion 20
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
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 {}
Is there a way to use flutter_secure_storage without exceeding the 64K method limit, or is there a workaround for this issue?
Thank you for your help.
Hello again,
I wanted to provide an update on this issue. I was able to resolve the problem by increasing the minSdkVersion in my build.gradle file to 21. Here's the updated line in my build.gradle:
minSdkVersion 21
I'm closing this issue now. Thank you for your attention to this matter.