Skip to content

Commit 9662df3

Browse files
Firestore: Fix args to AggregateQuerySnapshot constructor (#1277)
* Fix call to AggregateQuerySnapshot constructor * format code * Fix "More than one file was found with OS independent path 'META-INF/com.android.tools/proguard/coroutines.pro'" error * Revert "Fix "More than one file was found with OS independent path 'META-INF/com.android.tools/proguard/coroutines.pro'" error" This reverts commit fc0faea. * Fix conflict for coroutines.pro file in google library. Cherry-picked from #1278 to fix the "More than one file was found with OS independent path 'META-INF/com.android.tools/proguard/coroutines.pro'" error --------- Co-authored-by: Jon Simantov <jsimantov@google.com>
1 parent 0e9f12b commit 9662df3

File tree

8 files changed

+67
-2
lines changed

8 files changed

+67
-2
lines changed

auth/integration_test/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ android {
7272
proguardFile file('proguard.pro')
7373
}
7474
}
75+
packagingOptions {
76+
pickFirst 'META-INF/**/coroutines.pro'
77+
}
7578
}
7679

7780
apply from: "$gradle.firebase_cpp_sdk_dir/Android/firebase_dependencies.gradle"

database/integration_test/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ android {
7272
proguardFile file('proguard.pro')
7373
}
7474
}
75+
packagingOptions {
76+
pickFirst 'META-INF/**/coroutines.pro'
77+
}
7578
}
7679

7780
apply from: "$gradle.firebase_cpp_sdk_dir/Android/firebase_dependencies.gradle"

firestore/integration_test/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ android {
7373
proguardFile file('proguard.pro')
7474
}
7575
}
76+
packagingOptions {
77+
pickFirst 'META-INF/**/coroutines.pro'
78+
}
7679
}
7780

7881
apply from: "$gradle.firebase_cpp_sdk_dir/Android/firebase_dependencies.gradle"

firestore/integration_test_internal/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ android {
7373
proguardFile file('proguard.pro')
7474
}
7575
}
76+
packagingOptions {
77+
pickFirst 'META-INF/**/coroutines.pro'
78+
}
7679
lintOptions {
7780
abortOnError false
7881
}

firestore/src/android/aggregate_query_snapshot_android.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,34 @@ using jni::Env;
3030
using jni::Local;
3131
using jni::Method;
3232
using jni::Object;
33+
using jni::StaticMethod;
3334

3435
constexpr char kClassName[] =
3536
PROGUARD_KEEP_CLASS "com/google/firebase/firestore/AggregateQuerySnapshot";
3637
Constructor<Object> kConstructor(
37-
"(Lcom/google/firebase/firestore/AggregateQuery;J)V");
38+
"(Lcom/google/firebase/firestore/AggregateQuery;Ljava/util/Map;)V");
3839
Method<int64_t> kGetCount("getCount", "()J");
3940
Method<Object> kGetQuery("getQuery",
4041
"()Lcom/google/firebase/firestore/AggregateQuery;");
4142
Method<int32_t> kHashCode("hashCode", "()I");
4243

44+
constexpr char kHelperClassName[] = PROGUARD_KEEP_CLASS
45+
"com/google/firebase/firestore/internal/cpp/AggregateQuerySnapshotHelper";
46+
StaticMethod<Object> kCreateConstructorArg(
47+
"createAggregateQuerySnapshotConstructorArg", "(J)Ljava/util/Map;");
48+
4349
} // namespace
4450

4551
void AggregateQuerySnapshotInternal::Initialize(jni::Loader& loader) {
4652
loader.LoadClass(kClassName, kConstructor, kGetCount, kGetQuery, kHashCode);
53+
loader.LoadClass(kHelperClassName, kCreateConstructorArg);
4754
}
4855

4956
AggregateQuerySnapshot AggregateQuerySnapshotInternal::Create(
5057
Env& env, AggregateQueryInternal& aggregate_query_internal, int64_t count) {
58+
Local<Object> snapshot_data = env.Call(kCreateConstructorArg, count);
5159
Local<Object> instance =
52-
env.New(kConstructor, aggregate_query_internal.ToJava(), count);
60+
env.New(kConstructor, aggregate_query_internal.ToJava(), snapshot_data);
5361
return aggregate_query_internal.firestore_internal()
5462
->NewAggregateQuerySnapshot(env, instance);
5563
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2023 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.firebase.firestore.internal.cpp;
18+
19+
import com.google.firestore.v1.Value;
20+
import java.util.HashMap;
21+
import java.util.Map;
22+
23+
public final class AggregateQuerySnapshotHelper {
24+
private AggregateQuerySnapshotHelper() {}
25+
26+
/**
27+
* Creates an object appropriate for specifying to the AggregateQuerySnapshot
28+
* constructor that conveys the given "count" as the lone aggregate result.
29+
*
30+
* This class should be deleted and replaced with a proper mechanism once
31+
* SUM/AVERAGE are ported to this SDK.
32+
*/
33+
public static Map<String, Value> createAggregateQuerySnapshotConstructorArg(
34+
long count) {
35+
HashMap<String, Value> map = new HashMap<>();
36+
map.put("count", Value.newBuilder().setIntegerValue(count).build());
37+
return map;
38+
}
39+
}

functions/integration_test/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ android {
7272
proguardFile file('proguard.pro')
7373
}
7474
}
75+
packagingOptions {
76+
pickFirst 'META-INF/**/coroutines.pro'
77+
}
7578
}
7679

7780
apply from: "$gradle.firebase_cpp_sdk_dir/Android/firebase_dependencies.gradle"

storage/integration_test/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ android {
7272
proguardFile file('proguard.pro')
7373
}
7474
}
75+
packagingOptions {
76+
pickFirst 'META-INF/**/coroutines.pro'
77+
}
7578
}
7679

7780
apply from: "$gradle.firebase_cpp_sdk_dir/Android/firebase_dependencies.gradle"

0 commit comments

Comments
 (0)