could not get unknown property for 'applicationVariants' for BuildType_Decorated

佐手、 提交于 2019-12-01 03:12:26
DWattimena

You have an error at applicationVariants.all.

buildTypes {
    release {
        applicationVariants.all { variant ->
            appendVersionName(variant, defaultConfig)
        }
    }
}

Fix 1:

This will not work since you are applying apply plugin: 'com.android.library'.

You have to change it to apply plugin: 'com.android.application' to use applicationVariants.all.

Fix 2:

If you want to keep using apply plugin: 'com.android.library'.

Change applicationVariants.all to libraryVariants.all or testVariants.all.

Explanation:

applicationVariants (only for the app plugin)

libraryVariants (only for the library plugin)

testVariants (for both plugins)

All three return a DomainObjectCollection of ApplicationVariant, LibraryVariant, and TestVariant objects respectively.

Hope this helps.

Edit:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 25
    buildToolsVersion '25.0.3'

    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 22
        versionCode 71
        versionName "2.0.8.0"
        if (project.hasProperty('ADD_BUILD_TO_VERSION')) {
            versionName = versionName.substring(0,versionName.lastIndexOf(".") + 1) + (System.getenv("BUILD_NUMBER") ?: "0")
        }
    }

    signingConfigs {
        release {
            storeFile file("../../../keys/AndroidScannerSDK.keystore")
            if (project.hasProperty('RELEASE_STORE_PASSWORD')) {
                storePassword RELEASE_STORE_PASSWORD
                keyAlias RELEASE_KEY_ALIAS
                keyPassword RELEASE_KEY_PASSWORD
            }
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            if (project.hasProperty('RELEASE_STORE_PASSWORD')) {
                signingConfig signingConfigs.release
            }
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    lintOptions {
        abortOnError false
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:design:25.3.1'
    compile project(':BarcodeScannerLibrary')
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!