Skip to content

Commit 64eaaa2

Browse files
author
Mantu
committed
fix(android): Do not add duplicate queries and package entries
- use existing queries tag to append packages
1 parent e527b79 commit 64eaaa2

File tree

6 files changed

+39
-26
lines changed

6 files changed

+39
-26
lines changed

example/android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,10 @@
1010
<category android:name="android.intent.category.BROWSABLE"/>
1111
<data android:scheme="https"/>
1212
</intent>
13-
</queries>
14-
<queries>
15-
<package android:name="com.google.android.apps.fitness"/>
16-
<package android:name="com.android.chrome"/>
17-
</queries>
18-
<queries>
1913
<package android:name="com.google.android.apps.fitness"/>
2014
<package android:name="com.android.chrome"/>
2115
<package android:name="com.expo.flash.qr"/>
16+
<package android:name="com.test.this"/>
2217
</queries>
2318
<application android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:allowBackup="true" android:theme="@style/AppTheme">
2419
<meta-data android:name="expo.modules.updates.ENABLED" android:value="false"/>

example/android/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# Specifies the JVM arguments used for the daemon process.
1111
# The setting is particularly useful for tweaking memory settings.
1212
# Default value: -Xmx512m -XX:MaxMetaspaceSize=256m
13-
org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m
13+
org.gradle.jvmargs=-Xmx4096m -XX:MaxMetaspaceSize=1024m
1414

1515
# When configured, Gradle will run in incubating parallel mode.
1616
# This option should only be used with decoupled projects. More details, visit

example/app.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@
2424
},
2525
"plugins": [
2626
[
27-
"expo-check-installed-apps",
27+
"../app.plugin.js",
2828
{
2929
"android": [
3030
"com.google.android.apps.fitness",
3131
"com.android.chrome",
32-
"com.expo.flash.qr"
32+
"com.expo.flash.qr",
33+
"com.test.this"
3334
],
3435
"ios": ["fb", "twitter"]
3536
}

example/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
"dependencies": {
1212
"expo": "~51.0.28",
1313
"react": "18.2.0",
14-
"react-native": "0.74.5",
15-
"expo-check-installed-apps": "0.2.6"
14+
"react-native": "0.74.5"
1615
},
1716
"devDependencies": {
1817
"@babel/core": "^7.20.0",

example/yarn.lock

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2908,11 +2908,6 @@ expo-asset@~10.0.10:
29082908
invariant "^2.2.4"
29092909
md5-file "^3.2.3"
29102910

2911-
2912-
version "0.2.5"
2913-
resolved "https://registry.yarnpkg.com/expo-check-installed-apps/-/expo-check-installed-apps-0.2.5.tgz#1882e41d532fc7aa28d0892006b68997bda7995f"
2914-
integrity sha512-2G4TJyiLQz4ct5HcaXtYFAanuT5VGSoftm7jT4FT8dD2FgyXwqoTyGY6G/YTRHwMkfcHBKSLNxWF1Ofx9dJkZA==
2915-
29162911
expo-constants@~16.0.0:
29172912
version "16.0.2"
29182913
resolved "https://registry.npmjs.org/expo-constants/-/expo-constants-16.0.2.tgz"

plugin/src/index.ts

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,40 @@ const withAndroid: ConfigPlugin<PluginOptions> = (config, { android }) => {
2727
manifest.queries = [];
2828
}
2929

30-
// Create a single new <queries> block with all new packages
31-
const newPackages = android.map((packageName) => ({
32-
$: { "android:name": packageName },
33-
}));
34-
35-
const newQueriesBlock = {
36-
package: newPackages,
37-
};
30+
// Use the first <queries> block in the manifest
31+
const existingQueries = manifest.queries.find(
32+
(query) => query.intent || query.package
33+
);
3834

39-
// Append the new <queries> block while preserving existing blocks
40-
manifest.queries.push(newQueriesBlock);
35+
if (existingQueries) {
36+
// Add packages to the existing <queries> block
37+
if (!existingQueries.package) {
38+
existingQueries.package = [];
39+
}
40+
41+
const existingPackageNames = new Set(
42+
existingQueries.package.map((pkg: any) => pkg.$["android:name"])
43+
);
44+
45+
const newPackages = android
46+
.filter((packageName) => !existingPackageNames.has(packageName))
47+
.map((packageName) => ({
48+
$: { "android:name": packageName },
49+
}));
50+
51+
if (newPackages.length > 0) {
52+
existingQueries.package.push(...newPackages);
53+
}
54+
} else {
55+
// Create a new <queries> block if none exists
56+
const newPackages = android.map((packageName) => ({
57+
$: { "android:name": packageName },
58+
}));
59+
60+
manifest.queries.push({
61+
package: newPackages,
62+
});
63+
}
4164

4265
return config;
4366
});

0 commit comments

Comments
 (0)