其他分享
首页 > 其他分享> > android – gradle插件升级后无法解析DefaultManifestParser

android – gradle插件升级后无法解析DefaultManifestParser

作者:互联网

我正在尝试在Android Studio中编译AndroidCaldavSyncAdapter项目.它甚至曾经工作过,但是从com.android.tools.build:gradle:1.5.0升级gradle插件版本到com.android.tools.build:gradle:2.3.0之后它停止了工作.现在我收到这个错误:

  Error:(34, 0) A problem occurred evaluating project ':ACalDAV'.


    无法解析符号’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 Plugin version 1.5.0中,没有为DefaultManifestParser明确提供构造函数,这意味着有一个空构造函数.结果表达式def manifestParser = new DefaultManifestParser()正常执行.

在Android Gradle Plugin version 2.2.0中,构造函数的签名已更改为以下内容:

public DefaultManifestParser(@NonNull File manifestFile)

这意味着,应该执行build.gradle文件中的以下更改:

def manifestParser = new DefaultManifestParser(android.sourceSets.main.manifest.srcFile)
versionName = manifestParser.getVersionName()

标签:android,android-gradle,gradle,build,android-build
来源: https://codeday.me/bug/20190828/1752477.html