Skip to content

Commit

Permalink
Add support for custom activity impl.
Browse files Browse the repository at this point in the history
  • Loading branch information
Themaister committed Oct 3, 2024
1 parent fe21b75 commit db5e750
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion application/platforms/android/gradle/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<uses-feature android:name="android.hardware.vulkan.level" android:version="0" android:required="true"/>

<application android:label="@string/app_name" android:icon="@drawable/$$ICON$$">
<activity android:name="net.themaister.granite.GraniteActivity"
<activity android:name="$$ACTIVITY_NAME$$"
android:theme="@style/Application.Fullscreen"
android:launchMode="singleTask"
android:screenOrientation="landscape"
Expand Down
1 change: 1 addition & 0 deletions application/platforms/android/gradle/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,5 @@ dependencies {
implementation 'androidx.games:games-activity:2.0.2'
implementation 'androidx.games:games-controller:2.0.1'
implementation 'androidx.games:games-frame-pacing:2.1.0'
$$EXTRA_DEPENDENCIES$$
}
5 changes: 5 additions & 0 deletions application/platforms/android/gradle/settings_custom.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include 'granite:android'
project(':granite:android').projectDir = file('$$GRANITE_ANDROID_ACTIVITY_PATH$$')
include 'custom:android'
project(':custom:android').projectDir = file('$$ANDROID_ACTIVITY_PATH$$')
include '$$APP$$'
5 changes: 0 additions & 5 deletions application/platforms/android/src/main/AndroidManifest.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<!-- Base application theme. -->
<style name="Application.Fullscreen" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>"
<item name="android:windowContentOverlay">@null</item>
</style>
</resources>
15 changes: 13 additions & 2 deletions tools/create_android_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ def main():
parser.add_argument('--swappy',
help = 'Add Swappy support',
action = 'store_true')
parser.add_argument('--activity-name',
help = 'Use custom activity name')
parser.add_argument('--activity-path',
help = 'Path to custom Android activity code')

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

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

# Write out AndroidManifest.xml
with open(manifest, 'r') as f:
activity_name = args.activity_name if args.activity_name else 'net.themaister.granite.GraniteActivity'
manifest_data = f.read()
manifest_data = manifest_data \
.replace('$$ICON$$', args.activity_icon_drawable) \
.replace('$$NATIVE_TARGET$$', args.native_target) \
.replace('$$ACTIVITY_NAME$$', activity_name) \
.replace('$$VERSION_CODE$$', args.version_code) \
.replace('$$VERSION_NAME$$', args.version_name)

Expand Down Expand Up @@ -177,7 +183,8 @@ def main():
.replace('$$PHYSICS$$', 'ON' if args.physics else 'OFF') \
.replace('$$SHADER_OPTIMIZE$$', 'ON' if args.optimize else 'OFF') \
.replace('$$FOSSILIZE$$', 'ON' if args.fossilize else 'OFF') \
.replace('$$SWAPPY$$', 'ON' if args.swappy else 'OFF')
.replace('$$SWAPPY$$', 'ON' if args.swappy else 'OFF') \
.replace('$$EXTRA_DEPENDENCIES$$', "api project(':custom:android')" if args.activity_name else '')

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

if args.activity_path:
android_activity = find_relative_path(output_settings_gradle, args.activity_path)
data = data.replace('$$ANDROID_ACTIVITY_PATH$$', android_activity)

with open(output_settings_gradle, 'w') as dump_file:
print(data, file = dump_file)

Expand Down

0 comments on commit db5e750

Please sign in to comment.