Cloud Firestore with gRPC build error - android

I’m working on an android application, which have to use gRPC and Firestore. However, when I added both one of module from ‘io.grpc’ group dependency (e.g. io.grpc:grpc-okhttp:1.7.0) and firestore dependency (com.google.firebase:firebase-firestore:11.4.2) in the build gradle config, I got a build error “Unable to merge dex”. After with ‘stacktrace’ build option, I saw that the problem is
Multiple dex files define Lio/grpc/internal/OobChannel$5;
It could happen if firestore uses grpc-core module, but there is no one similar in tree dependencies, which I got using [androidDependencies] gradle task. I tried to exclude io.grpc like this:
implementation ('com.google.firebase:firebase-firestore:11.4.2') {
exclude group: 'io.grpc'
}
but there was the same error. Then I thought what if I exclude all ‘io.grpc.’ transitive dependencies from grpc module dependencies with adding grpc-core for internal classes. In this way, I wrote ugly dependencies just for test
implementation 'com.google.firebase:firebase-firestore:11.4.2'
implementation('io.grpc:grpc-okhttp:1.7.0') {
exclude group: 'io.grpc'
}
implementation('io.grpc:grpc-protobuf-lite:1.7.0') {
exclude group: 'io.grpc'
}
implementation('io.grpc:grpc-stub:1.7.0') {
exclude group: 'io.grpc'
}
implementation 'io.grpc:grpc-core:1.7.0'
I was surprised when it successfully compiled, but after launch app, it crashed with java.lang.RuntimeException: Internal error in Firestore (0.6.6-dev)
Caused by: java.lang.NoSuchMethodError: No static method zzcyc()Lio/grpc/ManagedChannelProvider; in class Lio/grpc/ManagedChannelProvider; or its super classes (declaration of 'io.grpc.ManagedChannelProvider' appears in /data/app/com.zipr.test-2/split_lib_dependencies_apk.apk)
I use gradle 3.0.0-rc1 with enabling multidex support. I deleted .gradle, build directories, cleaned rebuilt project, but I still have build error. What can I do to resolve this problem?

Due to a variety of factors that constrain the way we build Android SDKs at Google, Firestore proguards a copy of gRPC within itself. Unfortunately this is leaky and you're running into the fallout: the 11.4.2 Firestore SDK is incompatible with any external gRPC :-(.
This is essentially our top issue for the Firestore Android SDK and I'm sorry you've run into it.

Related

Can't use AliPay and Alibaba Push sdks in the same project due to Duplicate classes

I added Allibaba Push SDK to my Android project by adding the following module:
com.aliyun.ams:alicloud-android-push.
Then I tried to add the AliPay SDK in order to use payment via AliPay by downloading the following aar file:
alipaySdk-15.7.4-20200228192259 (this is the latest version according the the AliPay docs).
After adding both modules, the project won't compile due to several duplicate classes that exist in both modules.
I tried excluding the classes this way:
implementation(name: 'alipaySdk-15.7.4-20200228192259', ext: 'aar') {
exclude group: 'com.ut.device.UTDevice', module: 'alicloud-android-push'
}
com.ut.device.UTDevice is one of the duplicated classes..
But the duplicate message still persist for this class.
I also try to exclude the whole package (com.ut.*) but that didn't work either.
Anyone knows how to resolve this?
Thanks

R8: Program type already present: androidx.databinding.library.baseAdapters.BR

Im getting the above error trying to create a release build of my app. When doing a debug build everything is running fine.
My project has a structure as follows
app (contains databinding)
video sdk (contains data binding)
another sdk (contains data binding)
Im thinking it finds multiple databinding instances which makes the above error but im not really sure how to circumvent this.
What also weird is that the app does compile when clicking run in Android studio but when trying to build from terminal its not compiling
Posting few of workarounds here
./gradlew clean
Exclude duplicates as message Program type already present means there is a naming conflict.
configurations {
compile.exclude group: 'androidx.databinding', module: 'databinding'
}
Then do sync, clean & rebuild.
I am not sure but tried to create a separate module for databinding gradle and add that module into all current modules (app, video sdk, another sdk)
Module core (Gradle with "api"):
api 'com.github.bumptech.glide:glide:4.9.0'
kapt 'com.github.bumptech.glide:compiler:4.9.0'
App module and other SDKs modules will use that core module.
implementation project(path: ':core')
Hope it will help.
I faced this error and spent almost 2 days in figuring out what was causing this error. Eventually, I found out that one of my transitive SDK, which used Kotlin, did not have the following in its Gradle file.
kotlinOptions kotlin_options = {
jvmTarget = "1.8"
}
After adding this, I was able to resolve the error.
Please try this, I am not sure but sometime release apk having problem of conflict ion
Add multiDexEnabled true in app gradle file.
Hope this will help!

java.lang.RuntimeException: Duplicate class com.google.protobuf.AbstractMessageLite when adding firebase remote config

When I am adding com.google.firebase:firebase-config:19.1.0 to use firebase remote config having this issue.
java.lang.RuntimeException: Duplicate class com.google.protobuf.AbstractMessageLite found in modules protobuf-java-2.5.0.jar (com.google.protobuf:protobuf-java:2.5.0) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
I have updated both firebase-analytics and google-play-services to latest version. But still the problem exist.
But when I changed remote config to older version 18.0.0 or less then its working fine. But I want to use the latest version.
My dependencies:
firebase_analytics : "com.google.firebase:firebase-analytics:17.2.2",
fcm : "com.google.firebase:firebase-messaging:20.1.0",
performance : "com.google.firebase:firebase-perf:19.0.0",
config : "com.google.firebase:firebase-config:19.0.0",
Also tried to exclude below doesn't work:
exclude group: 'com.google.protobuf', module: 'protobuf-lite'
exclude group: 'com.google.protobuf', module: 'protobuf-java'
Finally, I fixed this issue. First lets understand the issue:
protobuf-java and protobuf-lite are incompatible packages. They both include classes in the com.google.protobuf package. protobuf-java is typically used in packages intended for desktop and server-side use (i.e. regular Java), while protobuf-lite is frequently used in packages that target Android.
Firebase packages depend upon protobuf-lite. Something else in your project must depend on protobuf-java. You can see a tree view of your dependencies by following these instructions: https://stackoverflow.com/a/35235229.
The exclusion is required to resolve the incompatibility, though really you should see if there's an android-specific variant of whatever package you're using that's introducing protobuf-java.
To exclude the duplicate classes that's causing the problem, add the following code into your build.gradle (app module) file:
android {
...
configurations {
implementation.exclude module:'protobuf-lite'
}
}
try this, add the code in app's build
configurations {
implementation.exclude module:'protobuf-java'
}
The missing classes is a known issue. Full proto and lite proto can't be mixed; they use different generated code. Do not depend on protobuf-java as an implementation dependency, but as a protobuf dependency which will cause gradle-protobuf-plugin to generate code for the .protos.
dependencies {
...
protobuf 'com.google.protobuf:protobuf-java:3.7.1'
}
Note that this solution only really works for an application. If you are a library, it is dangerous because users of your library may then see multiple copied of the generated code for the well-known protos.

Gradle duplicate dependency in library and project

We are working on an application (APP) that uses a local maven dependency library (LIB). LIB uses a custom .jar of OkHttp, and APP also uses OkHttp (not custom). When we try to build, we get a 'Multiple dex files define X' error, and enabling multiDex gives an error about a duplicate ZipException. APP is trying to refer to the OkHttp.jar in LIB, when we want it to not do that. And, well, we can't get it to work.
We've tried placing this in our APP gradle file with no luck:
compile(LIB) {
exclude group: 'com.squareup', module: 'okhttp';
}
And, unfortunately, we can't not use LIB. Thoughts? Also, gradle -q dependencies does not list any dependencies under LIB, but we know that it uses a compile file('CUSTOM_OKHTTP') line in its gradle.

How can I find the dependencies in my app that are using findbugs? (findbugs conflict)

I'm trying to discover the specific conflict when adding espresso to my app's gradle file:
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.1') {
exclude group: 'com.android.support', module: 'support-annotations'
}
Android Studio states "Warning:Conflict with dependency 'com.google.code.findbugs:jsr305'.
Dependency conflict error in my Android app which has Android Tests states the error means the dependency I am using in my app is version 3.0.0 while the one in my test app is 2.0.1.
However, my gradle never explicitly adds "com.google.code.findbugs", indicating it was part of another dependency I added to my "compile" and "androidTestCompile" statements. How do I find the dependencies in my app that are using findbugs?
Check your dependencies:
HelloApp/
app/
- build.gradle // local gradle config (for app only)
...
- build.gradle // global gradle config (for whole project)
- settings.gradle
- gradle.properties
Check here:
dependencies {
compile project(':libraries:lib')
}
Later check this LINK you have Unit testing support orientation
Execute the following command:
./gradlew app:dependencies
This will print a (large) graph of dependencies.
For the meaning of the arrows and stars, please refer to this SO answer.

Categories

Resources