Skip to content

Commit

Permalink
android: Resolve windows build issues
Browse files Browse the repository at this point in the history
bin\install.ps1 wasn't copying libuv src files
(Caused silent crash on copy files)
Note we currently require
bin\install.ps1 --uv 1.x
until 1.44.5 can be set as the default option.
Also resolved android command line tool path issues for windows, this relies on ANDROID_HOME being set.
Also resolved --host option not being a valid argument
  • Loading branch information
mribbons authored and jwerle committed Feb 1, 2023
1 parent 1e1d049 commit 00e2e6d
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 30 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ gradlew.bat
.settings/
.clang-format
.vimrc
.vscode
*.gradle*
compile_flags.txt
.classpath
Expand Down
7 changes: 5 additions & 2 deletions bin/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ Function Build {
Write-Output "ok - built libuv"

(New-Item -ItemType Directory -Force -Path "$WORKING_BUILD_PATH\lib") > $null
Copy-Item "$WORKING_BUILD_PATH\libuv\build\$LIBUV_BUILD_TYPE\uv_a.lib" -Destination "$WORKING_BUILD_PATH\lib\uv_a.lib"
Copy-Item "$WORKING_BUILD_PATH\libuv\build\uv_a.lib" -Destination "$WORKING_BUILD_PATH\lib\uv_a.lib"
if ($debug -eq $true) {
Copy-Item "$WORKING_BUILD_PATH\libuv\build\$LIBUV_BUILD_TYPE\uv_a.pdb" -Destination "$WORKING_BUILD_PATH\lib\uv_a.pdb"
Copy-Item "$WORKING_BUILD_PATH\libuv\build\uv_a.pdb" -Destination "$WORKING_BUILD_PATH\lib\uv_a.pdb"
}

(New-Item -ItemType Directory -Force -Path "$WORKING_BUILD_PATH\include") > $null
Expand Down Expand Up @@ -84,6 +84,9 @@ Function Install-Files {
(New-Item -ItemType Directory -Force -Path "$SRC_PATH") > $null
(New-Item -ItemType Directory -Force -Path "$INCLUDE_PATH") > $null

# install `.\build\uv\src`
Copy-Item -Path "$WORKING_BUILD_PATH\libuv\src" -Destination "$ASSET_PATH\uv\src" -Recurse -Force

# install `.\src\*`
Copy-Item -Path "$WORKING_PATH\src\*" -Destination "$SRC_PATH" -Recurse -Force -Container

Expand Down
81 changes: 53 additions & 28 deletions src/cli/cli.cc
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ int main (const int argc, const char* argv[]) {
exit(0);
});

createSubcommand("build", { "--platform", "--port", "--quiet", "-o", "-r", "--prod", "-p", "-c", "-s", "-e", "-n", "--test", "--headless" }, true, [&](const std::span<const char *>& options) -> void {
createSubcommand("build", { "--platform", "--host", "--port", "--quiet", "-o", "-r", "--prod", "-p", "-c", "-s", "-e", "-n", "--test", "--headless" }, true, [&](const std::span<const char *>& options) -> void {
bool flagRunUserBuildOnly = false;
bool flagAppStore = false;
bool flagCodeSign = false;
Expand All @@ -855,10 +855,15 @@ int main (const int argc, const char* argv[]) {
String targetPlatform = "";
String testFile = "";

String hostArg = "";
String portArg = "";
String devHost("localhost");
String devPort("0");
auto cnt = 0;

String localDirPrefix = !platform.win ? "./" : "";
String quote = !platform.win ? "'" : "\"";

for (auto const arg : options) {
if (is(arg, "-h") || is(arg, "--help")) {
printHelp("build");
Expand Down Expand Up @@ -939,21 +944,28 @@ int main (const int argc, const char* argv[]) {
}
}

auto host = optionValue(arg, "--host");
if (host.size() > 0) {
devHost = host;
} else {
if (flagBuildForIOS || flagBuildForAndroid) {
auto r = exec("ifconfig | grep -w 'inet' | awk '!match($2, \"^127.\") {print $2; exit}' | tr -d '\n'");
if (r.exitCode == 0) {
devHost = r.output;
if (hostArg.size() == 0) {
hostArg = optionValue(arg, "--host");
if (hostArg.size() > 0) {
devHost = hostArg;
} else {
if (flagBuildForIOS || flagBuildForAndroid) {
auto r = exec((!platform.win) ?
"ifconfig | grep -w 'inet' | awk '!match($2, \"^127.\") {print $2; exit}' | tr -d '\n'" :
"PowerShell -Command ((Get-NetIPAddress -AddressFamily IPV4).IPAddress ^| Select-Object -first 1)"
);
if (r.exitCode == 0) {
devHost = r.output;
}
}
}
}

auto port = optionValue(arg, "--port");
if (port.size() > 0) {
devPort = port;
if (portArg.size() == 0) {
portArg = optionValue(arg, "--port");
if (portArg.size() > 0) {
devPort = portArg;
}
}
}

Expand Down Expand Up @@ -1646,7 +1658,7 @@ int main (const int argc, const char* argv[]) {
// Windows Package Prep
// ---
//
if (platform.win) {
if (platform.win && !flagBuildForAndroid && !flagBuildForIOS) {
log("preparing build for win");
auto prefix = prefixFile();

Expand Down Expand Up @@ -1974,6 +1986,10 @@ int main (const int argc, const char* argv[]) {
StringStream packages;
StringStream gradlew;

if (settings["android_accept_sdk_licenses"].size() > 0) {
sdkmanager << "echo " << settings["android_accept_sdk_licenses"] << "|";
}

if (platform.unix) {
gradlew
<< "ANDROID_HOME=" << androidHome << " ";
Expand All @@ -1985,17 +2001,19 @@ int main (const int argc, const char* argv[]) {
}

packages
<< "'ndk;25.0.8775105' "
<< "'platform-tools' "
<< "'platforms;android-33' "
<< "'emulator' "
<< "'patcher;v4' "
<< "'system-images;android-33;google_apis;x86_64' "
<< "'system-images;android-33;google_apis;arm64-v8a' ";

if (!platform.win) {
if (std::system("sdkmanager --version 2>&1 >/dev/null") != 0) {
<< quote << "ndk;25.0.8775105" << quote << " "
<< quote << "platform-tools" << quote << " "
<< quote << "platforms;android-33" << quote << " "
<< quote << "emulator" << quote << " "
<< quote << "patcher;v4" << quote << " "
<< quote << "system-images;android-33;google_apis;x86_64" << quote << " "
<< quote << "system-images;android-33;google_apis;arm64-v8a" << quote << " ";

if (std::system("sdkmanager --version 2>&1 >/dev/null") != 0) {
if (!platform.win) {
sdkmanager << androidHome << "/cmdline-tools/latest/bin/";
} else {
sdkmanager << androidHome << "\\cmdline-tools\\latest\\bin\\";
}
}

Expand All @@ -2005,12 +2023,14 @@ int main (const int argc, const char* argv[]) {

if (std::system(sdkmanager.str().c_str()) != 0) {
log("error: failed to initialize Android SDK (sdkmanager)");
log("You may need to add accept_sdk_licenses = \"y\" to the [android] section of socket.ini.");
exit(1);
}

if (flagDebugMode) {
gradlew
<< "./gradlew :app:bundleDebug "
<< localDirPrefix
<< "gradlew :app:bundleDebug "
<< "--warning-mode all ";

if (std::system(gradlew.str().c_str()) != 0) {
Expand All @@ -2019,7 +2039,8 @@ int main (const int argc, const char* argv[]) {
}
} else {
gradlew
<< "./gradlew :app:bundle";
<< localDirPrefix
<< "gradlew :app:bundle";

if (std::system(gradlew.str().c_str()) != 0) {
log("error: failed to invoke `gradlew :app:bundle` command");
Expand All @@ -2029,7 +2050,9 @@ int main (const int argc, const char* argv[]) {

// clear stream
gradlew.str("");
gradlew << "./gradlew assemble";
gradlew
<< localDirPrefix
<< "gradlew assemble";

if (std::system(gradlew.str().c_str()) != 0) {
log("error: failed to invoke `gradlew assemble` command");
Expand All @@ -2044,7 +2067,8 @@ int main (const int argc, const char* argv[]) {
if (std::system("avdmanager list 2>&1 >/dev/null") != 0) {
avdmanager << androidHome << "/cmdline-tools/latest/bin/";
}
}
} else
avdmanager << androidHome << "\\cmdline-tools\\latest\\bin\\";

avdmanager
<< "avdmanager create avd "
Expand All @@ -2068,7 +2092,8 @@ int main (const int argc, const char* argv[]) {
if (std::system("adb --version 2>&1 >/dev/null") != 0) {
adb << androidHome << "/platform-tools/";
}
}
} else
adb << androidHome << "\\platform-tools\\";

adb
<< "adb "
Expand Down

0 comments on commit 00e2e6d

Please sign in to comment.