Adding multidex support to Flutter - error-handling

I am building my app with Flutter. Now I am always getting this error:
FAILURE: Build failed with an exception.* What went wrong:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug',> 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: 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 32s Finished with error: Gradle build failed: 1
So this error clearly says that I must add multidex-support. But how to do this in FLUTTER?

The problem is not with Firebase or Firestore - Its the number of dependencies you have added to your application, you need to enable Multidex - there are some steps on how to do it online Flutter multidex problem With FirebaseAuth , Firestore and Google Sign in

Versions of the platform prior to Android 5.0 use the Dalvik runtime for executing app code. By default, Dalvik limits apps to a single classes.dex bytecode file per APK. In order to get around this limitation, you can add the multidex support library to your project:
dependencies {
def multidex_version = "2.0.1"
implementation 'androidx.multidex:multidex:$multidex_version'
}
To view the current versions for this library, see the information about Multidex on the versions page.
If you aren't using AndroidX, add the following support library dependency instead:
dependencies {implementation 'com.android.support:multidex:1.0.3'}

Finally, I fixed it with removing the CloudFirestore implementation. Seems there is a version bug at the time.

Related

Where to enable zip64 extension in build.gradle.kts?

I am working on a ktor multiplatform application.
While the application is running continuously, I come across an error message that says
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':jvmJar'.
archive's size exceeds the limit of 4GByte.
To build this archive, please enable the zip64 extension.
See: https://docs.gradle.org/7.3.3/dsl/org.gradle.api.tasks.bundling.Zip.html#org.gradle.api.tasks.bundling.Zip:
How and where to enable the zip64 extension?The version of gradle that I am using is 7.3.3
Do you have a Jar task?
Say you use ShadowJar, then the configuration would look like:
tasks.shadowJar {
setProperty("zip64", true)
// other shadow jar config
}

How do you split large kotlin based Gradle build files with variables?

I have a large gradle.build.kts file and I'm trying to break it into smaller pieces using apply(from = "xxx") (I'm open to better solutions if one exists).
The problem is that I've run into a problem where one of my scripts cant handle variables. Here is the sample code:
build.gradle.kts
plugins { java }
repositories { mavenCentral() }
dependencies { testCompile("junit", "junit", "4.12") }
println("Before Apply")
apply(from = "./build.gradle.test.kts")
println("After Apply")
build.gradle.test.kts
println("Applying")
tasks.test {
val failedTests = mutableListOf<TestDescriptor>()
}
println("Applied")
both files are at the root project folder.
output...
>gradle clean build test
> Configure project :
Before Apply
FAILURE: Build failed with an exception.
* Where:
Build file 'D:\Users\jamesdmcmillian\Projects\FacilitatorLabs\Labs\gradle-dsl-script-variables\build.gradle.kts' line: 6
* What went wrong:
Could not open cp_dsl generic class cache for script 'D:\Users\jamesdmcmillian\Projects\FacilitatorLabs\Labs\gradle-dsl-script-variables\build.gradle.test.kts' (C:\Users\jamesdmcmillian\.gradle\caches\6.8\scripts\7kclhsg56vjpfm1z90j
4hwepn).
> Could not compile script 'D:\Users\jamesdmcmillian\Projects\FacilitatorLabs\Labs\gradle-dsl-script-variables\build.gradle.test.kts'.
> startup failed:
script 'D:\Users\jamesdmcmillian\Projects\FacilitatorLabs\Labs\gradle-dsl-script-variables\build.gradle.test.kts': 4: expecting '}', found 'failedTests' # line 4, column 9.
val failedTests = mutableListOf<TestDescriptor>()
^
1 error
* 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
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.8/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 4s
Is it possible to have variables/values contained inside applied scripts?
This seems like an awfully bad restriction if it's not.
These posts are close, but don't answer the variable question: Is there a way to split/factor out common parts of Gradle build
Also, I've read the kotlin-dsl primer, and not seeing anything specific to this issue, or maybe i missed it. The rest of the code works fine, so I've eliminated it from this question.
Any help is appreciated, thanks in advance.
Versions Info:
Gradle 6.8
Kotlin: 1.4.20
Groovy: 2.5.12
Ant: Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM: 11.0.2 (Oracle Corporation 11.0.2+9)
OS: Windows 10 10.0 amd64

calabash-android run app-debug.apk throws exception

I am trying to run calabash-android to test my app, but I get the following error, the same app without any modification was working before I tried to do some modifications, but then I reverted all the modifications to the app :
Exception occurred while dumping:
java.lang.IllegalArgumentException: Unknown package: com.bitbar.testdroid
at com.android.server.pm.Settings.isOrphaned(Settings.java:4134)
at com.android.server.pm.PackageManagerService.isOrphaned(PackageManagerService.java:18091)
at com.android.server.pm.PackageManagerService.deletePackage(PackageManagerService.java:15508)
at com.android.server.pm.PackageInstallerService.uninstall(PackageInstallerService.java:888)
at com.android.server.pm.PackageManagerShellCommand.runUninstall(PackageManagerShellCommand.java:792)
at com.android.server.pm.PackageManagerShellCommand.onCommand(PackageManagerShellCommand.java:118)
at android.os.ShellCommand.exec(ShellCommand.java:94)
at com.android.server.pm.PackageManagerService.onShellCommand(PackageManagerService.java:18349)
at android.os.Binder.shellCommand(Binder.java:468)
at android.os.Binder.onTransact(Binder.java:367)
at android.content.pm.IPackageManager$Stub.onTransact(IPackageManager.java:2387)
at com.android.server.pm.PackageManagerService.onTransact(PackageManagerService.java:3031)
at android.os.Binder.execTransact(Binder.java:565)
And then
Success
Success
Scenario: I can choose a file from the Gallery # features/my_first.feature:3
HTTPClient::KeepAliveDisconnected: Connection reset by peer # io_fillbuf - fd:8 (HTTPClient::KeepAliveDisconnected)
./features/support/app_life_cycle_hooks.rb:5:in `Before'
When I take a screenshot # calabash-android-0.9.0/lib/calabash-android/steps/screenshot_steps.rb:9
Then I take a screenshot # calabash-android-0.9.0/lib/calabash-android/steps/screenshot_steps.rb:9
Failing Scenarios:
cucumber features/my_first.feature:3 # Scenario: I can choose a file from the Gallery
1 scenario (1 failed)
2 steps (2 skipped)
0m6.240s
Exception ScreenShot
I solved the problem by running the build using the gradle task :app:assembleDebug
in the exception above, calabash can't find the package name, because it is on another dex class.
I think in calabash, they may be having problem with multidex projects, and Android Studio will always enable multidex to your app, even if it doesn't need it.
I am not an expert, any suggestion are welcome, and I hope some people can benefit from this answer.

Could not find com.android.support:support-v4:23.2.1

When using react-native 0.28 and above (0.29, 0.30-rc), I get the following error when executing react-native run-android in a fresh react-native init app project.
Could not find com.android.support:support-v4:23.2.1.
I installed the newest android studio and even installed the obsolete library manually.
What am I doing wrong?
Thanks!
To complete Tonithy's answer - the .jar may not be enough, you need to copy two whole directories, otherwise gradle will complain for the missing .aar. In this case, I think that those were installed by Android Studio:
{USER}/Library/Android/sdk/extras/android/m2repository/com/android/support/support-v4/23.2.1/
And don't forget the dependency:
{USER}/Library/Android/sdk/extras/android/m2repository/com/android/support/support-annotations/23.2.1/
I had exactly the same problem while upgrading to react-native 0.30, that solved the issue.
Google seems to have stopped including a version of each support library without sources/javadoc/etc and React is looking for this specific file. Assuming you manually installed the obsolete version, it will be in {YOUR_ANDROID_LOCATION}/extras/android/support/v4/android-support-v4.jar Your best bet is to manually copy it in:
cp {YOUR_ANDROID_LOCATION}/extras/android/support/v4/android-support-v4.jar {YOUR_ANDROID_LOCATION}/extras/android/m2repository/com/android/support/support-v4/23.2.1/support-v4-23.2.1.jar
This a React Native (version and probably OSX specific bug), it will probably be fixed soon. For posterity, your full error was something like this, looking for support in all the wrong places:
OsagieTheGreat-MBA:somereactapp osagiethegreat$ react-native run-android
JS server already running.
Building and installing the app on the device (cd android && ./gradlew installDebug...
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugCompile'.
> Could not find com.android.support:support-v4:23.2.1.
Searched in the following locations:
file:/Users/osagiethegreat/.m2/repository/com/android/support/support-v4/23.2.1/support-v4-23.2.1.pom
file:/Users/osagiethegreat/.m2/repository/com/android/support/support-v4/23.2.1/support-v4-23.2.1.jar
https://jcenter.bintray.com/com/android/support/support-v4/23.2.1/support-v4-23.2.1.pom
https://jcenter.bintray.com/com/android/support/support-v4/23.2.1/support-v4-23.2.1.jar
file:/Users/osagiethegreat/Documents/somereactapp/node_modules/react-native/android/com/android/support/support-v4/23.2.1/support-v4-23.2.1.pom
file:/Users/osagiethegreat/Documents/somereactapp/node_modules/react-native/android/com/android/support/support-v4/23.2.1/support-v4-23.2.1.jar
file:/Applications/Android Dev/sdk/extras/android/m2repository/com/android/support/support-v4/23.2.1/support-v4-23.2.1.pom
file:/Applications/Android Dev/sdk/extras/android/m2repository/com/android/support/support-v4/23.2.1/support-v4-23.2.1.jar
file:/Applications/Android Dev/sdk/extras/google/m2repository/com/android/support/support-v4/23.2.1/support-v4-23.2.1.pom
file:/Applications/Android Dev/sdk/extras/google/m2repository/com/android/support/support-v4/23.2.1/support-v4-23.2.1.jar
Required by:
SomeReactApp:app:unspecified > com.android.support:appcompat-v7:23.0.1
SomeReactApp:app:unspecified > com.facebook.react:react-native:0.29.0 > com.android.support:recyclerview-v7:23.0.1
> Could not find com.android.support:support-v4:23.2.1.
Searched in the following locations:
file:/Users/osagiethegreat/.m2/repository/com/android/support/support-v4/23.2.1/support-v4-23.2.1.pom
file:/Users/osagiethegreat/.m2/repository/com/android/support/support-v4/23.2.1/support-v4-23.2.1.jar
https://jcenter.bintray.com/com/android/support/support-v4/23.2.1/support-v4-23.2.1.pom
https://jcenter.bintray.com/com/android/support/support-v4/23.2.1/support-v4-23.2.1.jar
file:/Users/osagiethegreat/Documents/somereactapp/node_modules/react-native/android/com/android/support/support-v4/23.2.1/support-v4-23.2.1.pom
file:/Users/osagiethegreat/Documents/somereactapp/node_modules/react-native/android/com/android/support/support-v4/23.2.1/support-v4-23.2.1.jar
file:/Applications/Android Dev/sdk/extras/android/m2repository/com/android/support/support-v4/23.2.1/support-v4-23.2.1.pom
file:/Applications/Android Dev/sdk/extras/android/m2repository/com/android/support/support-v4/23.2.1/support-v4-23.2.1.jar
file:/Applications/Android Dev/sdk/extras/google/m2repository/com/android/support/support-v4/23.2.1/support-v4-23.2.1.pom
file:/Applications/Android Dev/sdk/extras/google/m2repository/com/android/support/support-v4/23.2.1/support-v4-23.2.1.jar
Required by:
SomeReactApp:app:unspecified > com.facebook.react:react-native:0.29.0 > com.facebook.fresco:imagepipeline-okhttp3:0.11.0 > com.facebook.fresco:imagepipeline:0.11.0
SomeReactApp:app:unspecified > com.facebook.react:react-native:0.29.0 > com.facebook.fresco:fresco:0.11.0 > com.facebook.fresco:drawee:0.11.0
SomeReactApp:app:unspecified > com.facebook.react:react-native:0.29.0 > com.facebook.fresco:imagepipeline-okhttp3:0.11.0 > com.facebook.fresco:imagepipeline:0.11.0 > com.facebook.fresco:imagepipeline-base:0.11.0
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 10.838 secs
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/android-setup.html
I also got this error, after installing Android Support Library the error has gone.
Install Android Support Library from Extras
First solution could be adding this
compile 'com.android.tools:sdklib:23.2.1'
to the next file
android/app/build.gradle
Second solution is installing Android Support Repository
To Complete Tonithy's and Simon's answer, yes the jar itself was not enough, all the files of two directories -
extras/android/m2repository/com/android/support/support-v4/23.2.1/ and
extras/android/m2repository/com/android/support/support-annotations/23.2.1/ are needed. On my Windows PC, I couldn't find files of these directories anywhere.
So what I did was, I downloaded these folders from googlesource
1. support/support-annotations/23.2.1
Download tgz of above folder and extract the files into {YOUR_ANDROID_LOCATION}/extras/android/m2repository/com/android/support/support-annotations/23.2.1/
2. support/support-v4/23.2.1
Download tgz of above folder and extract the files into {YOUR_ANDROID_LOCATION}/extras/android/m2repository/com/android/support/support-v4/23.2.1/
Now go to your command propmt or terminal and run react-native run-android
Hope it save someone few hours!!

Could not find com.google.gms:google-services:9.0,0

The Sync failed when tried to add the dependency for google play service. The problem seem to its looking for the jar in C:/Program/Files/Android/Android Studio however my SDK is placed in C:\Android\sdk. However I also have Android Studio in Program Files where there are no jar for Google play services.
Information:Gradle tasks [clean, :app:generateDebugSources, :app:compileDebugSources]
Error:A problem occurred configuring root project 'XXXXXX'.
Could not resolve all dependencies for configuration ':classpath'.
Could not find com.google.gms:google-services:9.0.0.
Searched in the following locations:
file:/C:/Program Files/Android/Android Studio/gradle/m2repository/com/google/gms/google-services/9.0.0/google-services-9.0.0.pom
file:/C:/Program Files/Android/Android Studio/gradle/m2repository/com/google/gms/google-services/9.0.0/google-services-9.0.0.jar
https://jcenter.bintray.com/com/google/gms/google-services/9.0.0/google-services-9.0.0.pom
https://jcenter.bintray.com/com/google/gms/google-services/9.0.0/google-services-9.0.0.jar
Required by:
:XXXXX:unspecified
Information:BUILD FAILED
Information:Total time: 6.148 secs
Information:1 error
Information:0 warnings
Information:See complete output in console
Also my ANDROID_HOME is set to C:\Android\sdk.
Please advise.
By checking other SO question. You can find that Google Play Service updating to version 9.0.0 has a bug issue.
Some solution is by checking if you have enabled offline work for gradle, deselect Offline Work if it's checked. Then, confirm if you have latest version of Google services mentioned as dependencies in project level build.gradle: classpath 'com.google.gms:google-services:3.0.0'. Clean and build the project after the gradle sync completes.
Also, some people fixed it by just deleting the debug.keystore file found in the android folder.
Check this SO question for more information.