Skip to content

Commit dcc85c5

Browse files
authored
[Android] Generate manifest from env, update intents (#145)
* Autogenerate manifest from env, update intents * Move manifest generation to build.gradle * Generate fake env for CI
1 parent ba7e176 commit dcc85c5

File tree

6 files changed

+45
-1
lines changed

6 files changed

+45
-1
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ jobs:
8787

8888
- name: Run Android tests
8989
run: |
90+
echo "STOREFRONT_DOMAIN=\"myshopify.com\"" > sample/.env
9091
yarn module build
9192
yarn sample test:android --no-daemon
9293

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,6 @@ sample/vendor
103103
!.yarn/releases
104104
!.yarn/sdks
105105
!.yarn/versions
106+
107+
# Sample app
108+
sample/**/AndroidManifest.xml

sample/android/app/build.gradle

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,21 @@ apply from: file("../../node_modules/react-native-vector-icons/fonts.gradle")
146146
apply from: file("../../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
147147

148148
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"
149+
150+
def properties = loadProperties()
151+
def storefrontDomain = properties.getProperty("STOREFRONT_DOMAIN")
152+
153+
if (!storefrontDomain) {
154+
println("**** Please add a .env file with STOREFRONT_DOMAIN set *****")
155+
}
156+
157+
task generateAndroidManifestFromTemplate {
158+
doLast {
159+
def templateFile = file('src/main/AndroidManifest.template.xml')
160+
def outputFile = file('src/main/AndroidManifest.xml')
161+
def content = templateFile.getText('UTF-8').replace('{{STOREFRONT_DOMAIN}}', "$storefrontDomain")
162+
outputFile.write(content, 'UTF-8')
163+
}
164+
}
165+
166+
preBuild.dependsOn(generateAndroidManifestFromTemplate)

sample/android/app/src/main/AndroidManifest.xml renamed to sample/android/app/src/main/AndroidManifest.template.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
22

33
<uses-permission android:name="android.permission.INTERNET" />
4+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
5+
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
46

57
<application
68
android:name=".MainApplication"
@@ -17,9 +19,21 @@
1719
android:launchMode="singleTask"
1820
android:windowSoftInputMode="adjustResize"
1921
android:exported="true">
22+
23+
<!-- This action signifies that the activity is the entry point of the application -->
2024
<intent-filter>
2125
<action android:name="android.intent.action.MAIN" />
2226
<category android:name="android.intent.category.LAUNCHER" />
27+
</intent-filter>
28+
29+
<!-- Configuration for app linking -->
30+
<intent-filter>
31+
<action android:name="android.intent.action.VIEW" />
32+
<category android:name="android.intent.category.DEFAULT" />
33+
<category android:name="android.intent.category.BROWSABLE" />
34+
35+
<!-- Note: the host here will be replaced on application start -->
36+
<data android:scheme="https" android:host={{STOREFRONT_DOMAIN}} />
2337
</intent-filter>
2438
</activity>
2539
</application>

sample/android/build.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,12 @@ buildscript {
2020
}
2121
}
2222

23+
def loadProperties() {
24+
def props = new Properties()
25+
file('../.env').withInputStream {
26+
props.load(it)
27+
}
28+
return props
29+
}
30+
2331
apply plugin: "com.facebook.react.rootproject"

sample/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"build:ios": "sh ./scripts/build_ios",
1212
"lint": "yarn typecheck && eslint .",
1313
"ios": "react-native run-ios --simulator 'iPhone 15 Pro'",
14-
"start": "react-native start -- --simulator 'iPhone 15 Pro'",
14+
"start": "react-native start -- --simulator 'iPhone 15 Pro' --reset-cache",
1515
"typecheck": "tsc --noEmit",
1616
"test:ios": "sh ./scripts/test_ios",
1717
"test:android": "sh ./scripts/test_android"

0 commit comments

Comments
 (0)