Skip to content

Commit

Permalink
Update FAQs on APK size and obfuscation
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsmith committed Mar 1, 2025
1 parent 7b22f59 commit 47b297b
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions product/runtime/docs/sphinx/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,52 +56,47 @@ the way Chaquopy packages its native components, the `APK splits
<https://developer.android.com/studio/build/configure-apk-splits.html>`_ and `app bundle
<https://developer.android.com/guide/app-bundle/>`_ features won't help much. Instead, use a
`product flavor dimension
<https://developer.android.com/studio/build/build-variants.html#product-flavors>`_ to build
separate APKs or app bundles for each ABI. If you plan to release your app on Google Play, each
flavor must also have a `different version code
<https://developer.android.com/google/play/publishing/multiple-apks#VersionCodes>`_. For
example:
<https://developer.android.com/studio/build/build-variants.html#product-flavors>`_, like
this:

.. tabs::

.. code-tab:: kotlin

android {
val versionBase = 123
flavorDimensions += "abi"
productFlavors {
create("arm32") {
create("development") {
dimension = "abi"
ndk { abiFilters += listOf("armeabi-v7a") }
versionCode = 1000000 + versionBase
ndk { abiFilters += listOf("arm64-v8a", "x86_64") }
}
create("arm64") {
create("production") {
dimension = "abi"
ndk { abiFilters += listOf("arm64-v8a") }
versionCode = 2000000 + versionBase
}
}
}

.. code-tab:: groovy

android {
def versionBase = 123
flavorDimensions "abi"
productFlavors {
create("arm32") {
create("development") {
dimension = "abi"
ndk { abiFilters "armeabi-v7a" }
versionCode = 1000000 + versionBase
ndk { abiFilters "arm64-v8a", "x86_64" }
}
create("arm64") {
create("production") {
dimension = "abi"
ndk { abiFilters "arm64-v8a" }
versionCode = 2000000 + versionBase
}
}
}

If you plan to release multiple flavors on Google Play, each flavor must also have a
`different version code
<https://developer.android.com/google/play/publishing/multiple-apks#VersionCodes>`_.

If your app uses TensorFlow, consider replacing it with `TensorFlow Lite
<https://www.tensorflow.org/lite/guide>`_:

Expand All @@ -119,10 +114,17 @@ How can I obfuscate my code?
----------------------------

As described :ref:`here <android-bytecode>`, your code is automatically compiled to .pyc
format if possible. To make the build fail if a compatible Python version isn't found,
you can use the `src = true` setting.
format if possible. To make this a required build step, use the `src = true` setting.

If you want to perform additional obfuscation:

* Store the original copy of your code in a different directory.
* In your build.gradle file, add an `afterEvaluate` block `like this
one <https://github.com/chaquo/chaquopy/blob/16.0.0/demo/app/build.gradle.kts#L7>`__,
which copies the code to `src/main/python` while making whatever modifications you
want.

If you want to hide your code further, you can compile it into an .so file using Cython
To hide your code even further, you could compile it into an .so file using Cython
and our package build tool. For more details, see `here
<https://github.com/chaquo/chaquopy/issues/800#issuecomment-1413451177>`_.

Expand Down

0 comments on commit 47b297b

Please sign in to comment.