Compiling with script encryption causes errors

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ggez

I followed the documentation: Compiling with PCK encryption key — Godot Engine (stable) documentation in English

Problem: I want to export for android with script encryption. I get same errors as on this page. ERROR: open_and_parse: Condition [...bla bla...] on Android.

Godot version: 3.2.4.beta1

Windows 10


Exact steps I did:

  • Created a key with openssl.
  • Set set SCRIPT_AES256_ENCRYPTION_KEY=your_generated_key
  • Executed following commands:

scons -j 6 platform=android target=release android_arch=armv7
scons -j 6 platform=android target=release android_arch=arm64v8
cd platform/android/java
.\gradlew generateGodotTemplates

Copied the bin/android_release.apk to %appdata%\Roaming\Godot\templates\3.2.4.beta1\

scons platform=android target=release_debug
android_arch=armv7 scons platform=android target=release_debug
android_arch=arm64v8 cd platform/android/java
.\gradlew generateGodotTemplates

Copied the bin/android_debug.apk to %appdata%\Roaming\Godot\templates\3.2.4.beta1\

In Godot:

  • Under android export > script, I set the key in the input field and
    set export mode to encrypted.
  • Under android export > options > Custom Template, I set the debug and
    release accordingly to C:/godot/bin/android_debug.apk and C:/godot/bin/android_release.apk

Then exported to android (and it crashes right after starting the game, it flickers a bit and then crashes). Adb logcat shows same errors as here. Note: it does not crash when exporting normally. Any help?

On the same link (top of the page), it says: Godot is encrypting the scripts during export, but can’t read them at runtime. Well, what should I do?

I’m quite unfamiliar with this process, but looking over your steps…

I see that you built the Godot export templates (presumably with your encryption key) and copied them to, for example, %appdata%\Roaming\Godot\templates\3.2.4.beta1\.

However, later, in Godot, you specified your custom template to be within C:/godot/bin/.

That doesn’t seem right. Shouldn’t that point to the custom templates you built?

jgodfrey | 2020-11-23 19:26

Hi. Since the compiled templates are the same as the one that I copied to %appdata%\Roaming\Godot\templates\3.2.4.beta1\ it does not make a difference (both files are the same). This is mentioned here too.

You don't even need to copy them, you can just reference the resulting file in the bin\ directory of your Godot source folder, so that the next time you build you will automatically have the custom templates referenced.

ggez | 2020-11-23 19:31

Again, I’m not familiar with this, but… I feel like the ones you compiled are different in that they include your encryption key. Just as a test, what happens if you point to the ones you compiled instead?

jgodfrey | 2020-11-23 19:44

But, yeah, I see what you mean with your docs reference. It does sound like it’s not necessary to point to the custom files, but since it doesn’t attempt to explain the magic that makes that auto-referencing mechanism work, I’m skeptical - especially since your problem is caused by not having your key properly included…

jgodfrey | 2020-11-23 19:53

Do you mean like this? Imgur: The magic of the Internet
If you meant like this, it unfortunately did not change anything. Leaving these empty also does not solve the problem.

ggez | 2020-11-23 20:22

I was suggesting that you set those two values to the templates you complied. So, set them to the 2 files you copied into %appdata%\Roaming\Godot\templates\3.2.4.beta1\

jgodfrey | 2020-11-23 20:36

I see. It unfortunately did not work. I set them like this:

C:/Users/###/AppData/Roaming/Godot/templates/3.2.4.beta1/android_debug.apk

C:/Users/###AppData/Roaming/Godot/templates/3.2.4.beta1/android_release.apk

I feel like I tried almost everything. I know you’re not very familiar with this, but if you do know about this, could the problem be eventually this line… set SCRIPT_AES256_ENCRYPTION_KEY=your_generated_key
I set this in the terminal before running the scons commands.

ggez | 2020-11-23 20:46

To be precise, when you set that environment variable, I assume you replaced the your_generated_key string with the actual key you generated, right?

jgodfrey | 2020-11-23 20:49

Correct. I was just wondering if this should be done in the terminal or somewhere else. But i guess its in the terminal inside the godot source folder.

ggez | 2020-11-23 20:54

Again, just guessing… But, I assume setting it the terminal you ran all of the build commands from is exactly right. I assume the build uses that specific variable to access your custom key during the build process…

jgodfrey | 2020-11-23 20:57

After setting the variable in a command terminal, it should be available to any process that’s started from that same terminal. However, if you ran any of the commands from a different command terminal (or ran any commands before setting the variable), the encryption key would not have been available to those processes…

jgodfrey | 2020-11-23 20:59