Cannot embed godot game in android project with .pck or .zip

Godot Version

godot-4

Question

I am unable to run my game in android without including my source code in the assets folder. The documentation says I should use --main-pack <pck_or_zip_filepath_relative_to_assets_dir> but after exporting my game to the assets folder as game.pck and setting the commandline to --main-pack game.pck I get the following error:

1: USER ERROR: Cannot open resource pack ‘game.pck’.
2: at: _setup (core/config/project_settings.cpp:534)
3: Error: Couldn’t load project data at path “.”. Is the .pck file missing?
4: If you’ve renamed the executable, the associated .pck file should also be renamed to match the executable’s name (without the extension).
5: Unable to setup the Godot engine! Aborting…

At this point I thought maybe the .zip will work but when doing that I get the following error:

1: USER ERROR: Condition “f.is_null()” is true. Returning: nullptr
2: at: godot_open (core/io/file_access_zip.cpp:51)
3: USER ERROR: Parameter “zfile” is null.
4: at: try_open_pack (core/io/file_access_zip.cpp:171)
5: USER ERROR: Cannot open resource pack ‘project.zip’.
6: at: _setup (core/config/project_settings.cpp:534)
7: Error: Couldn’t load project data at path “.”. Is the .pck file missing?
8: If you’ve renamed the executable, the associated .pck file should also be renamed to match the executable’s name (without the extension).
9: Unable to setup the Godot engine! Aborting…

Including all my game files in the assets dir without using --main-pack works but I would prefer not contain all my game code there.

1 Like

Hey! I hope this is still relevant :slight_smile:
I’ve been able to work around this by doing the following:

  1. Export your game as a .zip as you’re doing now
  2. Extrack this zip into the assets folder of your android project (src/main/assets by default)
  3. Remove --main-pack argument from command line

I follow you steps but found the same error :sob:
this is my code below,

@Override
    public List<String> getCommandLine() {
        return List.of("game.zip");
    }

and I put the game.zip in the src/main/assets.
So is some steps I did were not correct?
Thanks in advance

Hm, I don’t think you need to override getCommandLine function all together. Have you tried without it?

I export my godot project in windows platform and excute
“Godot_Demo.console.exe Godot_Demo.pck” , it works .
But in android platform , I don’t know how to embed the .pck or .zip if I do not override the getCommandLine() function. If you don’t mind, could you show me your sample code?
Thank you so much

This Godot Android library — Godot Engine (stable) documentation in English is the approach that I’ve been using. And here is the sample mentioned there: Godot-Android-Samples/apps/gltf_viewer at master · m4gr3d/Godot-Android-Samples · GitHub

My approach is the same and they also don’t override getCommandLine function

The sample app provided by official is that put all godot code and art assets in src/main/assets, but actually I don’t want to expose my godot code.I followed the document and found that it is possible to create the Godot project in a separate directory and export it as a .pck file. Then put the .pck file exported into src/main/assets.

However, after my continuous attampts , I finailly succeeded. :grinning: My code is as follows:
@Override
public List getCommandLine() {
return List.of(“–main-pack”,“res://game.pck”);
}

Indeed
What I’m saying is that if you extract that .pck into the assets folder then you wouldn’t need getCommandLine at all.

Anyway, I’m glad that worked out for you! :slight_smile:

1 Like

There is a commandline/extra_args option in Android Export Preset. It is more convenient to set main pack option there.

BTW, how do you run the gradle build after repalcing the assets files? I tried to run gradle from command line, but it requires a lot of options. All the options are generated by Godot Android Export.

Sorry for the late reply. I opened the project through Android Studio. After replacing the asset, I built it using Gradle. It may need to download the Gradle plugin, and once the download is complete, you should be able to build the APK.
Hope this can help you.