Tencent/matrix · error · GradleException

This plugin must be applied after "com.android.library"…

Error message

This plugin must be applied after "com.android.library" plugin

What it means

WeChatArmeabiCompat.gradle is a helper Gradle script that rewrites armeabi-v7a native libs to armeabi; it requires the Android library plugin to already be applied. It throws a GradleException at script-apply time if plugins.hasPlugin('com.android.library') is false.

Solutions

  1. Apply the script only in modules that use 'com.android.library'
  2. Ensure 'apply plugin: com.android.library' comes BEFORE 'apply from: WeChatArmeabiCompat.gradle' in the same script
  3. Remove the script from application modules; adapt it (libraryVariants -> applicationVariants) if needed for apps

Example fix

// before
apply from: 'WeChatArmeabiCompat.gradle'
apply plugin: 'com.android.library'
// after
apply plugin: 'com.android.library'
apply from: 'WeChatArmeabiCompat.gradle'
Defensive patterns

Strategy: validation

Validate before calling

// build.gradle
assert plugins.hasPlugin('com.android.library') : 'WeChatArmeabiCompat requires library plugin'

Prevention

When it happens

Trigger: Applying the script in a com.android.application module, in a pure Java/Kotlin module, or applying it before 'com.android.library' in the plugin declaration order of the same build script.

Common situations: Copy-pasting the script into an app module's build.gradle; applying via 'apply from:' before the library plugin is loaded; using it in a legacy project where the module uses the app plugin.

Understand the failure class

Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.

Related errors


AI-assisted analysis of Tencent/matrix@3b8293bd65 (2026-09-08). Data as JSON: /api/errors/aa4748e70394822a. Report an issue: GitHub.

Appendix: source

Thrown at matrix/matrix-android/gradle/WeChatArmeabiCompat.gradle:2

if (!plugins.hasPlugin('com.android.library'))
    throw new GradleException('This plugin must be applied after "com.android.library" plugin')

android.libraryVariants.all { variant ->
    def srcAbi = 'armeabi-v7a'
    def targetAbi = 'armeabi'
    
    def bundleTask = variant.getPackageLibrary() as Zip
    def makeCompatAbiTask = project.task("makeArmeabiCompatFor${variant.name.capitalize()}")
    makeCompatAbiTask.doFirst {
        bundleTask.inputs.files.files.each { fileIn ->
            def nameIn = fileIn.name
            def pathIn = fileIn.absolutePath
            def srcAbiPathSeg = "${File.separator}${srcAbi}${File.separator}"
            if ((!nameIn.endsWith('.so') && !nameIn.endsWith('.a')) || !pathIn.contains(srcAbiPathSeg)) {
                return
            }

            def targetAbiPathSeg = "${File.separator}${targetAbi}${File.separator}"
            def targetAbiPathIn = pathIn.replace(srcAbiPathSeg, targetAbiPathSeg)

View on GitHub (pinned to 3b8293bd65)