gradle 插件升级后无法解析 DefaultManifestParser
Cannot resolve DefaultManifestParser after gradle plugin upgrade
我正在尝试在 Android Studio 中编译 AndroidCaldavSyncAdapter 项目。它甚至以前工作过,但是在将 gradle 插件版本从 com.android.tools.build:gradle:1.5.0
升级到 com.android.tools.build:gradle:2.3.0
后它停止工作了。现在我收到这个错误:
Error:(34, 0) A problem occurred evaluating project ':ACalDAV'.
和
cannot resolve symbol 'builder'
在
import com.android.builder.core.DefaultManifestParser
这是 build.grade
文件:
import com.android.builder.core.DefaultManifestParser
apply plugin: 'com.android.application'
apply from: '../config/quality/quality.gradle'
android {
compileSdkVersion 22
buildToolsVersion '25.0.3'
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
defaultConfig {
applicationId "de.we.acaldav"
minSdkVersion 14
targetSdkVersion 20
multiDexEnabled true
def manifestParser = new DefaultManifestParser()
versionName = manifestParser.getVersionName(android.sourceSets.main.manifest.srcFile)
}
signingConfigs {
//noinspection GroovyMissingReturnStatement
release {
if (project.hasProperty('myKeyAlias') &&
project.hasProperty('myStoreFile') &&
project.hasProperty('myStorePassword') &&
project.hasProperty('myKeyPassword')) {
keyAlias = myKeyAlias
storeFile = file(myStoreFile)
storePassword = myStorePassword
keyPassword = myKeyPassword
}
}
}
buildTypes {
release {
minifyEnabled true
signingConfig signingConfigs.release
proguardFile 'proguard-project.txt'
}
debug {
//noinspection GroovyAssignabilityCheck
applicationIdSuffix = ".debug"
//noinspection GroovyAssignabilityCheck
versionNameSuffix = "-DEBUG"
}
//noinspection GroovyAssignabilityCheck
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(output.outputFile.parent, output.outputFile.name.replace(".apk", "-" + defaultConfig.versionName + ".apk"))
}
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
dependencies {
compile 'com.android.support:support-v4:22.0.0'
compile 'backport-util-concurrent:backport-util-concurrent:3.1'
compile 'commons-codec:commons-codec:1.10'
compile 'org.apache.commons:commons-lang3:3.3.2'
compile 'org.mnode.ical4j:ical4j:1.0.6'
repositories {
mavenCentral()
}
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
}
}
我试过使缓存无效,但这并没有改变任何东西。
发生这种情况,因为 DefaultManifestParser
的签名已更改:现在它需要 manifestFile
作为参数。
在Android Gradle 插件version 1.5.0 中没有明确提供DefaultManifestParser
的构造函数,这意味着有一个空的构造函数。结果表达式 def manifestParser = new DefaultManifestParser()
正常执行。
在 Android Gradle 插件中 version 2.2.0 构造函数的签名已更改为以下内容:
public DefaultManifestParser(@NonNull File manifestFile)
这意味着,应执行 build.gradle
文件中的以下更改:
def manifestParser = new DefaultManifestParser(android.sourceSets.main.manifest.srcFile)
versionName = manifestParser.getVersionName()
我正在尝试在 Android Studio 中编译 AndroidCaldavSyncAdapter 项目。它甚至以前工作过,但是在将 gradle 插件版本从 com.android.tools.build:gradle:1.5.0
升级到 com.android.tools.build:gradle:2.3.0
后它停止工作了。现在我收到这个错误:
Error:(34, 0) A problem occurred evaluating project ':ACalDAV'.
和
cannot resolve symbol 'builder'
在
import com.android.builder.core.DefaultManifestParser
这是 build.grade
文件:
import com.android.builder.core.DefaultManifestParser
apply plugin: 'com.android.application'
apply from: '../config/quality/quality.gradle'
android {
compileSdkVersion 22
buildToolsVersion '25.0.3'
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
defaultConfig {
applicationId "de.we.acaldav"
minSdkVersion 14
targetSdkVersion 20
multiDexEnabled true
def manifestParser = new DefaultManifestParser()
versionName = manifestParser.getVersionName(android.sourceSets.main.manifest.srcFile)
}
signingConfigs {
//noinspection GroovyMissingReturnStatement
release {
if (project.hasProperty('myKeyAlias') &&
project.hasProperty('myStoreFile') &&
project.hasProperty('myStorePassword') &&
project.hasProperty('myKeyPassword')) {
keyAlias = myKeyAlias
storeFile = file(myStoreFile)
storePassword = myStorePassword
keyPassword = myKeyPassword
}
}
}
buildTypes {
release {
minifyEnabled true
signingConfig signingConfigs.release
proguardFile 'proguard-project.txt'
}
debug {
//noinspection GroovyAssignabilityCheck
applicationIdSuffix = ".debug"
//noinspection GroovyAssignabilityCheck
versionNameSuffix = "-DEBUG"
}
//noinspection GroovyAssignabilityCheck
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(output.outputFile.parent, output.outputFile.name.replace(".apk", "-" + defaultConfig.versionName + ".apk"))
}
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
dependencies {
compile 'com.android.support:support-v4:22.0.0'
compile 'backport-util-concurrent:backport-util-concurrent:3.1'
compile 'commons-codec:commons-codec:1.10'
compile 'org.apache.commons:commons-lang3:3.3.2'
compile 'org.mnode.ical4j:ical4j:1.0.6'
repositories {
mavenCentral()
}
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
}
}
我试过使缓存无效,但这并没有改变任何东西。
发生这种情况,因为 DefaultManifestParser
的签名已更改:现在它需要 manifestFile
作为参数。
在Android Gradle 插件version 1.5.0 中没有明确提供DefaultManifestParser
的构造函数,这意味着有一个空的构造函数。结果表达式 def manifestParser = new DefaultManifestParser()
正常执行。
在 Android Gradle 插件中 version 2.2.0 构造函数的签名已更改为以下内容:
public DefaultManifestParser(@NonNull File manifestFile)
这意味着,应执行 build.gradle
文件中的以下更改:
def manifestParser = new DefaultManifestParser(android.sourceSets.main.manifest.srcFile)
versionName = manifestParser.getVersionName()