androidandroid-studiocmakeandroid-ndk

How to compile native library for armv8?


I am compiling split apk's for four architectures x86,x86_64,armeabi-v7a and arm64-v8a. The app is working fine and loading native libraries fine on majority of devices. but on some devices The error occurs that unable to find mylibrary.so .in armv8 folder or in arm folder. here is my code to generate split apk's and genertes Unsatisfied Link Error

splits {
        // Configures multiple APKs based on ABI.
        abi {
            // Enables building multiple APKs per ABI.
            enable true


            // By default all ABIs are included, so use reset() and include to specify that we only
            // want APKs for x86, armeabi-v7a, and mips.
            reset()

            // Specifies a list of ABIs that Gradle should create APKs for.
            include "x86", "x86_64", "armeabi-v7a", "arm64-v8a"

            // Specifies that we want to also generate a universal APK that includes all ABIs.
            universalApk false
        }
    }



    def abiCodes = ['x86':0, 'x86_64':1, 'armeabi-v7a':2, 'arm64-v8a':3]
    android.applicationVariants.all { variant ->
        // Assigns a different version code for each output APK.
        variant.outputs.each {
            output ->
                def abiName = output.getFilter(OutputFile.ABI)
                output.versionCodeOverride = abiCodes.get(abiName, 0) + variant.versionCode
        }
    }

when i analyze apk i succesfully get required native libs in arm64-v8a apk in libs folder and in libs folder of all other apk's.


Solution

  • Posting the answer to help others with the same issue:

    Solved this issue by updating the opencv-android sdk. The older version did not had the .so file for armv8 architecture causing the crash in devices with armv8 architecture as I load the opencv .so file at the start of the app. The updated version had the required file.