Gradle报错:'com.android.model.library'插件未找到,如何启用?
Hey there, let's clear this up for you first: com.android.model.library is part of the old Android Experimental Gradle Plugin, which Google officially deprecated and stopped maintaining years ago. The standard com.android.library plugin is now the official, supported way to build Android library projects.
That said, if you have a specific legacy need to use this deprecated plugin, here's how you can enable it:
1. Add the plugin repository
In your project root's build.gradle (not the module-level one), add the repository where the Experimental plugin is hosted:
buildscript { repositories { google() mavenCentral() // This repo is required since the Experimental plugin is only published here maven { url 'https://maven.google.com' } } dependencies { // Use one of the last available Experimental plugin versions, e.g., 3.0.0-alpha7 classpath 'com.android.tools.build:gradle-experimental:3.0.0-alpha7' } } allprojects { repositories { google() mavenCentral() maven { url 'https://maven.google.com' } } }
2. Apply the plugin and use its model syntax
In your library module's build.gradle, replace the standard plugin declaration and use the Experimental plugin's unique model block syntax (note it's very different from standard Gradle syntax):
// Replace your original apply plugin: 'com.android.library' apply plugin: 'com.android.model.library' model { android { compileSdkVersion 28 // Stick to SDK versions compatible with the plugin; newer versions won't work buildToolsVersion "28.0.3" defaultConfig { minSdkVersion.apiLevel 16 targetSdkVersion.apiLevel 28 versionCode 1 versionName "1.0" } } android.buildTypes { release { minifyEnabled false proguardFiles.add(file('proguard-rules.pro')) } } }
3. Critical notes you can't ignore
- Version lock-in: The Experimental plugin only works with specific Gradle and Android SDK versions. For example,
gradle-experimental:3.0.0-alpha7requires Gradle 4.1—newer Gradle versions will throw errors immediately. - No support: This plugin is abandoned. You won't get official fixes, and it won't work with modern Android features or tooling.
- Better alternative: Strongly recommend switching back to the standard
com.android.libraryplugin. It's fully maintained, supports all latest Android capabilities, and has far more community resources and documentation.
内容的提问来源于stack exchange,提问作者Kevin ABRIOUX

