Tencent/matrix · error · GradleException
[-] Either or should be applied when use this script.
Error message
[-] Either ${ANDROID_APP_PLUGIN_ID} or ${ANDROID_LIB_PLUGIN_ID} should be applied when use this script. What it means
WeChatNativeDepend.gradle customizes native dependency handling and supports two modes depending on the applied Android plugin: application or library. If neither the app nor the library plugin is applied to the project, it throws a GradleException naming both required plugin IDs.
Solutions
- Apply the script only in modules that apply 'com.android.application' or 'com.android.library'
- Ensure the Android plugin is applied before 'apply from: WeChatNativeDepend.gradle'
- Remove the script from the root project or non-Android modules
Example fix
// before // root build.gradle apply from: 'WeChatNativeDepend.gradle' // after // app/build.gradle apply plugin: 'com.android.application' apply from: '../WeChatNativeDepend.gradle'
Defensive patterns
Strategy: validation
Validate before calling
// in module build.gradle, before apply from:
assert plugins.hasPlugin('com.android.application') || plugins.hasPlugin('com.android.library') Prevention
- Apply the script only inside Android application/library modules
- Apply the Android plugin before the helper script
- Never apply at the root project level
When it happens
Trigger: Applying the script in a module without any Android plugin (plain java-library, Kotlin JVM, or the root build.gradle), or applying it before either Android plugin is registered on the project.
Common situations: Adding the script to the root project instead of an Android module; applying from a non-Android subproject; plugin-application order issues in legacy apply-from setups.
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
- This plugin must be applied after "com.android.library"…
- plugin stop, plugin listener is null
- plugin destroy, but plugin has been already destroyed
- plugin destroy, plugin listener is null
- publish issue, but issue listener is null
AI-assisted analysis of Tencent/matrix@3b8293bd65 (2026-09-08).
Data as JSON: /api/errors/eed309fa3e4f7013.
Report an issue: GitHub.
Appendix: source
Thrown at matrix/matrix-android/gradle/WeChatNativeDepend.gradle:115
def moveToDir(String path) {
moveToDirPath = Objects.requireNonNull(path)
}
}
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
// Entry Codes
//////////////////////////////////////////////////////////////
if (project.pluginManager.hasPlugin(ANDROID_APP_PLUGIN_ID)) {
handleAndroidApplication()
} else if (project.pluginManager.hasPlugin(ANDROID_LIB_PLUGIN_ID)) {
handleAndroidLibrary()
} else {
throw new GradleException("[-] Either ${ANDROID_APP_PLUGIN_ID} or ${ANDROID_LIB_PLUGIN_ID} "
+ "should be applied when use this script.")
}
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
// Helper Methods
//////////////////////////////////////////////////////////////
def cleanDirectory(File dir) {
if (dir.isDirectory()) {
dir.deleteDir()
dir.mkdirs()
}
}
def getGenerateOpsAnchorTask(variant) {
final List<String> startTaskNames = gradle.startParameter.taskNamesView on GitHub (pinned to 3b8293bd65)