Android

How do I resolve Application Binary Interface (ABI) mismatches between the base and mywebdynamicfeature modules?

This error occurs because the base module supports ARM64_V8A and ARMEABI_V7A, whereas mywebdynamicfeature also includes ARMEABI. The error message is as follows:

copy
All modules with native libraries must support the same set of ABIs, but module 'base' supports '[ARM64_V8A, ARMEABI_V7A]' and module 'mywebdynamicfeature' supports '[ARM64_V8A, ARMEABI_V7A, ARMEABI]'.

However, Android enforces ABI consistency across all modules with native libraries. To resolve mismatches, update the base module's build.gradle file to add an abiFilters block under ndk to specify the allowed ABIs as follows:

copy
android {
    ...

    defaultConfig {
        ...

        //Explicitly list allowed ABIs
        ndk {
            abiFilters 'arm64-v8a', 'armeabi-v7a'
        }
    }

}

How do I resolve the lib/arm64-v8a/libc++_shared.so conflict between the base and mywebdynamicfeature modules?

This error occurs because the base and mywebdynamicfeature modules include different versions of lib/arm64-v8a/libc++_shared.so. The Android build system blocks APK merging to prevent runtime instability from conflicting native libraries. The error message is as follows:

copy
Modules 'base' and 'mywebdynamicfeature' contain entry 'lib/arm64-v8a/libc++_shared.so' with different content.

To resolve the conflict, replace the .so file in the mywebdynamicfeature module with the version from the base module to ensure that both modules use the same .so file. Follow these steps:

  1. Extract the .so file from the base module

Build your APK. Use Android Studio's APK Analyzer (right-click the APK and select Analyze APK) to locate libc++_shared.so in the base module. Then, export this file to your computer.

  1. Add the .so file to the mywebdynamicfeature module

Create the directory: mywebdynamicfeature/libs/arm64-v8a/. Then, copy the extracted libc++_shared.so into this directory. An example directory structure is as follows:

image.png

  1. Update the mywebdynamicfeature build.gradle file

Add the following configurations:

    • pickFirst: Configure this to resolve the duplicate .so conflict by selecting the appropriate version for the build.
    • sourceSets: Configure this to include the libs directory with the .so file.

Refer to the following code sample for details:

copy
android {
    ...

    // Resolve the duplicate .so conflict
    packagingOptions {
        pickFirst 'lib/arm64-v8a/libc++_shared.so'
    }
    
    // Include the lib directory containing the .so file
    sourceSets {
        main {
            jniLibs.srcDirs = ['libs']
        }
    }
}
dependencies {
    implementation project(":app")
    implementation "com.alipay.plus.android:iapminiprogram-myweb:${iapminiprogram_version}"
}

Note: Avoid using exclude in mywebdynamicfeature's build.gradle to remove the .so file. Excluding it causes MYWeb to fail at runtime. The following code sample shows an incorrect configuration:

copy
// Do not do this
packagingOptions {
    exclude 'lib/arm64-v8a/libc++_shared.so'
}