Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android support #10

Merged
merged 1 commit into from
May 30, 2024
Merged

Android support #10

merged 1 commit into from
May 30, 2024

Conversation

TheBearodactyl
Copy link
Contributor

No description provided.

@FlafyDev
Copy link
Owner

Thanks! I remember trying to run an android build of the mod and it crashed on startup. I will try your changes soon. (Assuming this PR is ready)

Also, it seems ANSongCell::setSong() was reverted to a few commits ago here

@TheBearodactyl
Copy link
Contributor Author

Thanks! I remember trying to run an android build of the mod and it crashed on startup. I will try your changes soon. (Assuming this PR is ready)

Also, it seems ANSongCell::setSong() was reverted to a few commits ago here

there is one problem. i just need to figure out how to make the Android specific directory if it doesn't exist. I've tried a few different ways of doing it but they've all just crashed the game :(

@TheBearodactyl
Copy link
Contributor Author

@FlafyDev it's ready for merging, i solved pretty much the only problem lol

@FlafyDev
Copy link
Owner

Ok, thanks!
I'll Soon merge it to an intermediate branch so I can work on it a bit and:

  • Fix the function ANSongCell::setSong() that seem to have been reverted to a few commits ago in this PR.
  • Clean the code where I can

@TheBearodactyl
Copy link
Contributor Author

Ok, thanks! I'll Soon merge it to an intermediate branch so I can work on it a bit and:

  • Fix the function ANSongCell::setSong() that seem to have been reverted to a few commits ago in this PR.
  • Clean the code where I can

i can probably just do that lol

@TheBearodactyl
Copy link
Contributor Author

also, I reverted the setSong function because Android doesn't like try/catch

@TheBearodactyl
Copy link
Contributor Author

@FlafyDev I fixed the code looking bad, lemme make an android friendly version of the newer setSong version real quick

@TheBearodactyl
Copy link
Contributor Author

@FlafyDev Should be good to merge now, everything is cleaned up and formatted, and the setSong function has been updated to the latest version with some modifications for Android (because Android doesn't like try/catch)

@FlafyDev
Copy link
Owner

FlafyDev commented May 29, 2024

image
oh it seems you changed the formatter settings so it left a lot of changes
image

I prefer not to do that (at least not in this PR) as it obscures history. And There isn't really a need for a new formatter settings.

@TheBearodactyl
Copy link
Contributor Author

image oh it seems you changed the formatter settings so it left a lot of changes image

I prefer not to do that (at least not in this PR) as it obscures history. And There isn't really a need for a new formatter settings.

I can revert the formatter settings real quick, and the squashed commit has all of the changes logged in it, so that shouldn't be too much of a problem.

  - Uses a different dir for NONGs on Android
  - Makes the dir if it doesn't already exist
  - Update `setSong` to be Android friendly
  - Uncomment android build commands for actions
  - (OBSELETE/REDACTED) Update `.clang-format` for better code readability
  - (OBSELETE/REDACTED) Format ALL `cpp/hpp` files based on new `.clang-format`
@TheBearodactyl
Copy link
Contributor Author

it is done

@FlafyDev FlafyDev changed the base branch from main to android May 30, 2024 01:10
@FlafyDev FlafyDev merged commit f3260a6 into FlafyDev:android May 30, 2024
@FlafyDev
Copy link
Owner

FlafyDev commented May 30, 2024

@TheBearodactyl

There seem to be a lot of unnecessary changes(like the Rust like types). And some formatting issues. I reverted these back. Is it correct that these are all the necessary changes for android support?

diff --git a/.github/workflows/multi-platform.yml b/.github/workflows/multi-platform.yml
index 01d6d83..d6172ef 100644
--- a/.github/workflows/multi-platform.yml
+++ b/.github/workflows/multi-platform.yml
@@ -18,13 +18,13 @@ jobs:
         # - name: macOS
         #   os: macos-latest
 
-        # - name: Android32
-        #   os: ubuntu-latest
-        #   target: Android32
-        #
-        # - name: Android64
-        #   os: ubuntu-latest
-        #   target: Android64
+        - name: Android32
+          os: ubuntu-latest
+          target: Android32
+
+        - name: Android64
+          os: ubuntu-latest
+          target: Android64
 
     name: ${{ matrix.config.name }}
     runs-on: ${{ matrix.config.os }}
diff --git a/mod.json b/mod.json
index df955d3..df9ecb5 100644
--- a/mod.json
+++ b/mod.json
@@ -1,6 +1,9 @@
 {
 	"geode": "2.0.0-beta.27",
-	"gd": "2.204",
+	"gd": {
+		"win": "2.204",
+		"android": "2.205"
+	},
 	"version": "v0.0.3",
 	"id": "flafy.autonong",
 	"name": "Auto Nong",
diff --git a/src/ui/an_song_cell.cpp b/src/ui/an_song_cell.cpp
index b3e9dfa..eed58f9 100644
--- a/src/ui/an_song_cell.cpp
+++ b/src/ui/an_song_cell.cpp
@@ -143,21 +143,29 @@ void ANSongCell::setSong() {
 }
 
 fs::path ANSongCell::getFileDownloadPath(bool create) {
+#ifdef GEODE_IS_ANDROID
+  std::string baseDir = "/storage/emulated/0/nongs";
+  if (!fs::exists(baseDir)) {
+    fs::create_directories(baseDir);
+  }
+#else
+  std::string baseDir = Mod::get()->getSaveDir().string();
+#endif
+
   if (typeid(*m_anSong) == typeid(ANYTSong)) {
     const ANYTSong *ytSong = static_cast<ANYTSong *>(m_anSong);
     const std::string videoId = ytSong->m_ytId;
     if (create) {
-      fs::create_directory(fmt::format("{}\\youtube", Mod::get()->getSaveDir().string()));
+      fs::create_directories(fmt::format("{}/youtube", baseDir));
     }
-    return fmt::format("{}\\youtube\\{}.mp3", Mod::get()->getSaveDir().string(), videoId);
+    return fmt::format("{}/youtube/{}.mp3", baseDir, videoId);
   }
   if (typeid(*m_anSong) == typeid(ANHostSong)) {
     const ANHostSong *hostSong = static_cast<ANHostSong *>(m_anSong);
     if (create) {
-      fs::create_directory(fmt::format("{}\\host", Mod::get()->getSaveDir().string()));
+      fs::create_directories(fmt::format("{}/host", baseDir));
     }
-    return fmt::format("{}\\host\\{}.mp3", Mod::get()->getSaveDir().string(),
-                       urlToFilename(hostSong->m_url));
+    return fmt::format("{}/host/{}.mp3", baseDir, urlToFilename(hostSong->m_url));
   }
   return "";
 }

Also, I tested your version but I'm crashing on startup when trying to decompress the indexes. Are you not crashing there?

I used an index that doesn't require decompression and managed to get in. I opened the auto nong menu and got another crash. This time there was a crashlog and after reading it it seems to crash on

create_directories: Permission denied ["/storage/emulated/0/nongs"]

Are you not experiencing any of these crashes?

@TheBearodactyl
Copy link
Contributor Author

TheBearodactyl commented May 30, 2024

@TheBearodactyl

There seem to be a lot of unnecessary changes(like the Rust like types). And some formatting issues. I reverted these back. Is it correct that these are all the necessary changes for android support?

diff --git a/.github/workflows/multi-platform.yml b/.github/workflows/multi-platform.yml
index 01d6d83..d6172ef 100644
--- a/.github/workflows/multi-platform.yml
+++ b/.github/workflows/multi-platform.yml
@@ -18,13 +18,13 @@ jobs:
         # - name: macOS
         #   os: macos-latest
 
-        # - name: Android32
-        #   os: ubuntu-latest
-        #   target: Android32
-        #
-        # - name: Android64
-        #   os: ubuntu-latest
-        #   target: Android64
+        - name: Android32
+          os: ubuntu-latest
+          target: Android32
+
+        - name: Android64
+          os: ubuntu-latest
+          target: Android64
 
     name: ${{ matrix.config.name }}
     runs-on: ${{ matrix.config.os }}
diff --git a/mod.json b/mod.json
index df955d3..df9ecb5 100644
--- a/mod.json
+++ b/mod.json
@@ -1,6 +1,9 @@
 {
 	"geode": "2.0.0-beta.27",
-	"gd": "2.204",
+	"gd": {
+		"win": "2.204",
+		"android": "2.205"
+	},
 	"version": "v0.0.3",
 	"id": "flafy.autonong",
 	"name": "Auto Nong",
diff --git a/src/ui/an_song_cell.cpp b/src/ui/an_song_cell.cpp
index b3e9dfa..eed58f9 100644
--- a/src/ui/an_song_cell.cpp
+++ b/src/ui/an_song_cell.cpp
@@ -143,21 +143,29 @@ void ANSongCell::setSong() {
 }
 
 fs::path ANSongCell::getFileDownloadPath(bool create) {
+#ifdef GEODE_IS_ANDROID
+  std::string baseDir = "/storage/emulated/0/nongs";
+  if (!fs::exists(baseDir)) {
+    fs::create_directories(baseDir);
+  }
+#else
+  std::string baseDir = Mod::get()->getSaveDir().string();
+#endif
+
   if (typeid(*m_anSong) == typeid(ANYTSong)) {
     const ANYTSong *ytSong = static_cast<ANYTSong *>(m_anSong);
     const std::string videoId = ytSong->m_ytId;
     if (create) {
-      fs::create_directory(fmt::format("{}\\youtube", Mod::get()->getSaveDir().string()));
+      fs::create_directories(fmt::format("{}/youtube", baseDir));
     }
-    return fmt::format("{}\\youtube\\{}.mp3", Mod::get()->getSaveDir().string(), videoId);
+    return fmt::format("{}/youtube/{}.mp3", baseDir, videoId);
   }
   if (typeid(*m_anSong) == typeid(ANHostSong)) {
     const ANHostSong *hostSong = static_cast<ANHostSong *>(m_anSong);
     if (create) {
-      fs::create_directory(fmt::format("{}\\host", Mod::get()->getSaveDir().string()));
+      fs::create_directories(fmt::format("{}/host", baseDir));
     }
-    return fmt::format("{}\\host\\{}.mp3", Mod::get()->getSaveDir().string(),
-                       urlToFilename(hostSong->m_url));
+    return fmt::format("{}/host/{}.mp3", baseDir, urlToFilename(hostSong->m_url));
   }
   return "";
 }

Also, I tested your version but I'm crashing on startup when trying to decompress the indexes. Are you not crashing there?

I used an index that doesn't require decompression and managed to get in. I opened the auto nong menu and got another crash. This time there was a crashlog and after reading it it seems to crash on

create_directories: Permission denied ["/storage/emulated/0/nongs"]

Are you not experiencing any of these crashes?

yes, in the action, uncommenting the thingies makes the github actions build for android. also, the changes in the paths make it android compatible since android paths use forward slashes, and \ is used for escaping characters in linux devices (Android is just weird linux). Also, no i haven't had any of those crashes. I added the create_directories thingy because the game crashes if the android specific directory doesn't already exist.

@FlafyDev
Copy link
Owner

I don't know how you had permission to write in /storage/emulated/0/nongs (Maybe another mod asked for perms and GD still had it). But changing back to

  std::string baseDir = Mod::get()->getSaveDir().string();

for Android as well made it work for me.

There is still the issue with the decompression, though. Not sure how to solve it. But everything else seem to work on both Android and Windows :D

@TheBearodactyl
Copy link
Contributor Author

TheBearodactyl commented May 30, 2024

I don't know how you had permission to write in /storage/emulated/0/nongs (Maybe another mod asked for perms and GD still had it). But changing back to

  std::string baseDir = Mod::get()->getSaveDir().string();

for Android as well made it work for me.

There is still the issue with the decompression, though. Not sure how to solve it. But everything else seem to work on both Android and Windows :D

@FlafyDev try setting the nong for a song with that, it won't work. also, you have to give the geode launcher filesystem perms in the app settings lol

@FlafyDev
Copy link
Owner

@FlafyDev try setting the nong for a song with that, it won't work. also, you have to give the geode launcher filesystem perms in the app settings lol

Setting the song through auto-nong still works.

This is also what jukebox does
https://github.com/Fleeym/jukebox/blob/035e7c5f2f237c978cfac294c8b4b56cfc7fbaa5/src/managers/nong_manager.cpp#L326
and jukebox works on android just fine

@FlafyDev
Copy link
Owner

Figured it out. for some reason it takes time for my android device to decompress the entire json, but the code still continues... for smaller json files like official it manages to complete it before the next line uses the string. but for bigger files like sfh-rooot.json.gz it crashes.

I'll make a 1 second loop that checks if the string is empty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants