chaquo / chaquopy

Chaquopy: the Python SDK for Android
https://chaquo.com/chaquopy/
MIT License
748 stars 127 forks source link

Could the assets files be abi filtered? #1190

Closed anonyein closed 2 days ago

anonyein commented 2 days ago

Chaquopy version

15.0.1

Relevant parts of your build.gradle file

    ndk {
        abiFilters 'x86', 'x86_64', 'armeabi-v7a', "arm64-v8a" 
    }
    chaquopy {
        defaultConfig {
            version = "3.8"
            pip {
                options "--extra-index-url", "https://pypi.org/project"
                install "-r", "src/main/python/requirements.txt"
            }
        }
        productFlavors {

        }
        sourceSets {
            getByName("main") {
                srcDir("src/main/python")
            }
        }
    }

Describe your issue

Could the assets files be abi filtered? The size of app is too large when the requirement file contains many modules? image the requirements imys could be abi filtered?

IsakTheHacker commented 2 days ago
flavorDimensions = ["abi"]
productFlavors { private final NamedDomainObjectContainer<ProductFlavor> _productFlavors ->
    universal { private final ProductFlavor _productFlavor ->
        isDefault true
        dimension "abi"

        //If you want to have a universal fat apk, you NEED to put the abiFilters here and not in the defaultConfig.
        //Otherwise, all assets for all ABIs will be included in all other specialized product flavors.
        //I had this configuration unknowingly for the past year (even thought it was a bug in Chaquopy, check my other issues)
        //It was a nightmare to finally figure it out, so I am really glad to be able to help here
        ndk { private final NdkOptions _ndkOptions ->
            abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
        }
    }
    arm32 { private final ProductFlavor _productFlavor ->
        dimension "abi"
        ndk { private final NdkOptions _ndkOptions ->
            //noinspection ChromeOsAbiSupport
            abiFilters "armeabi-v7a"
        }
    }
    arm64 { private final ProductFlavor _productFlavor ->
        dimension "abi"
        ndk { private final NdkOptions _ndkOptions ->
            //noinspection ChromeOsAbiSupport
            abiFilters "arm64-v8a"
        }
    }
    x86 { private final ProductFlavor _productFlavor ->
        dimension "abi"
        ndk { private final NdkOptions _ndkOptions ->
            //noinspection ChromeOsAbiSupport
            abiFilters "x86"
        }
    }
    amd64 { private final ProductFlavor _productFlavor ->
        dimension "abi"
        ndk { private final NdkOptions _ndkOptions ->
            //noinspection ChromeOsAbiSupport
            abiFilters "x86_64"
        }
    }
}

Hope that solves it for you :) Oh and by the way, you can remove the whole sourceSets block and the --extra-index-url argument since you're just redefining the Chaquopy defaults there. I wish you all the best bro

anonyein commented 2 days ago

it seems that in the gradle-7.5.1, class "ProductFlavor" and "ProductFlavor" can not be found

IsakTheHacker commented 2 days ago

You can just add this at the top of the file or remove those variables entirely:

import com.android.build.gradle.internal.dsl.NdkOptions
import com.android.build.gradle.internal.dsl.ProductFlavor
anonyein commented 2 days ago

You can just add this at the top of the file or remove those variables entirely:

import com.android.build.gradle.internal.dsl.NdkOptions
import com.android.build.gradle.internal.dsl.ProductFlavor

Thanks for your help!

mhsmith commented 2 days ago

There should be no need for any of the type declarations, so you can delete everything between private and ->.

For the Kotlin equivalent of this configuration, see the FAQ.