{"record":{"id":"c5e11117d1210fb0","repo":"Tencent/matrix","slug":"matrix-plugin-android-application-plugin-required","errorCode":null,"errorMessage":"Matrix Plugin, Android Application plugin required.","messagePattern":"Matrix Plugin, Android Application plugin required\\.","errorType":"exception","errorClass":"GradleException","httpStatus":null,"severity":"error","filePath":"matrix/matrix-android/matrix-gradle-plugin/src/main/kotlin/com/tencent/matrix/plugin/MatrixPlugin.kt","lineNumber":42,"sourceCode":"import com.tencent.matrix.trace.extension.MatrixTraceExtension\nimport org.gradle.api.GradleException\nimport org.gradle.api.Plugin\nimport org.gradle.api.Project\nimport org.gradle.api.plugins.ExtensionAware\n\nclass MatrixPlugin : Plugin<Project> {\n    companion object {\n        const val TAG = \"Matrix.Plugin\"\n    }\n\n    override fun apply(project: Project) {\n\n        val matrix = project.extensions.create(\"matrix\", MatrixExtension::class.java)\n        val traceExtension = (matrix as ExtensionAware).extensions.create(\"trace\", MatrixTraceExtension::class.java)\n        val removeUnusedResourcesExtension = matrix.extensions.create(\"removeUnusedResources\", MatrixRemoveUnusedResExtension::class.java)\n\n        if (!project.plugins.hasPlugin(\"com.android.application\")) {\n            throw GradleException(\"Matrix Plugin, Android Application plugin required.\")\n        }\n\n        project.afterEvaluate {\n            Log.setLogLevel(matrix.logLevel)\n        }\n\n        MatrixTasksManager().createMatrixTasks(\n                project.extensions.getByName(\"android\") as AppExtension,\n                project,\n                traceExtension,\n                removeUnusedResourcesExtension\n        )\n    }\n}\n","sourceCodeStart":24,"sourceCodeEnd":57,"githubUrl":"https://github.com/Tencent/matrix/blob/3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7/matrix/matrix-android/matrix-gradle-plugin/src/main/kotlin/com/tencent/matrix/plugin/MatrixPlugin.kt#L24-L57","documentation":"Matrix's Gradle plugin (`apply 'matrix'`) only works on Android application modules, so the plugin explicitly checks that the `com.android.application` plugin is already applied to the project during `apply()`. If it is not, a GradleException is thrown to fail the build early instead of producing broken instrumentation later. Matrix relies on AGP application-specific APIs (variants, APK artifacts) that only exist in app modules.","triggerScenarios":"Applying the Matrix plugin from a project's build.gradle (root project), or from a library (`com.android.library`) / dynamic-feature module, or applying `matrix` before `com.android.application` in the same build script.","commonSituations":"Putting `apply plugin: 'matrix'` in the root build.gradle instead of the app module's build.gradle; forgetting to apply `com.android.application` first; moving the plugin to a shared convention plugin without ordering the plugin application correctly.","solutions":["Apply the Matrix plugin inside the module that applies `com.android.application` (typically `app/build.gradle`).","Ensure `apply plugin: 'com.android.application'` (or the `plugins { id 'com.android.application' }` block) appears before `apply plugin: 'matrix'` in the same module.","Remove the matrix plugin from the root project or any library modules and keep it only in the app module."],"exampleFix":"// before (root build.gradle)\napply plugin: 'matrix'\n\n// after (app/build.gradle)\napply plugin: 'com.android.application'\napply plugin: 'matrix'","handlingStrategy":"validation","validationCode":"// app/build.gradle\nassert project.plugins.hasPlugin('com.android.application') : 'matrix plugin requires com.android.application'\napply plugin: 'matrix'","typeGuard":"def isAppModule = { proj -> proj.plugins.hasPlugin('com.android.application') }","tryCatchPattern":null,"preventionTips":["Apply matrix only in the app module, never root or library modules.","Keep `com.android.application` above `matrix` in the plugin block.","Use `plugins { id 'com.android.application'; id 'matrix' }` so ordering is enforced."],"tags":["gradle","android","plugin-ordering","build-configuration"],"backgroundTag":"missing-dependency","analyzedSha":"3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7","analyzedAt":"2026-09-08T08:01:39.722Z","contentChangedAt":"2026-09-08T08:01:39.722Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}