Skip to content

Commit db5e750

Browse files
committed
Add support for custom activity impl.
1 parent fe21b75 commit db5e750

File tree

6 files changed

+21
-9
lines changed

6 files changed

+21
-9
lines changed

application/platforms/android/gradle/AndroidManifest.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<uses-feature android:name="android.hardware.vulkan.level" android:version="0" android:required="true"/>
99

1010
<application android:label="@string/app_name" android:icon="@drawable/$$ICON$$">
11-
<activity android:name="net.themaister.granite.GraniteActivity"
11+
<activity android:name="$$ACTIVITY_NAME$$"
1212
android:theme="@style/Application.Fullscreen"
1313
android:launchMode="singleTask"
1414
android:screenOrientation="landscape"

application/platforms/android/gradle/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,5 @@ dependencies {
9494
implementation 'androidx.games:games-activity:2.0.2'
9595
implementation 'androidx.games:games-controller:2.0.1'
9696
implementation 'androidx.games:games-frame-pacing:2.1.0'
97+
$$EXTRA_DEPENDENCIES$$
9798
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
include 'granite:android'
2+
project(':granite:android').projectDir = file('$$GRANITE_ANDROID_ACTIVITY_PATH$$')
3+
include 'custom:android'
4+
project(':custom:android').projectDir = file('$$ANDROID_ACTIVITY_PATH$$')
5+
include '$$APP$$'

application/platforms/android/src/main/AndroidManifest.xml

-5
This file was deleted.

application/platforms/android/src/main/res/values/themes.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
<!-- Base application theme. -->
33
<style name="Application.Fullscreen" parent="Theme.AppCompat.Light.NoActionBar">
44
<item name="android:windowFullscreen">true</item>
5-
<item name="android:windowContentOverlay">@null</item>"
5+
<item name="android:windowContentOverlay">@null</item>
66
</style>
77
</resources>

tools/create_android_build.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ def main():
8888
parser.add_argument('--swappy',
8989
help = 'Add Swappy support',
9090
action = 'store_true')
91+
parser.add_argument('--activity-name',
92+
help = 'Use custom activity name')
93+
parser.add_argument('--activity-path',
94+
help = 'Path to custom Android activity code')
9195

9296
args = parser.parse_args()
9397
abis = ['arm64-v8a'] if args.abis is None else args.abis
@@ -99,7 +103,7 @@ def main():
99103

100104
manifest = os.path.join(gradle_base, 'AndroidManifest.xml')
101105
build_gradle = os.path.join(gradle_base, 'build.gradle')
102-
settings_gradle = os.path.join(gradle_base, 'settings.gradle')
106+
settings_gradle = os.path.join(gradle_base, 'settings_custom.gradle' if args.activity_name else 'settings.gradle')
103107
toplevel_gradle = os.path.join(gradle_base, 'toplevel.build.gradle')
104108
gradle_properties = os.path.join(gradle_base, 'gradle.properties')
105109
if (not os.path.isfile(manifest)) or \
@@ -122,10 +126,12 @@ def main():
122126

123127
# Write out AndroidManifest.xml
124128
with open(manifest, 'r') as f:
129+
activity_name = args.activity_name if args.activity_name else 'net.themaister.granite.GraniteActivity'
125130
manifest_data = f.read()
126131
manifest_data = manifest_data \
127132
.replace('$$ICON$$', args.activity_icon_drawable) \
128133
.replace('$$NATIVE_TARGET$$', args.native_target) \
134+
.replace('$$ACTIVITY_NAME$$', activity_name) \
129135
.replace('$$VERSION_CODE$$', args.version_code) \
130136
.replace('$$VERSION_NAME$$', args.version_name)
131137

@@ -177,7 +183,8 @@ def main():
177183
.replace('$$PHYSICS$$', 'ON' if args.physics else 'OFF') \
178184
.replace('$$SHADER_OPTIMIZE$$', 'ON' if args.optimize else 'OFF') \
179185
.replace('$$FOSSILIZE$$', 'ON' if args.fossilize else 'OFF') \
180-
.replace('$$SWAPPY$$', 'ON' if args.swappy else 'OFF')
186+
.replace('$$SWAPPY$$', 'ON' if args.swappy else 'OFF') \
187+
.replace('$$EXTRA_DEPENDENCIES$$', "api project(':custom:android')" if args.activity_name else '')
181188

182189
with open(target_build_gradle, 'w') as dump_file:
183190
print(data, file = dump_file)
@@ -196,6 +203,10 @@ def main():
196203
.replace('$$APP$$', granite_app) \
197204
.replace('$$GRANITE_ANDROID_ACTIVITY_PATH$$', granite_android_activity)
198205

206+
if args.activity_path:
207+
android_activity = find_relative_path(output_settings_gradle, args.activity_path)
208+
data = data.replace('$$ANDROID_ACTIVITY_PATH$$', android_activity)
209+
199210
with open(output_settings_gradle, 'w') as dump_file:
200211
print(data, file = dump_file)
201212

0 commit comments

Comments
 (0)