Skip to content

Commit 897f3d4

Browse files
committed
more touch ups
1 parent da1149c commit 897f3d4

File tree

4 files changed

+38
-28
lines changed

4 files changed

+38
-28
lines changed

examples/minimal/README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
As of 2024-09-19, this is a thrown together, very quick copy-paste of the minimal example from the original [ZigAndroidTemplate](https://github.com/ikskuh/ZigAndroidTemplate/blob/master/examples/minimal/main.zig) repository.
44

5+
### Build and run natively on your operating system or install/run on Android device
6+
7+
```sh
8+
zig build run # Native
9+
zig build run -Dandroid # Android
10+
```
11+
512
### Build, install to test one target against a local emulator and run
613

714
```sh
@@ -13,7 +20,7 @@ adb shell am start -S -W -n com.zig.minimal/android.app.NativeActivity
1320
### Build and install for all supported Android targets
1421

1522
```sh
16-
zig build -Dandroid=true
23+
zig build -Dandroid
1724
adb install ./zig-out/bin/minimal.apk
1825
```
1926

examples/raylib/README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ ld.lld: warning: <path-to-project>/.zig-cache/o/4227869d730f094811a7cdaaab535797
77
```
88
You can ignore this error for now.
99

10+
### Build and run natively on your operating system or install/run on Android device
11+
12+
```sh
13+
zig build run # Native
14+
zig build run -Dandroid # Android
15+
```
16+
1017
### Build, install to test one target against a local emulator and run
1118

1219
```sh
@@ -18,16 +25,10 @@ adb shell am start -S -W -n com.zig.raylib/android.app.NativeActivity
1825
### Build and install for all supported Android targets
1926

2027
```sh
21-
zig build -Dandroid=true
28+
zig build -Dandroid
2229
adb install ./zig-out/bin/raylib.apk
2330
```
2431

25-
### Build and run natively on your operating system
26-
27-
```sh
28-
zig build run
29-
```
30-
3132
### Uninstall your application
3233

3334
If installing your application fails with something like:

examples/sdl2/README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
This is a copy-paste of [Andrew Kelly's SDL Zig Demo](https://github.com/andrewrk/sdl-zig-demo) but running on Android. The build is setup so you can also target your native operating system as well.
44

5+
### Build and run natively on your operating system or install/run on Android device
6+
7+
```sh
8+
zig build run # Native
9+
zig build run -Dandroid # Android
10+
```
11+
512
### Build, install to test one target against a local emulator and run
613

714
```sh
@@ -17,12 +24,6 @@ zig build -Dandroid=true
1724
adb install ./zig-out/bin/sdl-zig-demo.apk
1825
```
1926

20-
### Build and run natively on your operating system
21-
22-
```sh
23-
zig build run
24-
```
25-
2627
### Uninstall your application
2728

2829
If installing your application fails with something like:

src/androidbuild/tools.zig

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const std = @import("std");
22
const builtin = @import("builtin");
33
const androidbuild = @import("androidbuild.zig");
4+
const Allocator = std.mem.Allocator;
45

56
/// Used for reading install locations from the registry
67
const RegistryWtf8 = @import("WindowsSdk.zig").RegistryWtf8;
@@ -378,39 +379,39 @@ pub fn createOrGetLibCFile(tools: *Sdk, compile: *Step.Compile, android_api_leve
378379

379380
/// Search JDK_HOME, and then JAVA_HOME
380381
fn getJDKPath(allocator: std.mem.Allocator) error{OutOfMemory}![]const u8 {
381-
const jdkHome = std.process.getEnvVarOwned(allocator, "JDK_HOME") catch |err| switch (err) {
382+
const jdk_home = std.process.getEnvVarOwned(allocator, "JDK_HOME") catch |err| switch (err) {
382383
error.OutOfMemory => return error.OutOfMemory,
383384
error.EnvironmentVariableNotFound => &[0]u8{},
384385
// Windows-only
385386
error.InvalidWtf8 => @panic("JDK_HOME environment variable is invalid UTF-8"),
386387
};
387-
if (jdkHome.len > 0) {
388-
return jdkHome;
388+
if (jdk_home.len > 0) {
389+
return jdk_home;
389390
}
390391

391-
const javaHome = std.process.getEnvVarOwned(allocator, "JAVA_HOME") catch |err| switch (err) {
392+
const java_home = std.process.getEnvVarOwned(allocator, "JAVA_HOME") catch |err| switch (err) {
392393
error.OutOfMemory => return error.OutOfMemory,
393394
error.EnvironmentVariableNotFound => &[0]u8{},
394395
// Windows-only
395396
error.InvalidWtf8 => @panic("JAVA_HOME environment variable is invalid UTF-8"),
396397
};
397-
if (javaHome.len > 0) {
398-
return javaHome;
398+
if (java_home.len > 0) {
399+
return java_home;
399400
}
400401

401402
return &[0]u8{};
402403
}
403404

404405
/// Caller must free returned memory
405406
fn getAndroidSDKPath(allocator: std.mem.Allocator) error{OutOfMemory}![]const u8 {
406-
const androidHome = std.process.getEnvVarOwned(allocator, "ANDROID_HOME") catch |err| switch (err) {
407+
const android_home = std.process.getEnvVarOwned(allocator, "ANDROID_HOME") catch |err| switch (err) {
407408
error.OutOfMemory => return error.OutOfMemory,
408409
error.EnvironmentVariableNotFound => &[0]u8{},
409410
// Windows-only
410411
error.InvalidWtf8 => @panic("ANDROID_HOME environment variable is invalid UTF-8"),
411412
};
412-
if (androidHome.len > 0) {
413-
return androidHome;
413+
if (android_home.len > 0) {
414+
return android_home;
414415
}
415416

416417
// Check for Android Studio
@@ -567,8 +568,8 @@ const PathSearch = struct {
567568

568569
// setup binaries to search for
569570
const exe_suffix = if (host_os_tag == .windows) ".exe" else "";
570-
const adb = std.mem.concat(allocator, u8, &.{ "adb", exe_suffix }) catch |err| return err;
571-
const jarsigner = std.mem.concat(allocator, u8, &.{ "jarsigner", exe_suffix }) catch |err| return err;
571+
const adb = try std.mem.concat(allocator, u8, &.{ "adb", exe_suffix });
572+
const jarsigner = try std.mem.concat(allocator, u8, &.{ "jarsigner", exe_suffix });
572573

573574
const path_it = std.mem.splitScalar(u8, path_env, ';');
574575
return .{
@@ -586,7 +587,7 @@ const PathSearch = struct {
586587
}
587588

588589
/// Get the Android SDK Path, the caller owns the memory
589-
pub fn findAndroidSDK(self: *PathSearch, allocator: std.mem.Allocator) error{OutOfMemory}![]const u8 {
590+
pub fn findAndroidSDK(self: *PathSearch, allocator: std.mem.Allocator) Allocator.Error![]const u8 {
590591
if (self.android_sdk_path == null) {
591592
// Iterate over PATH environment folders until we either hit the end or the Android SDK folder
592593
try self.getNext(.androidsdk);
@@ -598,7 +599,7 @@ const PathSearch = struct {
598599
}
599600

600601
/// Get the JDK Path, the caller owns the memory
601-
pub fn findJDK(self: *PathSearch, allocator: std.mem.Allocator) error{OutOfMemory}![]const u8 {
602+
pub fn findJDK(self: *PathSearch, allocator: std.mem.Allocator) Allocator.Error![]const u8 {
602603
if (self.jdk_path == null) {
603604
// Iterate over PATH environment folders until we either hit the end or the Android SDK folder
604605
try self.getNext(.jdk);
@@ -614,7 +615,7 @@ const PathSearch = struct {
614615
jdk,
615616
};
616617

617-
fn getNext(self: *PathSearch, path: PathType) error{OutOfMemory}!void {
618+
fn getNext(self: *PathSearch, path: PathType) Allocator.Error!void {
618619
const allocator = self.allocator;
619620
while (self.path_it.next()) |path_item| {
620621
if (path_item.len == 0) continue;

0 commit comments

Comments
 (0)