<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: A. Ababa</title>
    <description>The latest articles on DEV Community by A. Ababa (@better_call_sriz).</description>
    <link>https://dev.to/better_call_sriz</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1074047%2F455f1780-23d0-4e43-afd7-65cf1c29eddb.png</url>
      <title>DEV Community: A. Ababa</title>
      <link>https://dev.to/better_call_sriz</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/better_call_sriz"/>
    <language>en</language>
    <item>
      <title>Porting a Pygame Game from Arch (BTW) to Android (By losing my mind so you don’t have to)</title>
      <dc:creator>A. Ababa</dc:creator>
      <pubDate>Tue, 20 Jan 2026 21:32:31 +0000</pubDate>
      <link>https://dev.to/better_call_sriz/porting-a-pygame-game-from-arch-btw-to-android-by-losing-my-mind-so-you-dont-have-to-19d4</link>
      <guid>https://dev.to/better_call_sriz/porting-a-pygame-game-from-arch-btw-to-android-by-losing-my-mind-so-you-dont-have-to-19d4</guid>
      <description>&lt;h3&gt;
  
  
  &lt;strong&gt;Introduction&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;If you have ever tried to run &lt;code&gt;buildozer android debug&lt;/code&gt; on a rolling-release distribution like Arch Linux, you probably know the pain. It usually starts with a simple command and ends with you staring at &lt;em&gt;gcc compiler logs&lt;/em&gt; at 3 AM, wondering why &lt;em&gt;longintrepr.h&lt;/em&gt; is missing.&lt;/p&gt;

&lt;h4&gt;
  
  
  Table of Contents
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;The Golden Stack (TL;DR)&lt;/li&gt;
&lt;li&gt;Step 1: System Prerequisites&lt;/li&gt;
&lt;li&gt;Step 2: The Virtual Environment&lt;/li&gt;
&lt;li&gt;Step 3: The "Flag Sanitization" Patch&lt;/li&gt;
&lt;li&gt;Step 4: Building the APK&lt;/li&gt;
&lt;li&gt;Troubleshooting Cheatsheet&lt;/li&gt;
&lt;li&gt;Final Thoughts&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;The Golden Stack (TL;DR)&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Android cross-compilation is fragile. If you mix the wrong versions of &lt;em&gt;Python, Cython,&lt;/em&gt; and &lt;em&gt;Java&lt;/em&gt;, the build fails. Here is the exact combination that works in 2026:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Tool&lt;/th&gt;
&lt;th&gt;Version&lt;/th&gt;
&lt;th&gt;The Why&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Python&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;3.11&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;3.12+ removed &lt;code&gt;distutils&lt;/code&gt;, breaking many Android recipes.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Cython&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;&amp;lt; 3.0.0&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Cython 3.0 removed &lt;code&gt;longintrepr.h&lt;/code&gt;, breaking Kivy/Pygame recipes.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Java&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;JDK 17&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Required by the latest Android SDK/Gradle.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h4&gt;
  
  
  Step 1: System Prerequisites
&lt;/h4&gt;

&lt;p&gt;Arch is "bare bones," so we need to manually fetch the headers that &lt;em&gt;&lt;code&gt;python-for-android&lt;/code&gt; (p4a)&lt;/em&gt; needs to compile the recipes.&lt;/p&gt;

&lt;p&gt;Run the following in your terminal to install the build toolchain and headers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Update everything first
sudo pacman -Syu


# Install the build toolchain and headers
# We need jdk17-openjdk for Gradle and base-devel for gcc/make
sudo pacman -S git zip unzip jdk17-openjdk python pip python-virtualenv \
    base-devel autoconf libtool pkg-config zlib ncurses cmake libffi openssl
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 2: The Virtual Environment (DO NOT SKIP THIS)
&lt;/h4&gt;

&lt;p&gt;Never install &lt;em&gt;Buildozer&lt;/em&gt; or &lt;em&gt;Cython&lt;/em&gt; globally on Arch. System updates will break your build toolchain. We need an isolated environment where we can pin older versions of &lt;em&gt;Cython&lt;/em&gt; without messing up the system.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# 1. Create the venv with Python 3.11
python3.11 -m venv .venv


# 2. Activate it
source .venv/bin/activate


# 3. Install the specific versions
# We pin Cython &amp;lt; 3.0 to fix the "longintrepr.h" error
pip install "Cython&amp;lt;3.0" "setuptools&amp;lt;71.0.0" buildozer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 3: The "Flag Sanitization" Patch
&lt;/h4&gt;

&lt;p&gt;This was the hardest bug to track down.&lt;/p&gt;

&lt;p&gt;On Arch Linux, the system compilers are configured with aggressive security and optimization flags like &lt;code&gt;-fcf-protection&lt;/code&gt; (Intel Control-flow enforcement) and &lt;code&gt;-march=x86-64&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;When &lt;em&gt;Buildozer&lt;/em&gt; runs, it sometimes leaks these Host Flags into the Target (Android) build process. The Android NDK compiler sees &lt;code&gt;-march=x86-64&lt;/code&gt;, panics because it's trying to build for ARM, and crashes with cryptic errors.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Fix:&lt;/strong&gt; We need to "sanitize" the environment variables in the recipe before the build starts.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Navigate to the pygame recipe inside your hidden .buildozer directory. It is usually located here: &lt;code&gt;.buildozer/android/platform/python-for-android/pythonforandroid/recipes/pygame/__init__.py&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Locate the &lt;code&gt;build_armeabi_v7a&lt;/code&gt; method and inject this sanitation logic:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import re


# ... inside the build_armeabi_v7a method ...
env = self.get_recipe_env(arch)


# 🧹 THE SANITIZER
# Strip flags that break ARM builds (like x86 specific protections)
bad_flags = [
    r'-m(arch|tune|cpu)=\S+',      # e.g., -march=x86-64
    r'-fcf-protection(=\S+)?',     # Intel specific
    r'-fno-plt'                    # PLT hardening
]


for var in ['CFLAGS', 'LDFLAGS']:
    if var in env:
        for pattern in bad_flags:
            env[var] = re.sub(pattern, '', env[var])


# ... proceed with the build ...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This simple script strips the x86 flags before they reach the NDK.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 4: Building the APK
&lt;/h4&gt;

&lt;p&gt;Now that our environment is clean and our flags are sanitized, we can build.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CRITICAL:&lt;/strong&gt; You must export your local &lt;code&gt;venv&lt;/code&gt; path before building. If you don't, &lt;em&gt;Buildozer&lt;/em&gt; might use the system &lt;em&gt;Cython (v3.0+)&lt;/em&gt; and fail.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Force the build to use our local venv tools
export PATH="$(pwd)/.venv/bin:$PATH"


# Build the debug APK
buildozer android debug
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Download the Android SDK/NDK (takes a while the first time).&lt;/li&gt;
&lt;li&gt;Compile Python 3.11 for ARM.&lt;/li&gt;
&lt;li&gt;Package your Pygame app.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If everything goes well, you’ll see the glorious &lt;code&gt;Application pushed.&lt;/code&gt; message.&lt;/p&gt;

&lt;h3&gt;
  
  
  Troubleshooting Cheatsheet
&lt;/h3&gt;

&lt;p&gt;If (when) things break, here is your rescue kit.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. The &lt;strong&gt;"longintrepr.h not found"&lt;/strong&gt; Error
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Cause:&lt;/strong&gt; You are using &lt;em&gt;Cython 3.0+&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fix:&lt;/strong&gt; Run &lt;code&gt;pip install "Cython&amp;lt;3.0"&lt;/code&gt; and check your &lt;code&gt;PATH&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  2. The App Crashes Immediately
&lt;/h4&gt;

&lt;p&gt;Buildozer hides the Python errors. You need &lt;code&gt;logcat&lt;/code&gt; to see why your game crashed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Filter specifically for Python crashes
adb logcat -s python studio.flappybird.game
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. "Get Android SDK" Hangs
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Cause: You need to accept a license agreement.&lt;/li&gt;
&lt;li&gt;Fix: Run the command in the foreground first, or check your internet connection.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Final Thoughts
&lt;/h3&gt;

&lt;p&gt;Porting to Android doesn't have to be a nightmare, but on Linux (Arch BTW), you have to respect the toolchain. By pinning your dependencies and sanitizing your compiler flags, you can build reliable APKs even on a bleeding-edge distro like Arch.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Happy Coding!&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>android</category>
      <category>archlinux</category>
      <category>gamedev</category>
    </item>
  </channel>
</rss>
